Avoid information leakage with badly formed download header

Parsing of Content-Disposition relies on well formed headers.
A malformed header such as:

Content-Disposition="";

will result in a strnduppayload->content_disp_name, -1, ptr),
which will copy memory until it hits a \0.

Prevent this by only copying the value if it exists.

Fixes FS#73704.

Signed-off-by: Allan McRae <allan@archlinux.org>
(cherry picked from commit 40583ebe89)
This commit is contained in:
Allan McRae 2022-03-06 21:43:59 +10:00
parent b187daefdf
commit 3bad984871

View file

@ -295,8 +295,11 @@ static size_t dload_parseheader_cb(void *ptr, size_t size, size_t nmemb, void *u
endptr--; endptr--;
} }
STRNDUP(payload->content_disp_name, fptr, endptr - fptr + 1, /* avoid information leakage with badly formed headers */
RET_ERR(payload->handle, ALPM_ERR_MEMORY, realsize)); if(endptr > fptr) {
STRNDUP(payload->content_disp_name, fptr, endptr - fptr + 1,
RET_ERR(payload->handle, ALPM_ERR_MEMORY, realsize));
}
} }
} }