Skip to content

Commit f652d7b

Browse files
committed
Add missing checks for ipcrypt_str_to_ip16
I noticed that gcc was complaining about possibly using uninitialized memory: ``` In file included from /usr/include/string.h:548, from ipcrypt2.c:37: In function 'memcpy', inlined from 'ipcrypt_nd_encrypt_ip16' at ipcrypt2.c:1349:5, inlined from 'ipcrypt_nd_encrypt_ip_str' at ipcrypt2.c:1388:5: /usr/include/bits/string_fortified.h:29:10: warning: 'ip16' may be used uninitialized [-Wmaybe-uninitialized] 29 | return __builtin___memcpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30 | __glibc_objsize0 (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ ipcrypt2.c: In function 'ipcrypt_nd_encrypt_ip_str': ipcrypt2.c:1381:13: note: 'ip16' declared here 1381 | uint8_t ip16[16]; | ^~~~ ``` which seems indeed possible if the IPv6 address could not be parsed. Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
1 parent 70a4daf commit f652d7b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/ipcrypt2.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,9 @@ ipcrypt_nd_encrypt_ip_str(const IPCrypt *ipcrypt, char encrypted_ip_str[IPCRYPT_
13831383

13841384
COMPILER_ASSERT(IPCRYPT_NDIP_STR_BYTES == IPCRYPT_NDIP_BYTES * 2 + 1);
13851385
// Convert to 16-byte IP.
1386-
ipcrypt_str_to_ip16(ip16, ip_str);
1386+
if (ipcrypt_str_to_ip16(ip16, ip_str) != 0) {
1387+
return 0;
1388+
}
13871389
// Perform non-deterministic encryption.
13881390
ipcrypt_nd_encrypt_ip16(ipcrypt, ndip, ip16, random);
13891391
// Convert the 24-byte ndip to a hex string.
@@ -1468,7 +1470,9 @@ ipcrypt_ndx_encrypt_ip_str(const IPCryptNDX *ipcrypt,
14681470

14691471
COMPILER_ASSERT(IPCRYPT_NDX_NDIP_STR_BYTES == IPCRYPT_NDX_NDIP_BYTES * 2 + 1);
14701472
// Convert to 16-byte IP.
1471-
ipcrypt_str_to_ip16(ip16, ip_str);
1473+
if (ipcrypt_str_to_ip16(ip16, ip_str) != 0) {
1474+
return 0;
1475+
}
14721476
// Perform non-deterministic encryption.
14731477
ipcrypt_ndx_encrypt_ip16(ipcrypt, ndip, ip16, random);
14741478
// Convert the 32-byte ndip to a hex string.

0 commit comments

Comments
 (0)