Warning while compiling and error after running
dannyrock opened this issue · 1 comments
dannyrock commented
cc -std=c99 -O2 -fPIC -finline-functions -Wall -W -Wunused -pedantic -Wpointer-arith -Wreturn-type -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wcast-qual -Wextra -o eschalot eschalot.c -lpthread -lssl -lcrypto
In function ‘setoptions’,
inlined from ‘main’ at eschalot.c:172:2:
eschalot.c:788:4: warning: ‘strncpy’ specified bound 17 equals destination size [-Wstringop-truncation]
strncpy(prefix, optarg, ONION_LENP1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc -std=c99 -O2 -fPIC -finline-functions -Wall -W -Wunused -pedantic -Wpointer-arith -Wreturn-type -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wcast-qual -Wextra -o worgen worgen.c
while running
root@io:/opt/eschalot/eschalot# ./eschalot -ct5 -p test
ERROR: malloc(buf->length + 1) failed!
judearich commented
The error happened because malloc
couldn't allocate enough memory, so the program aborted.
The warning happened because of this call to strncpy
. The size of prefix
is exactly ONION_LENP1
, so the string might not be null-terminated.
I would suggest to a developer to use snprintf
, since it guarantees the string to be null terminated.