Skip to content

Commit

Permalink
Make macro safer when strlcpy() is not available
Browse files Browse the repository at this point in the history
Macro would previously trigger an out-of-bound write if passed a size of
zero. Also, the size was not protected against a possible operator
precedence issue.

Signed-off-by: Loren M. Lang <[email protected]>
Signed-off-by: Aaron Conole <[email protected]>
  • Loading branch information
penguin359 authored and apconole committed Aug 16, 2024
1 parent 96106e8 commit 6c947ee
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/lldp.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ typedef __u64 u64;
#else
#define STRNCPY_TERMINATED(DEST, SRC, N) \
do { \
strncpy (DEST, SRC, N - 1); \
DEST[N - 1] = '\0'; \
if((N) > 0) { \
strncpy (DEST, SRC, (N) - 1); \
DEST[(N) - 1] = '\0'; \
} \
} while (false)
#endif

Expand Down

0 comments on commit 6c947ee

Please sign in to comment.