From: Eugene Syromiatnikov Date: Fri, 25 Jul 2025 16:55:26 +0000 (+0200) Subject: crypto/bio/bio_print.c: support hh length modifier in _dopr X-Git-Tag: openssl-3.6.0-alpha1~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f8beb7ce9be114dcb03d7dd7b1521235ec24958;p=thirdparty%2Fopenssl.git crypto/bio/bio_print.c: support hh length modifier in _dopr Per [1]: hh Specifies that a following d, i, o, u, x, or X conversion specifier applies to a signed char or unsigned char argument [1] https://pubs.opengroup.org/onlinepubs/9799919799//functions/printf.html Signed-off-by: Eugene Syromiatnikov Reviewed-by: Saša Nedvědický Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/28177) --- diff --git a/crypto/bio/bio_print.c b/crypto/bio/bio_print.c index b987ecd750f..f6db6d3bfc1 100644 --- a/crypto/bio/bio_print.c +++ b/crypto/bio/bio_print.c @@ -68,11 +68,12 @@ static int _dopr(char **sbuffer, char **buffer, #define DP_F_UNSIGNED (1 << 6) /* conversion flags */ -#define DP_C_SHORT 1 -#define DP_C_LONG 2 -#define DP_C_LDOUBLE 3 -#define DP_C_LLONG 4 -#define DP_C_SIZE 5 +#define DP_C_CHAR 1 +#define DP_C_SHORT 2 +#define DP_C_LONG 3 +#define DP_C_LDOUBLE 4 +#define DP_C_LLONG 5 +#define DP_C_SIZE 6 /* Floating point formats */ #define F_FORMAT 0 @@ -182,7 +183,12 @@ _dopr(char **sbuffer, case DP_S_MOD: switch (ch) { case 'h': - cflags = DP_C_SHORT; + if (*format == 'h') { + cflags = DP_C_CHAR; + format++; + } else { + cflags = DP_C_SHORT; + } ch = *format++; break; case 'l': @@ -216,6 +222,9 @@ _dopr(char **sbuffer, case 'd': case 'i': switch (cflags) { + case DP_C_CHAR: + value = (signed char)va_arg(args, int); + break; case DP_C_SHORT: value = (short int)va_arg(args, int); break; @@ -244,6 +253,9 @@ _dopr(char **sbuffer, case 'u': flags |= DP_F_UNSIGNED; switch (cflags) { + case DP_C_CHAR: + value = (unsigned char)va_arg(args, unsigned int); + break; case DP_C_SHORT: value = (unsigned short int)va_arg(args, unsigned int); break;