]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
string: Fix UB on gneric strncmp
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 22 Apr 2025 17:35:39 +0000 (14:35 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:21:21 +0000 (14:21 -0300)
Building with ubsan it triggers:

UBSAN: Undefined behaviour in ../string/strncmp.c:103:12 shift exponent 32 is too large for 32-bit type 'int'

Use an unsigned constant literal for MERGE, since op_t is defined
as unsigned.

string/strncmp.c

index 79a21c12a3ac3d6a2fb1ce27a3160933a24267eb..746d5acc2559d75b8a1cbcb6b416dc4e655dd176 100644 (file)
@@ -100,7 +100,7 @@ strncmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs,
 
       /* Load the final word of P1 and align the final partial of P2.  */
       w1 = *x1++;
-      w2 = MERGE (w2b, sh_1, 0, sh_2);
+      w2 = MERGE (w2b, sh_1, 0UL, sh_2);
     }
 
   return final_cmp (w1, w2, n);