Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tweaked kindy's patch for base64/md5_bin/get_today etc a bit. and pfr…

…ee aggressively to prevent leaking
  • Loading branch information...
commit 5d0f7a8e80d7327756bccc5676bbac2e92fec687 1 parent 3348b15
@agentzh agentzh authored
2  deps/ngx_devel_kit
@@ -1 +1 @@
-Subproject commit 8a0e8e6ef55b564901815e543598c60b5672e815
+Subproject commit 7ccc46dadbccf571234a60e58ad33b83aa4f5fca
View
28 src/ngx_http_lua_hook.c
@@ -1,4 +1,5 @@
/* vim:set ft=c ts=4 sw=4 et fdm=marker: */
+#define DDEBUG 1
#include "ngx_http_lua_hook.h"
#include "ngx_http_lua_util.h"
#include "ngx_http_lua_contentby.h"
@@ -910,7 +911,7 @@ ngx_http_lua_ngx_md5(lua_State *L)
src = (u_char *) luaL_checklstring(L, 1, &slen);
}
- p = ngx_palloc(r->pool, len);
+ p = ngx_palloc(r->pool, len);
if (p == NULL) {
return NGX_ERROR;
}
@@ -952,7 +953,9 @@ ngx_http_lua_ngx_md5_bin(lua_State *L)
src = (u_char *) luaL_checklstring(L, 1, &slen);
}
- p = ngx_palloc(r->pool, len);
+ dd("slen: %d", (int) slen);
+
+ p = ngx_palloc(r->pool, len);
if (p == NULL) {
return NGX_ERROR;
}
@@ -961,8 +964,12 @@ ngx_http_lua_ngx_md5_bin(lua_State *L)
ngx_md5_update(&md5, (char *) src, slen);
ngx_md5_final(p, &md5);
+ dd("len: %d", (int) len);
+
lua_pushlstring(L, (char *) p, len);
+ ngx_pfree(r->pool, p);
+
return 1;
}
@@ -994,7 +1001,7 @@ ngx_http_lua_ngx_base64_decode(lua_State *L)
p.len = ngx_base64_decoded_length(src.len);
- p.data = ngx_palloc(r->pool, p.len);
+ p.data = ngx_palloc(r->pool, p.len);
if (p.data == NULL) {
return NGX_ERROR;
}
@@ -1009,9 +1016,12 @@ ngx_http_lua_ngx_base64_decode(lua_State *L)
lua_pushnil(L);
}
+ ngx_pfree(r->pool, p.data);
+
return 1;
}
+
int
ngx_http_lua_ngx_base64_encode(lua_State *L)
{
@@ -1039,7 +1049,7 @@ ngx_http_lua_ngx_base64_encode(lua_State *L)
p.len = ngx_base64_encoded_length(src.len);
- p.data = ngx_palloc(r->pool, p.len);
+ p.data = ngx_palloc(r->pool, p.len);
if (p.data == NULL) {
return NGX_ERROR;
}
@@ -1048,9 +1058,12 @@ ngx_http_lua_ngx_base64_encode(lua_State *L)
lua_pushlstring(L, (char *) p.data, p.len);
+ ngx_pfree(r->pool, p.data);
+
return 1;
}
+
int
ngx_http_lua_ngx_get_today(lua_State *L)
{
@@ -1087,9 +1100,12 @@ ngx_http_lua_ngx_get_today(lua_State *L)
lua_pushlstring(L, (char *) p, len);
+ ngx_pfree(r->pool, p);
+
return 1;
}
+
int
ngx_http_lua_ngx_get_now(lua_State *L)
{
@@ -1126,9 +1142,12 @@ ngx_http_lua_ngx_get_now(lua_State *L)
lua_pushlstring(L, (char *) p, len);
+ ngx_pfree(r->pool, p);
+
return 1;
}
+
int
ngx_http_lua_ngx_get_now_ts(lua_State *L)
{
@@ -1153,3 +1172,4 @@ ngx_http_lua_ngx_get_now_ts(lua_State *L)
return 1;
}
+
View
29 t/011-md5_bin.t
@@ -22,19 +22,30 @@ __DATA__
=== TEST 1: set md5_bin hello ????xxoo
--- config
location = /md5_bin {
- content_by_lua 'ngx.say(string.gsub(ngx.md5_bin("hello"), ".", function (c)
+ content_by_lua 'local a = string.gsub(ngx.md5_bin("hello"), ".", function (c)
return string.format("%02x", string.byte(c))
- end))';
+ end); ngx.say(a)';
}
--- request
GET /md5_bin
--- response_body
5d41402abc4b2a76b9719d911017c592
---- SKIP
-=== TEST 2: set md5_bin hello
+=== TEST 2: set md5_bin hello ????xxoo
+--- config
+ location = /md5_bin {
+ content_by_lua 'ngx.say(string.len(ngx.md5_bin("hello")))';
+ }
+--- request
+GET /md5_bin
+--- response_body
+16
+
+
+
+=== TEST 3: set md5_bin hello
--- config
location = /md5_bin {
content_by_lua '
@@ -52,7 +63,7 @@ GET /md5_bin
-=== TEST 3: nil string to ngx.md5_bin
+=== TEST 4: nil string to ngx.md5_bin
--- config
location = /md5_bin {
content_by_lua '
@@ -70,7 +81,7 @@ d41d8cd98f00b204e9800998ecf8427e
-=== TEST 4: null string to ngx.md5_bin
+=== TEST 5: null string to ngx.md5_bin
--- config
location /md5_bin {
content_by_lua '
@@ -88,7 +99,7 @@ d41d8cd98f00b204e9800998ecf8427e
-=== TEST 5: use ngx.md5_bin in set_by_lua
+=== TEST 6: use ngx.md5_bin in set_by_lua
--- config
location = /md5_bin {
set_by_lua $a 'return string.gsub(ngx.md5_bin("hello"), ".", function (c)
@@ -103,7 +114,7 @@ GET /md5_bin
-=== TEST 6: use ngx.md5_bin in set_by_lua (nil)
+=== TEST 7: use ngx.md5_bin in set_by_lua (nil)
--- config
location = /md5_bin {
set_by_lua $a '
@@ -122,7 +133,7 @@ d41d8cd98f00b204e9800998ecf8427e
-=== TEST 7: use ngx.md5_bin in set_by_lua (null string)
+=== TEST 8: use ngx.md5_bin in set_by_lua (null string)
--- config
location /md5_bin {
set_by_lua $a '
View
14 t/013-base64.t
@@ -28,6 +28,7 @@ GET /base64_encode
aGVsbG8=
+
=== TEST 2: nil string to ngx.base64_encode
--- config
location = /base64_encode {
@@ -91,7 +92,7 @@ leftright
-=== TEST 1: base64 encode hello
+=== TEST 7: base64 encode hello
--- config
location = /base64_decode {
content_by_lua 'ngx.say(ngx.base64_decode("aGVsbG8="))';
@@ -102,7 +103,8 @@ GET /base64_decode
hello
-=== TEST 2: nil string to ngx.base64_decode
+
+=== TEST 8: nil string to ngx.base64_decode
--- config
location = /base64_decode {
content_by_lua 'ngx.say("left" .. ngx.base64_decode(nil) .. "right")';
@@ -114,7 +116,7 @@ leftright
-=== TEST 3: null string to ngx.base64_decode
+=== TEST 9: null string to ngx.base64_decode
--- config
location = /base64_decode {
content_by_lua 'ngx.say("left" .. ngx.base64_decode("") .. "right")';
@@ -126,7 +128,7 @@ leftright
-=== TEST 4: use ngx.base64_decode in set_by_lua
+=== TEST 10: use ngx.base64_decode in set_by_lua
--- config
location = /base64_decode {
set_by_lua $a 'return ngx.base64_decode("aGVsbG8=")';
@@ -139,7 +141,7 @@ hello
-=== TEST 5: use ngx.base64_decode in set_by_lua (nil)
+=== TEST 11: use ngx.base64_decode in set_by_lua (nil)
--- config
location = /base64_decode {
set_by_lua $a 'return "left" .. ngx.base64_decode(nil) .. "right"';
@@ -152,7 +154,7 @@ leftright
-=== TEST 6: use ngx.base64_decode in set_by_lua (null string)
+=== TEST 12: use ngx.base64_decode in set_by_lua (null string)
--- config
location /base64_decode {
set_by_lua $a 'return "left" .. ngx.base64_decode("") .. "right"';
View
17 valgrind.suppress
@@ -3,6 +3,23 @@
Memcheck:Leak
fun:malloc
fun:ngx_alloc
+ fun:ngx_palloc_large
+ fun:ngx_palloc
+ fun:ngx_array_push
+ fun:ngx_http_get_variable_index
+ fun:ngx_http_memc_add_variable
+ fun:ngx_http_memc_init
+ fun:ngx_http_block
+ fun:ngx_conf_parse
+ fun:ngx_init_cycle
+ fun:main
+}
+
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:malloc
+ fun:ngx_alloc
fun:ngx_event_process_init
fun:ngx_single_process_cycle
fun:main
Please sign in to comment.
Something went wrong with that request. Please try again.