@@ -247,6 +247,7 @@ void supervisor_start_web_workflow(void) {
247247 port_len = dotenv_get_key ("/.env" , "CIRCUITPY_WEB_API_PORT" , port_encoded , sizeof (port_encoded ) - 1 );
248248 #endif
249249 if (0 < port_len && port_len < sizeof (port_encoded )) {
250+ port_encoded [port_len ] = '\0' ;
250251 new_port = strtoul (port_encoded , NULL , 10 );
251252 }
252253
@@ -623,8 +624,6 @@ static void _reply_directory_json(socketpool_socket_obj_t *socket, _request *req
623624
624625static void _reply_with_file (socketpool_socket_obj_t * socket , _request * request , const char * filename , FIL * active_file ) {
625626 uint32_t total_length = f_size (active_file );
626- char encoded_len [10 ];
627- snprintf (encoded_len , sizeof (encoded_len ), "%d" , total_length );
628627
629628 _send_str (socket , "HTTP/1.1 200 OK\r\n" );
630629 mp_print_t _socket_print = {socket , _print_raw };
@@ -1209,9 +1208,12 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request)
12091208 request -> authenticated = strncmp (request -> header_value , prefix , strlen (prefix )) == 0 &&
12101209 strcmp (_api_password , request -> header_value + strlen (prefix )) == 0 ;
12111210 } 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 :.
12131213 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 )] == ':' );
12151217 } else if (strcasecmp (request -> header_key , "Content-Length" ) == 0 ) {
12161218 request -> content_length = strtoul (request -> header_value , NULL , 10 );
12171219 } else if (strcasecmp (request -> header_key , "Expect" ) == 0 ) {
0 commit comments