1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Sanitize value sent to memset to prevent SEGFAULT

This commit is contained in:
Darshit Shah 2016-02-22 15:08:15 +01:00
parent 75e5be7aad
commit 7099f48998

View File

@ -1164,6 +1164,8 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
} }
padding = bp->width - count_cols (bp->buffer); padding = bp->width - count_cols (bp->buffer);
assert (padding > 0 && "Padding length became non-positive!");
padding = padding > 0 ? padding : 0;
memset (p, ' ', padding); memset (p, ' ', padding);
p += padding; p += padding;
*p = '\0'; *p = '\0';
@ -1174,6 +1176,9 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
* from the release code since we do not want Wget to crash and burn when the * from the release code since we do not want Wget to crash and burn when the
* assertion fails. Instead Wget should continue downloading and display a * assertion fails. Instead Wget should continue downloading and display a
* horrible and irritating progress bar that spams the screen with newlines. * horrible and irritating progress bar that spams the screen with newlines.
*
* By default, all assertions are disabled in a Wget build and are enabled
* only with the --enable-assert configure option.
*/ */
assert (count_cols (bp->buffer) == bp->width); assert (count_cols (bp->buffer) == bp->width);
} }