prevent invalid reads of nl_arg in printf_core
authorMarkus Wichmann <nullplan@gmx.net>
Thu, 3 Nov 2022 19:42:16 +0000 (20:42 +0100)
committerRich Felker <dalias@aerifal.cx>
Wed, 14 Dec 2022 15:03:37 +0000 (10:03 -0500)
commit7d358599d4c8f793cfb42ee49ff5e1d107de6ee4
tree6039a28651b26d731d556d6a5da05c2a7b0a962b
parentc5f4b2dfea320356f69445dc1adf8f73596a3c36
prevent invalid reads of nl_arg in printf_core

printf_core() runs twice, and during its first run, nl_arg is
uninitialized and must not be read. It gets initialized at the end of
the first run. Conversely, nl_type does not need to be set during the
second run, as its useful life has ended at that point, since the only
time it is read is during that exact same initialization. Therefore we
can simply alternate the assignments.

p and w do still need to get values assigned to them, since at least one
line in the same if-statement depends on that, but they can be dummy
values. arg does not need to be assigned, since in the first run, we
encounter a continue statement before using the argument.
src/stdio/vfprintf.c