]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
stdio-common: Fix UB on stdio-common/vfprintf-process-arg.c
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 24 Apr 2025 12:41:11 +0000 (09:41 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:25:44 +0000 (09:25 -0300)
On i686 debug/tst-sprintf-fortify-unchecked triggers:

UBSAN: Undefined behaviour in vfprintf-process-arg.c:41:57 negation of 9223372036854775808 cannot be represented in type 'long long int'

stdio-common/vfprintf-process-arg.c

index a41feb2c472a53b5795444c33a6b77dda584c485..fd23213e7eeb5805e3ae52527d16f0c99b2f5def 100644 (file)
@@ -38,7 +38,8 @@ LABEL (form_integer):
     {
       long long int signed_number = process_arg_long_long_int ();
       is_negative = signed_number < 0;
-      number.longlong = is_negative ? (- signed_number) : signed_number;
+      number.longlong = is_negative ? (- (unsigned long long) signed_number)
+                                   : signed_number;
 
       goto LABEL (longlong_number);
     }