Skip to content

lib/util-xstrcpy.c: strcpy_or_abort: Actually abort() in -DNDEBUG builds #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/util-xstrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "crypt-port.h"

#include <stdlib.h>

/* Provide a safe way to copy strings with the guarantee src,
including its terminating '\0', will fit d_size bytes.
The trailing bytes of d_size will be filled with '\0'.
Expand All @@ -30,7 +32,9 @@
assert (dst != NULL);
assert (src != NULL);
size_t s_size = strlen ((const char *)src);
assert (d_size >= s_size + 1);
assert (d_size > s_size);
if (!(d_size > s_size)) /* for NDEBUG builds */
abort();

Check warning on line 37 in lib/util-xstrcpy.c

View check run for this annotation

Codecov / codecov/patch

lib/util-xstrcpy.c#L37

Added line #L37 was not covered by tests

memcpy (dst, src, s_size);
memset (((char *)dst) + s_size, 0, d_size - s_size);
Expand Down