]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps/enc.c: avoid signed integer overflow on bufsize assignment
authorEugene Syromiatnikov <esyr@openssl.org>
Mon, 1 Sep 2025 12:05:33 +0000 (14:05 +0200)
committerNeil Horman <nhorman@openssl.org>
Wed, 3 Sep 2025 11:47:33 +0000 (07:47 -0400)
The calculated option value, while being long-typed, is not checked
for fitting into int-sized bufsize.  Avoid overflow by throwing error
if it is bigger than INT_MAX and document that behaviour.

Fixes: 7e1b7485706c "Big apps cleanup (option-parsing, etc)"
Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=1665149
References: https://github.com/openssl/project/issues/1362
Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28405)

apps/enc.c
doc/man1/openssl-enc.pod.in

index a3133aa25496f78f1d64363222ed3eb3e3d8cdb8..8f5044fbb3b0089ae4279c5cf545459c0a438d41 100644 (file)
@@ -260,6 +260,8 @@ int enc_main(int argc, char **argv)
                 goto opthelp;
             if (k)
                 n *= 1024;
+            if (n > INT_MAX)
+                goto opthelp;
             bsize = (int)n;
             break;
         case OPT_K:
index 4d7ff3dc77e78bb271755999cc111f37df49d05a..7f5dfde57d0677e90ea10d3b41c104c91b4a7188 100644 (file)
@@ -196,6 +196,7 @@ or decryption.
 =item B<-bufsize> I<number>
 
 Set the buffer size for I/O.
+The maximum size that can be specified is B<2^31-1> (2147483647) bytes.
 
 =item B<-nopad>