@@ -247,6 +247,7 @@ void supervisor_start_web_workflow(void) {
247
247
port_len = dotenv_get_key ("/.env" , "CIRCUITPY_WEB_API_PORT" , port_encoded , sizeof (port_encoded ) - 1 );
248
248
#endif
249
249
if (0 < port_len && port_len < sizeof (port_encoded )) {
250
+ port_encoded [port_len ] = '\0' ;
250
251
new_port = strtoul (port_encoded , NULL , 10 );
251
252
}
252
253
@@ -623,8 +624,6 @@ static void _reply_directory_json(socketpool_socket_obj_t *socket, _request *req
623
624
624
625
static void _reply_with_file (socketpool_socket_obj_t * socket , _request * request , const char * filename , FIL * active_file ) {
625
626
uint32_t total_length = f_size (active_file );
626
- char encoded_len [10 ];
627
- snprintf (encoded_len , sizeof (encoded_len ), "%d" , total_length );
628
627
629
628
_send_str (socket , "HTTP/1.1 200 OK\r\n" );
630
629
mp_print_t _socket_print = {socket , _print_raw };
@@ -1209,9 +1208,12 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request)
1209
1208
request -> authenticated = strncmp (request -> header_value , prefix , strlen (prefix )) == 0 &&
1210
1209
strcmp (_api_password , request -> header_value + strlen (prefix )) == 0 ;
1211
1210
} else if (strcasecmp (request -> header_key , "Host" ) == 0 ) {
1212
- // Do a prefix check so that port is ignored.
1211
+ // Do a prefix check so that port is ignored. Length must be the same or the
1212
+ // header ends in :.
1213
1213
const char * cp_local = "circuitpython.local" ;
1214
- request -> redirect = strncmp (request -> header_value , cp_local , strlen (cp_local )) == 0 ;
1214
+ request -> redirect = strncmp (request -> header_value , cp_local , strlen (cp_local )) == 0 &&
1215
+ (strlen (request -> header_value ) == strlen (cp_local ) ||
1216
+ request -> header_value [strlen (cp_local )] == ':' );
1215
1217
} else if (strcasecmp (request -> header_key , "Content-Length" ) == 0 ) {
1216
1218
request -> content_length = strtoul (request -> header_value , NULL , 10 );
1217
1219
} else if (strcasecmp (request -> header_key , "Expect" ) == 0 ) {
0 commit comments