1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-05 16:55:50 +03:00

mod_lua: Fix signedness/other small bugs as per cjaillet/fuankg's emails - thanks guys :)

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1421780 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Gruno
2012-12-14 10:15:37 +00:00
parent 9875cc5fab
commit df178d1e41
3 changed files with 41 additions and 54 deletions

View File

@@ -233,8 +233,11 @@ static int lua_ap_unescape (lua_State *L) {
plain = apr_pstrdup(r->pool, escaped); plain = apr_pstrdup(r->pool, escaped);
strncpy(plain, escaped, x); strncpy(plain, escaped, x);
y = ap_unescape_urlencoded(plain); y = ap_unescape_urlencoded(plain);
lua_pushstring(L, plain); if (!y) {
return 1; lua_pushstring(L, plain);
return 1;
}
return 0;
} }
/* lua_ap_escape; r:escape(string) - URL-escapes a string */ /* lua_ap_escape; r:escape(string) - URL-escapes a string */
@@ -246,7 +249,6 @@ static int lua_ap_escape (lua_State *L) {
r = ap_lua_check_request_rec(L, 1); r = ap_lua_check_request_rec(L, 1);
luaL_checktype(L, 2, LUA_TSTRING); luaL_checktype(L, 2, LUA_TSTRING);
plain = lua_tolstring(L, 2, &x); plain = lua_tolstring(L, 2, &x);
escaped = apr_pcalloc(r->pool, x*3);
escaped = ap_escape_urlencoded(r->pool, plain); escaped = ap_escape_urlencoded(r->pool, plain);
lua_pushstring(L, escaped); lua_pushstring(L, escaped);
return 1; return 1;
@@ -256,9 +258,8 @@ static int lua_ap_escape (lua_State *L) {
static int lua_apr_md5(lua_State *L) static int lua_apr_md5(lua_State *L)
{ {
/*~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~*/
int n;
union { union {
char chr[16]; unsigned char chr[16];
uint32_t num[4]; uint32_t num[4];
} digest; } digest;
apr_md5_ctx_t md5; apr_md5_ctx_t md5;
@@ -294,15 +295,14 @@ static int lua_apr_md5(lua_State *L)
static int lua_apr_sha1(lua_State *L) static int lua_apr_sha1(lua_State *L)
{ {
/*~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~*/
int n;
union { union {
char chr[16]; unsigned char chr[16];
uint32_t num[4]; uint32_t num[4];
} digest; } digest;
apr_sha1_ctx_t sha1; apr_sha1_ctx_t sha1;
const char* buffer; const char* buffer;
char* result; char* result;
char Rsha1[16]; unsigned char Rsha1[20];
uint32_t *sha1X; uint32_t *sha1X;
size_t x,y; size_t x,y;
request_rec *r; request_rec *r;
@@ -355,7 +355,6 @@ static int lua_ap_port(lua_State *L)
static int lua_ap_mpm_query(lua_State *L) static int lua_ap_mpm_query(lua_State *L)
{ {
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
request_rec *r;
int x,y; int x,y;
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
x = lua_tonumber(L, 1); x = lua_tonumber(L, 1);
@@ -425,30 +424,26 @@ static int lua_ap_regex(lua_State *L)
if (ap_regcomp(&regex, pattern,0)) { if (ap_regcomp(&regex, pattern,0)) {
return 0; return 0;
} }
int i;
if (!err) { x = ap_regexec(&regex, source, 10, matches, 0);
int i; if (x < 0) {
x = ap_regexec(&regex, source, 10, matches, 0); lua_pushstring(L, err);
if (x < 0) {
lua_pushstring(L, err);
return 1;
}
lua_newtable(L);
for (i=0;i<10;i++) {
lua_pushinteger(L, i);
if (matches[i].rm_so >= 0 && matches[i].rm_eo >= 0) {
lua_pushstring(L,apr_pstrndup(r->pool, source+matches[i].rm_so, matches[i].rm_eo - matches[i].rm_so));
}
else {
lua_pushnil(L);
}
lua_settable(L, -3);
}
return 1; return 1;
} }
return 0; lua_newtable(L);
for (i=0;i<10;i++) {
lua_pushinteger(L, i);
if (matches[i].rm_so >= 0 && matches[i].rm_eo >= 0) {
lua_pushstring(L,apr_pstrndup(r->pool, source+matches[i].rm_so, matches[i].rm_eo - matches[i].rm_so));
}
else {
lua_pushnil(L);
}
lua_settable(L, -3);
}
return 1;
} }
@@ -458,13 +453,11 @@ static int lua_ap_regex(lua_State *L)
static int lua_ap_scoreboard_process(lua_State *L) static int lua_ap_scoreboard_process(lua_State *L)
{ {
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
request_rec *r;
int i; int i;
process_score* ps_record; process_score* ps_record;
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
luaL_checktype(L, 1, LUA_TUSERDATA); luaL_checktype(L, 1, LUA_TUSERDATA);
luaL_checktype(L, 2, LUA_TNUMBER); luaL_checktype(L, 2, LUA_TNUMBER);
r = ap_lua_check_request_rec(L, 1);
i = lua_tonumber(L, 2); i = lua_tonumber(L, 2);
ps_record = ap_get_scoreboard_process(i); ps_record = ap_get_scoreboard_process(i);
if (ps_record) { if (ps_record) {
@@ -511,14 +504,12 @@ static int lua_ap_scoreboard_process(lua_State *L)
static int lua_ap_scoreboard_worker(lua_State *L) static int lua_ap_scoreboard_worker(lua_State *L)
{ {
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
request_rec *r;
int i,j; int i,j;
worker_score* ws_record; worker_score* ws_record;
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
luaL_checktype(L, 1, LUA_TUSERDATA); luaL_checktype(L, 1, LUA_TUSERDATA);
luaL_checktype(L, 2, LUA_TNUMBER); luaL_checktype(L, 2, LUA_TNUMBER);
luaL_checktype(L, 3, LUA_TNUMBER); luaL_checktype(L, 3, LUA_TNUMBER);
r = ap_lua_check_request_rec(L, 1);
i = lua_tonumber(L, 2); i = lua_tonumber(L, 2);
j = lua_tonumber(L, 3); j = lua_tonumber(L, 3);
ws_record = ap_get_scoreboard_worker_from_indexes(i, j); ws_record = ap_get_scoreboard_worker_from_indexes(i, j);
@@ -618,7 +609,7 @@ static int lua_ap_requestbody(lua_State *L)
request_rec* r; request_rec* r;
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
r = r = ap_lua_check_request_rec(L, 1); r = ap_lua_check_request_rec(L, 1);
filename = luaL_optstring(L, 2, 0); filename = luaL_optstring(L, 2, 0);
if (r) { if (r) {
@@ -703,7 +694,6 @@ static int lua_ap_add_input_filter(lua_State *L)
static int lua_ap_module_info(lua_State *L) static int lua_ap_module_info(lua_State *L)
{ {
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
request_rec *r;
const char* moduleName; const char* moduleName;
module* mod; module* mod;
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/

View File

@@ -227,7 +227,7 @@ static int req_parsebody(lua_State *L)
int i, z; int i, z;
size_t vlen = 0; size_t vlen = 0;
size_t len = 0; size_t len = 0;
if (lua_read_body(r, &data, &size) != OK) { if (lua_read_body(r, &data, (apr_off_t*) &size) != OK) {
return 2; return 2;
} }
len = strlen(multipart); len = strlen(multipart);
@@ -574,23 +574,20 @@ static int lua_ap_sendfile(lua_State *L)
lua_pushboolean(L, 0); lua_pushboolean(L, 0);
} }
else { else {
if (r) { apr_size_t sent;
apr_size_t sent; apr_status_t rc;
apr_status_t rc; apr_file_t *file;
apr_file_t *file;
rc = apr_file_open(&file, filename, APR_READ, APR_OS_DEFAULT,
rc = apr_file_open(&file, filename, APR_READ, APR_OS_DEFAULT, r->pool);
r->pool); if (rc == APR_SUCCESS) {
if (rc == APR_SUCCESS) { ap_send_fd(file, r, 0, file_info.size, &sent);
ap_send_fd(file, r, 0, file_info.size, &sent); apr_file_close(file);
apr_file_close(file); lua_pushinteger(L, sent);
lua_pushinteger(L, sent);
}
else
lua_pushboolean(L, 0);
} }
else else {
lua_pushboolean(L, 0); lua_pushboolean(L, 0);
}
} }
return (1); return (1);

View File

@@ -83,7 +83,7 @@ typedef enum {
AP_LUA_INHERIT_UNSET = -1, AP_LUA_INHERIT_UNSET = -1,
AP_LUA_INHERIT_NONE = 0, AP_LUA_INHERIT_NONE = 0,
AP_LUA_INHERIT_PARENT_FIRST = 1, AP_LUA_INHERIT_PARENT_FIRST = 1,
AP_LUA_INHERIT_PARENT_LAST = 2, AP_LUA_INHERIT_PARENT_LAST = 2
} ap_lua_inherit_t; } ap_lua_inherit_t;
/** /**