Skip to content

vcard_emul_rsa_op: assert pad_len >= 3

Uri Lublin requested to merge uril/libcacard:fix_pad_len_assert into master

After the assert, there is a pad_len -= 3; statement. Since pad_len should not be negative, when calling memset, make sure it's 3.

This fixes the following gcc warning when building vcard_emul_nss.c: In file included from /usr/include/string.h:519, from /usr/include/glib-2.0/glib/gslice.h:26, from /usr/include/glib-2.0/glib.h:79, from ../src/vcard_emul_nss.c:14: In function ‘memset’, inlined from ‘vcard_emul_rsa_op.part.0’ at ../src/vcard_emul_nss.c:369:5: /usr/include/bits/string_fortified.h:71:10: warning: ‘memset’ specified
size between 18446744071562067968 and 18446744073709551615 exceeds
maximum object size 9223372036854775807 [-Wstringop-overflow=] 71 | return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I could have replaced the assert condition with pal_len == 3, but decided to keep it as is for readability.

Also, the code below can be simplified, as pad_len==3 in the assert and after the -=3 pad_len==0, but that can be done later.

I did not test this except running meson test

Merge request reports