From: Kirill Isakov Date: Wed, 25 May 2022 15:52:42 +0000 (+0600) Subject: Fix UBSAN failure in b64decode_tinc() X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=3528edaeb862e2a223a1384b90b372356d15d777;p=tinc Fix UBSAN failure in b64decode_tinc() ../src/utils.c:141:14: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned) #0 0x478d06 in b64decode_tinc /home/runner/work/tinc/tinc/openssl3/../src/utils.c:141:14 #1 0x437f6c in dump_invitations /home/runner/work/tinc/tinc/openssl3/../src/tincctl.c:1116:6 #2 0x42ebf6 in cmd_dump /home/runner/work/tinc/tinc/openssl3/../src/tincctl.c:1190:10 #3 0x42b4c5 in run_command /home/runner/work/tinc/tinc/openssl3/../src/tincctl.c:3315:11 #4 0x42aa24 in main /home/runner/work/tinc/tinc/openssl3/../src/tincctl.c:3366:15 #5 0x7f6fb7a4c082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) #6 0x406e2d in _start (/home/runner/work/tinc/tinc/openssl3/src/tinc+0x406e2d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/utils.c:141:14 in --- diff --git a/src/utils.c b/src/utils.c index 231938dc..8655e2be 100644 --- a/src/utils.c +++ b/src/utils.c @@ -138,7 +138,7 @@ size_t b64decode_tinc(const char *src, void *dst, size_t length) { unsigned char *udst = (unsigned char *)dst; for(i = 0; i < length && src[i]; i++) { - triplet |= base64_decode[src[i] & 0xff] << (6 * (i & 3)); + triplet |= (uint32_t)(base64_decode[src[i] & 0xff] << (6 * (i & 3))); if((i & 3) == 3) { if(triplet & 0xff000000U) {