1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-07 04:02:58 +03:00

mod_lua: Error out if lua_read_body() or lua_write_body() fail.

Otherwise r:requestbody() or r:parsebody() failures might go unnoticed for
the user.



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1898689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yann Ylavic
2022-03-07 14:07:02 +00:00
parent 6418c66ab6
commit 3e561918fb

View File

@@ -235,14 +235,16 @@ static int lua_read_body(request_rec *r, const char **rbuf, apr_off_t *size,
{ {
int rc = OK; int rc = OK;
*rbuf = NULL;
*size = 0;
if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) { if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) {
return (rc); return (rc);
} }
if (ap_should_client_block(r)) { if (ap_should_client_block(r)) {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
char argsbuffer[HUGE_STRING_LEN]; apr_off_t len_read, rpos = 0;
apr_off_t rsize, len_read, rpos = 0;
apr_off_t length = r->remaining; apr_off_t length = r->remaining;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@@ -250,18 +252,18 @@ static int lua_read_body(request_rec *r, const char **rbuf, apr_off_t *size,
return APR_EINCOMPLETE; /* Only room for incomplete data chunk :( */ return APR_EINCOMPLETE; /* Only room for incomplete data chunk :( */
} }
*rbuf = (const char *) apr_pcalloc(r->pool, (apr_size_t) (length + 1)); *rbuf = (const char *) apr_pcalloc(r->pool, (apr_size_t) (length + 1));
*size = length; while ((rpos < length)
while ((len_read = ap_get_client_block(r, argsbuffer, sizeof(argsbuffer))) > 0) { && (len_read = ap_get_client_block(r, (char *) *rbuf + rpos,
if ((rpos + len_read) > length) { length - rpos)) > 0) {
rsize = length - rpos; rpos += len_read;
}
else {
rsize = len_read;
}
memcpy((char *) *rbuf + rpos, argsbuffer, (size_t) rsize);
rpos += rsize;
} }
if (len_read < 0) {
return APR_EINCOMPLETE;
}
*size = rpos;
}
else {
rc = DONE;
} }
return (rc); return (rc);
@@ -278,6 +280,8 @@ static apr_status_t lua_write_body(request_rec *r, apr_file_t *file, apr_off_t *
{ {
apr_status_t rc = OK; apr_status_t rc = OK;
*size = 0;
if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)))
return rc; return rc;
if (ap_should_client_block(r)) { if (ap_should_client_block(r)) {
@@ -303,6 +307,9 @@ static apr_status_t lua_write_body(request_rec *r, apr_file_t *file, apr_off_t *
rpos += rsize; rpos += rsize;
} }
} }
else {
rc = DONE;
}
return rc; return rc;
} }