[nginx] Secure link: fixed stack buffer overflow.

Roman Arutyunyan arut at nginx.com
Wed Aug 23 17:59:39 UTC 2017


details:   http://hg.nginx.org/nginx/rev/c7d4017c8876
branches:  
changeset: 7094:c7d4017c8876
user:      Roman Arutyunyan <arut at nginx.com>
date:      Tue Aug 22 21:22:59 2017 +0300
description:
Secure link: fixed stack buffer overflow.

When secure link checksum has length of 23 or 24 bytes, decoded base64 value
could occupy 17 or 18 bytes which is more than 16 bytes previously allocated
for it on stack.  The buffer overflow does not have any security implications
since only one local variable was corrupted and this variable was not used in
this case.

The fix is to increase buffer size up to 18 bytes.  Useless buffer size
initialization is removed as well.

diffstat:

 src/http/modules/ngx_http_secure_link_module.c |  3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diffs (20 lines):

diff -r acc2cddc7b45 -r c7d4017c8876 src/http/modules/ngx_http_secure_link_module.c
--- a/src/http/modules/ngx_http_secure_link_module.c	Wed Aug 23 19:20:06 2017 +0300
+++ b/src/http/modules/ngx_http_secure_link_module.c	Tue Aug 22 21:22:59 2017 +0300
@@ -107,7 +107,7 @@ ngx_http_secure_link_variable(ngx_http_r
     ngx_md5_t                     md5;
     ngx_http_secure_link_ctx_t   *ctx;
     ngx_http_secure_link_conf_t  *conf;
-    u_char                        hash_buf[16], md5_buf[16];
+    u_char                        hash_buf[18], md5_buf[16];
 
     conf = ngx_http_get_module_loc_conf(r, ngx_http_secure_link_module);
 
@@ -154,7 +154,6 @@ ngx_http_secure_link_variable(ngx_http_r
         goto not_found;
     }
 
-    hash.len = 16;
     hash.data = hash_buf;
 
     if (ngx_decode_base64url(&hash, &val) != NGX_OK) {


More information about the nginx-devel mailing list