1
0
mirror of https://git.tukaani.org/xz.git synced 2026-10-31 03:14:56 +00:00

xz: Fix use-after-free in verbose error message to a non-tty

If --verbose was used when stderr isn't a terminal, the filename
contained a non-printable character, and an error occurred,
a use-after-free occurred when printing the error message.

The bug exists in versions 5.7.1alpha to 5.8.3.

Reported-by: Omkhar Arasaratnam
Fixes: d22f96921fd2 ("xz: Use tuklib_mbstr_nonprint")
This commit is contained in:
Lasse Collin 2026-05-19 12:34:53 +03:00
parent ebb0e6789c
commit 327c906dcd
No known key found for this signature in database
GPG Key ID: 38EE757D69184620

View File

@ -650,7 +650,14 @@ progress_flush(bool finished)
cols[4]);
} else {
// The filename is always printed.
fprintf(stderr, _("%s: "), tuklib_mask_nonprint(filename));
//
// NOTE: This function is called from vmessage() whose
// caller may have used tuklib_mask_nonprint(). Thus,
// we must use the _r variant here.
char *mem = NULL;
fprintf(stderr, _("%s: "),
tuklib_mask_nonprint_r(filename, &mem));
free(mem);
// Percentage is printed only if we didn't finish yet.
if (!finished) {