diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-04-08 16:31:05 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-04-08 16:31:05 +0000 |
commit | 1226d45eba22faf9d1f776f0d4151601364ca317 (patch) | |
tree | 3c5c84d93babdf4e103e20c14a333a591a255ae2 | |
parent | 6096c8a88ea2265016502c9ed677ac4116455da8 (diff) |
Check result of snprintf() in basicauth.c and digestauth.c, log more errors
-rw-r--r-- | src/microhttpd/basicauth.c | 27 | ||||
-rw-r--r-- | src/microhttpd/digestauth.c | 19 |
2 files changed, 35 insertions, 11 deletions
diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c index 51f9cf93..bb9e1ea4 100644 --- a/src/microhttpd/basicauth.c +++ b/src/microhttpd/basicauth.c @@ -117,7 +117,7 @@ MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, const char *realm, struct MHD_Response *response) { - int ret; + int ret, res; size_t hlen = strlen(realm) + strlen("Basic realm=\"\"") + 1; char *header; @@ -130,18 +130,29 @@ MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection, #endif /* HAVE_MESSAGES */ return MHD_NO; } - MHD_snprintf_ (header, - hlen, - "Basic realm=\"%s\"", - realm); - ret = MHD_add_response_header (response, - MHD_HTTP_HEADER_WWW_AUTHENTICATE, - header); + res = MHD_snprintf_ (header, + hlen, + "Basic realm=\"%s\"", + realm); + if (res > 0 && res < hlen) + ret = MHD_add_response_header (response, + MHD_HTTP_HEADER_WWW_AUTHENTICATE, + header); + else + ret = MHD_NO; + free(header); if (MHD_YES == ret) ret = MHD_queue_response (connection, MHD_HTTP_UNAUTHORIZED, response); + else + { +#ifdef HAVE_MESSAGES + MHD_DLOG (connection->daemon, + "Failed to add Basic auth header\n"); +#endif /* HAVE_MESSAGES */ + } return ret; } diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c index 8e38dc41..851eaa3f 100644 --- a/src/microhttpd/digestauth.c +++ b/src/microhttpd/digestauth.c @@ -822,6 +822,7 @@ MHD_queue_auth_fail_response (struct MHD_Connection *connection, signal_stale ? ",stale=\"true\"" : ""); + if (hlen > 0) { char *header; @@ -835,7 +836,7 @@ MHD_queue_auth_fail_response (struct MHD_Connection *connection, return MHD_NO; } - MHD_snprintf_(header, + if (MHD_snprintf_(header, hlen + 1, "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s", realm, @@ -843,16 +844,28 @@ MHD_queue_auth_fail_response (struct MHD_Connection *connection, opaque, signal_stale ? ",stale=\"true\"" - : ""); - ret = MHD_add_response_header(response, + : "") == hlen) + ret = MHD_add_response_header(response, MHD_HTTP_HEADER_WWW_AUTHENTICATE, header); + else + ret = MHD_NO; free(header); } + else + ret = MHD_NO; + if (MHD_YES == ret) ret = MHD_queue_response(connection, MHD_HTTP_UNAUTHORIZED, response); + else + { +#ifdef HAVE_MESSAGES + MHD_DLOG (connection->daemon, + "Failed to add Digest auth header\n"); +#endif /* HAVE_MESSAGES */ + } return ret; } |