Avoid pointer UB in strip_header

Don't calculate header_start if lc_header_start is NULL, as we're
going to overflow the address space in that case.
This commit is contained in:
Nikita Popov 2019-09-03 12:01:56 +02:00
parent 265af40a0a
commit 518c651c66

View File

@ -86,11 +86,10 @@ static inline void strip_header(char *header_bag, char *lc_header_bag,
const char *lc_header_name)
{
char *lc_header_start = strstr(lc_header_bag, lc_header_name);
char *header_start = header_bag + (lc_header_start - lc_header_bag);
if (lc_header_start
&& (lc_header_start == lc_header_bag || *(lc_header_start-1) == '\n')
) {
char *header_start = header_bag + (lc_header_start - lc_header_bag);
char *lc_eol = strchr(lc_header_start, '\n');
char *eol = header_start + (lc_eol - lc_header_start);