From: Eugene Syromiatnikov Date: Fri, 15 Aug 2025 14:07:24 +0000 (+0200) Subject: crypto/bio/bio_print.c: bring back the length modifier support for %n X-Git-Tag: openssl-3.6.0-alpha1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b16781c5b84e13e1429d58e10c65a51bc6fc224;p=thirdparty%2Fopenssl.git crypto/bio/bio_print.c: bring back the length modifier support for %n For some reason, it has been removed in commit 15b337fa58ba "bio/b_print.c: switch to int64_t as "greatest-width integer type".", despite being a part of the standard in both ANSI C and POSIX.1-2001. Bring it back for all the supported length modifiers. 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 186c3cdef2b..5f2afdde4cd 100644 --- a/crypto/bio/bio_print.c +++ b/crypto/bio/bio_print.c @@ -375,12 +375,8 @@ _dopr(char **sbuffer, break; case 's': strvalue = va_arg(args, char *); - if (max < 0) { - if (buffer || *maxlen > INT_MAX) - max = INT_MAX; - else - max = (int)*maxlen; - } + if (max < 0) + max = INT_MAX; if (!fmtstr(&desc, strvalue, flags, min, max)) goto out; break; @@ -390,7 +386,36 @@ _dopr(char **sbuffer, goto out; break; case 'n': - *num = (int)desc.pos; + switch (cflags) { +#define HANDLE_N(type) \ + do { \ + type *num; \ + \ + num = va_arg(args, type *); \ + *num = (type) desc.pos; \ + } while (0) + case DP_C_CHAR: + HANDLE_N(signed char); + break; + case DP_C_SHORT: + HANDLE_N(short); + break; + case DP_C_LONG: + HANDLE_N(long); + break; + case DP_C_LLONG: + HANDLE_N(long long); + break; + case DP_C_SIZE: + HANDLE_N(ossl_ssize_t); + break; + case DP_C_PTRDIFF: + HANDLE_N(ptrdiff_t); + break; + default: + HANDLE_N(int); + break; +#undef HANDLE_N } break; case '%':