Sync r1895107 from libapreq.
@@ -422,22 +422,27 @@ APREQ_DECLARE_PARSER(apreq_parse_multipart)
goto mfd_parse_brigade;
}
- next_ctx->param_name = "";
-
if (cd != NULL) {
s = apreq_header_attribute(cd, "name", 4,
&name, &nlen);
- if (s == APR_SUCCESS) {
- next_ctx->param_name
- = apr_pstrmemdup(pool, name, nlen);
+ if (s == APR_SUCCESS && nlen) {
+ next_ctx->param_name = apr_pstrmemdup(pool, name,
+ nlen);
}
- else {
+ else if (s != APREQ_ERROR_NOATTR) {
+ ctx->status = MFD_ERROR;
+ goto mfd_parse_brigade;
+ }
+ }
+ if (!next_ctx->param_name) {
const char *cid = apr_table_get(ctx->info,
"Content-ID");
- if (cid != NULL)
+ if (cid) {
next_ctx->param_name = apr_pstrdup(pool, cid);
}
-
+ else {
+ next_ctx->param_name = "";
+ }
}
ctx->next_parser = apreq_parser_make(pool, ba, ct,
@@ -455,14 +460,14 @@ APREQ_DECLARE_PARSER(apreq_parse_multipart)
if (cd != NULL && strncmp(cd, "form-data", 9) == 0) {
s = apreq_header_attribute(cd, "name", 4, &name, &nlen);
- if (s != APR_SUCCESS) {
+ if (s != APR_SUCCESS || !nlen) {
ctx->status = MFD_ERROR;
goto mfd_parse_brigade;
}
s = apreq_header_attribute(cd, "filename",
8, &filename, &flen);
- if (s == APR_SUCCESS) {
+ if (s == APR_SUCCESS && flen) {
apreq_param_t *param;
param = apreq_param_make(pool, name, nlen,
@@ -475,6 +480,10 @@ APREQ_DECLARE_PARSER(apreq_parse_multipart)
ctx->status = MFD_UPLOAD;
goto mfd_parse_brigade;
}
+ else if (s != APREQ_ERROR_NOATTR) {
+ ctx->status = MFD_ERROR;
+ goto mfd_parse_brigade;
+ }
else {
ctx->param_name = apr_pstrmemdup(pool, name, nlen);
ctx->status = MFD_PARAM;
@@ -488,7 +497,7 @@ APREQ_DECLARE_PARSER(apreq_parse_multipart)
s = apreq_header_attribute(cd, "filename",
8, &filename, &flen);
- if (s != APR_SUCCESS || ctx->param_name == NULL) {
+ if (s != APR_SUCCESS || !flen || !ctx->param_name) {
ctx->status = MFD_ERROR;
goto mfd_parse_brigade;
}
