Skip to content

Commit

Permalink
bugfix: we should always test if the request object pointer is null i…
Browse files Browse the repository at this point in the history
…n the ngx.req.*_body API.
  • Loading branch information
agentzh committed Jul 5, 2012
1 parent c2f74d1 commit 4960e01
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/ngx_http_lua_req_body.c
Expand Up @@ -60,6 +60,10 @@ ngx_http_lua_ngx_req_read_body(lua_State *L)
r = lua_touserdata(L, -1);
lua_pop(L, 1);

if (r == NULL) {
return luaL_error(L, "request object not found");
}

r->request_body_in_single_buf = 1;
r->request_body_in_persistent_file = 1;
r->request_body_in_clean_file = 1;
Expand Down Expand Up @@ -155,6 +159,10 @@ ngx_http_lua_ngx_req_discard_body(lua_State *L)
r = lua_touserdata(L, -1);
lua_pop(L, 1);

if (r == NULL) {
return luaL_error(L, "request object not found");
}

rc = ngx_http_discard_request_body(r);

if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
Expand Down Expand Up @@ -186,6 +194,10 @@ ngx_http_lua_ngx_req_get_body_data(lua_State *L)
r = lua_touserdata(L, -1);
lua_pop(L, 1);

if (r == NULL) {
return luaL_error(L, "request object not found");
}

if (r->request_body == NULL
|| r->request_body->temp_file
|| r->request_body->bufs == NULL)
Expand Down Expand Up @@ -250,6 +262,10 @@ ngx_http_lua_ngx_req_get_body_file(lua_State *L)
r = lua_touserdata(L, -1);
lua_pop(L, 1);

if (r == NULL) {
return luaL_error(L, "request object not found");
}

if (r->request_body == NULL || r->request_body->temp_file == NULL) {
lua_pushnil(L);
return 1;
Expand Down Expand Up @@ -299,6 +315,10 @@ ngx_http_lua_ngx_req_set_body_data(lua_State *L)
r = lua_touserdata(L, -1);
lua_pop(L, 1);

if (r == NULL) {
return luaL_error(L, "request object not found");
}

if (r->request_body == NULL) {

#if 1
Expand Down Expand Up @@ -511,6 +531,10 @@ ngx_http_lua_ngx_req_set_body_file(lua_State *L)
r = lua_touserdata(L, -1);
lua_pop(L, 1);

if (r == NULL) {
return luaL_error(L, "request object not found");
}

if (r->request_body == NULL) {

#if 1
Expand Down

0 comments on commit 4960e01

Please sign in to comment.