comparison src/http/modules/ngx_http_secure_link_module.c @ 7094:c7d4017c8876

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.
author Roman Arutyunyan <arut@nginx.com>
date Tue, 22 Aug 2017 21:22:59 +0300
parents d89442dab4d1
children bdd4d89370a7
comparison
equal deleted inserted replaced
7093:acc2cddc7b45 7094:c7d4017c8876
105 ngx_str_t val, hash; 105 ngx_str_t val, hash;
106 time_t expires; 106 time_t expires;
107 ngx_md5_t md5; 107 ngx_md5_t md5;
108 ngx_http_secure_link_ctx_t *ctx; 108 ngx_http_secure_link_ctx_t *ctx;
109 ngx_http_secure_link_conf_t *conf; 109 ngx_http_secure_link_conf_t *conf;
110 u_char hash_buf[16], md5_buf[16]; 110 u_char hash_buf[18], md5_buf[16];
111 111
112 conf = ngx_http_get_module_loc_conf(r, ngx_http_secure_link_module); 112 conf = ngx_http_get_module_loc_conf(r, ngx_http_secure_link_module);
113 113
114 if (conf->secret.data) { 114 if (conf->secret.data) {
115 return ngx_http_secure_link_old_variable(r, conf, v, data); 115 return ngx_http_secure_link_old_variable(r, conf, v, data);
152 152
153 if (val.len > 24) { 153 if (val.len > 24) {
154 goto not_found; 154 goto not_found;
155 } 155 }
156 156
157 hash.len = 16;
158 hash.data = hash_buf; 157 hash.data = hash_buf;
159 158
160 if (ngx_decode_base64url(&hash, &val) != NGX_OK) { 159 if (ngx_decode_base64url(&hash, &val) != NGX_OK) {
161 goto not_found; 160 goto not_found;
162 } 161 }