Skip to content

Commit babd4ee

Browse files
committed
Tweaks based on review comments
1 parent f9cc4ec commit babd4ee

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

shared-bindings/mdns/Server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mdns_server_find_obj, 1, _mdns_server_find);
161161
//| def advertise_service(self, *, service_type: str, protocol: str, port: int) -> None:
162162
//| """Respond to queries for the given service with the given port.
163163
//|
164-
//| service_type and protocol can only occur on one port. Any call after the first will
165-
//| update the entry's port.
164+
//| ``service_type`` and ``protocol`` can only occur on one port. Any call after the first
165+
//| will update the entry's port.
166166
//|
167167
//| :param str service_type: The service type such as "_http"
168168
//| :param str protocol: The service protocol such as "_tcp"

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

624625
static 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

Comments
 (0)