]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/bio/bio_print.c: bring back the length modifier support for %n
authorEugene Syromiatnikov <esyr@openssl.org>
Fri, 15 Aug 2025 14:07:24 +0000 (16:07 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 29 Aug 2025 16:18:30 +0000 (12:18 -0400)
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 <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

index 186c3cdef2b8c6e0d94eaabb252086b78adf6c05..5f2afdde4cd2a916a3229161983d0e4180b1c52f 100644 (file)
@@ -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 '%':