diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-05-05 09:40:59 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-05-05 09:40:59 +0200 |
commit | 91a58b207ea04e6078f44cecae6c3356e059da8a (patch) | |
tree | 944331d1caf83f624ba73ab36b873533dabbc02b | |
parent | 5b34a5594c6fc40b6183c50a42e3f86e4b441688 (diff) | |
download | busybox-w32-91a58b207ea04e6078f44cecae6c3356e059da8a.tar.gz busybox-w32-91a58b207ea04e6078f44cecae6c3356e059da8a.tar.bz2 busybox-w32-91a58b207ea04e6078f44cecae6c3356e059da8a.zip |
httpd: no need to strcpy() when we only need to copy one byte
function old new delta
handle_incoming_and_exit 2161 2172 +11
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/httpd.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index e48574e4f..6bc58995b 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -2416,14 +2416,18 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2416 | } | 2416 | } |
2417 | #if ENABLE_FEATURE_HTTPD_CGI | 2417 | #if ENABLE_FEATURE_HTTPD_CGI |
2418 | else if (urlp[-1] == '/') { | 2418 | else if (urlp[-1] == '/') { |
2419 | /* It's a dir URL and there is no index.html | 2419 | /* It's a dir URL and there is no index.html */ |
2420 | * Try cgi-bin/index.cgi */ | 2420 | /* Is there cgi-bin/index.cgi? */ |
2421 | if (access("/cgi-bin/index.cgi"+1, X_OK) != 0) | 2421 | if (access("/cgi-bin/index.cgi"+1, X_OK) != 0) |
2422 | send_headers_and_exit(HTTP_NOT_FOUND); | 2422 | send_headers_and_exit(HTTP_NOT_FOUND); /* no */ |
2423 | cgi_type = CGI_INDEX; | 2423 | cgi_type = CGI_INDEX; |
2424 | } | 2424 | } |
2425 | #endif | 2425 | #endif |
2426 | |||
2427 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH || ENABLE_FEATURE_HTTPD_CGI | ||
2428 | /* check_user_passwd() would be confused by added .../index.html, truncate it */ | ||
2426 | urlp[0] = '\0'; | 2429 | urlp[0] = '\0'; |
2430 | #endif | ||
2427 | 2431 | ||
2428 | #if ENABLE_FEATURE_HTTPD_CGI | 2432 | #if ENABLE_FEATURE_HTTPD_CGI |
2429 | total_headers_len = 0; | 2433 | total_headers_len = 0; |
@@ -2566,8 +2570,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2566 | if (found_moved_temporarily) | 2570 | if (found_moved_temporarily) |
2567 | send_headers_and_exit(HTTP_MOVED_TEMPORARILY); | 2571 | send_headers_and_exit(HTTP_MOVED_TEMPORARILY); |
2568 | 2572 | ||
2569 | tptr = urlcopy + 1; /* skip first '/' */ | ||
2570 | |||
2571 | #if ENABLE_FEATURE_HTTPD_CGI | 2573 | #if ENABLE_FEATURE_HTTPD_CGI |
2572 | if (cgi_type != CGI_NONE) { | 2574 | if (cgi_type != CGI_NONE) { |
2573 | send_cgi_and_exit( | 2575 | send_cgi_and_exit( |
@@ -2578,9 +2580,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2578 | } | 2580 | } |
2579 | #endif | 2581 | #endif |
2580 | 2582 | ||
2581 | if (urlp[-1] == '/') | ||
2582 | strcpy(urlp, index_page); | ||
2583 | |||
2584 | #if ENABLE_FEATURE_HTTPD_CGI | 2583 | #if ENABLE_FEATURE_HTTPD_CGI |
2585 | if (prequest != request_GET && prequest != request_HEAD) { | 2584 | if (prequest != request_GET && prequest != request_HEAD) { |
2586 | /* POST / DELETE / PUT / OPTIONS for files do not make sense */ | 2585 | /* POST / DELETE / PUT / OPTIONS for files do not make sense */ |
@@ -2589,7 +2588,13 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2589 | #else | 2588 | #else |
2590 | /* !CGI: it can be only GET or HEAD */ | 2589 | /* !CGI: it can be only GET or HEAD */ |
2591 | #endif | 2590 | #endif |
2592 | send_file_and_exit(tptr, | 2591 | |
2592 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH | ||
2593 | /* Restore truncated .../index.html */ | ||
2594 | if (urlp[-1] == '/') | ||
2595 | urlp[0] = index_page[0]; | ||
2596 | #endif | ||
2597 | send_file_and_exit(urlcopy + 1, | ||
2593 | (prequest != request_HEAD ? (SEND_HEADERS + SEND_BODY) : SEND_HEADERS) | 2598 | (prequest != request_HEAD ? (SEND_HEADERS + SEND_BODY) : SEND_HEADERS) |
2594 | ); | 2599 | ); |
2595 | } | 2600 | } |