eworm-de / mkinitcpio-ykfde

Full disk encryption with Yubikey (Yubico key)
GNU General Public License v3.0
109 stars 26 forks source link

gcc 8: error: 'strncpy' specified bound 108 equals destination size [-Werror=stringop-truncation] #25

Closed bpereto closed 6 years ago

bpereto commented 6 years ago

gcc (GCC) 8.0.1 20180317 (Red Hat 8.0.1-0.19)

gcc -std=gnu11 -O2 -fPIC -Wall -Werror -larchive -Wl,-z,now -Wl,-z,relro -pie -o ykfde-cpio ykfde-cpio.c
sed -i 's/\(README[-[:alnum:]]*\).md/\1.html/g' README-mkinitcpio.html
gcc -std=gnu11 -O2 -fPIC -Wall -Werror -liniparser -lkeyutils -lykpers-1 -lyubikey -lsystemd  -lcryptsetup -Wl,-z,now -Wl,-z,relro -pie -o ykfde ykfde.c
gcc -std=gnu11 -O2 -fPIC -Wall -Werror -liniparser -lkeyutils -lykpers-1 -lyubikey -lsystemd  -Wl,-z,now -Wl,-z,relro -pie -o worker worker.c
sed -i 's/\(README[-[:alnum:]]*\).md/\1.html/g' README-dracut.html
In function 'send_on_socket.constprop',
    inlined from 'answer_askpass' at worker.c:288:6,
    inlined from 'walk_askpass' at worker.c:321:15,
    inlined from 'main' at worker.c:395:12:
worker.c:66:2: error: 'strncpy' specified bound 108 equals destination size [-Werror=stringop-truncation]
  strncpy(sa.un.sun_path, socket_name, sizeof(sa.un.sun_path));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
suyash0103 commented 2 years ago

How was this issue resolved?

eworm-de commented 2 years ago

By committing 2c1c626ca971741ffca2ed22d77545f6befe0632.

suyash0103 commented 2 years ago

@eworm-de Thanks! I guess the reason for this would be hidden in the internal implementation of memcpy and strncpy

eworm-de commented 2 years ago

The problem is that strncpy() may want to append a trailing null byte that does not fit. We do not need that, so memcpy() is fine.