commit 77f906b3cf1c549a28c0cd767e2244e470f598bf from: Alisdair MacLeod date: Tue Mar 31 18:46:12 2026 UTC Use stack buffer for URI path copy instead of strdup CGI request URIs are short (the longest valid path is /book/YYYY-MM-DD at 16 characters). A 256-byte stack buffer avoids one heap allocation per request. Co-Authored-By: Claude Opus 4.6 (1M context) commit - b91d801835eb928cf8379ebefe2add66ed98f61c commit + 77f906b3cf1c549a28c0cd767e2244e470f598bf blob - 648500bf17d5e80bbfe5a0243fdf3522d167598c blob + 34e32cfd4c7264484ab03c697f905c622541e8c7 --- deskd.c +++ deskd.c @@ -158,13 +158,16 @@ main(const int argc, char *argv[]) } /* Strip query string from URI to get the path. */ - char *path_copy = strdup(uri); - if (path_copy == NULL) - return 1; - char *qmark = strchr(path_copy, '?'); + char path[256]; + const size_t urilen = strlen(uri); + if (urilen >= sizeof(path)) { + cgi_redirect(302, "/"); + return 0; + } + memcpy(path, uri, urilen + 1); + char *qmark = strchr(path, '?'); if (qmark != NULL) *qmark = '\0'; - const char *path = path_copy; const size_t pathlen = strlen(path); /* Route the request. */ @@ -196,6 +199,5 @@ main(const int argc, char *argv[]) cgi_redirect(302, "/"); } - free(path_copy); return 0; }