]> git.ipfire.org Git - thirdparty/openssl.git/commit
crypto/bio/bio_print.c: make %n in line with other libc implementations
authorEugene Syromiatnikov <esyr@openssl.org>
Fri, 15 Aug 2025 14:00:50 +0000 (16:00 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 29 Aug 2025 16:18:30 +0000 (12:18 -0400)
commit228ef5f5472790e64c14596ef6d3d698875ffd61
tree64c6f0c9e6c9488a53cdde156e8d99b269958ccf
parenta8d02c5ca706384c53c941b3041c326c62a6f09e
crypto/bio/bio_print.c: make %n in line with other libc implementations

The standard[1] is pretty vague in its definition of the %n specifier
by using "the number of bytes written to the output so far", without
actually elaborating, whether only the actually written bytes, or the bytes
that would be written (but discarded) are used;  the consensus across
implementations, however, seems to gravitate towards the latter.  Track
the virtual "write position" separately and use its value when %n format
is occurred.  That also means that we cannot finish the output early
upon reach of the end of buffer (unless we made sure that no %n specifiers
occur in the remainder of the format string).

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html

Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28177)
crypto/bio/bio_print.c