Commit c0e857c9 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Make SAFECOPY() even safer by not passing NULL destination to strncpy()

This should resolve (new) CID 434884 and 434885.

Also, remove the SAFECOPY_USES_SPRINTF check/block - nobody enables this.
parent 11255c6f
Pipeline #3664 passed with stage
in 6 minutes and 13 seconds
......@@ -430,11 +430,7 @@ typedef struct {
#define TERMINATE(str) str[sizeof(str)-1]=0
/* This is a bound-safe version of strcpy basically - only works with fixed-length arrays */
#ifdef SAFECOPY_USES_SPRINTF
#define SAFECOPY(dst,src) sprintf(dst,"%.*s",(int)sizeof(dst)-1,src)
#else /* strncpy is faster */
#define SAFECOPY(dst,src) (strncpy(dst,src,sizeof(dst)), TERMINATE(dst))
#endif
#define SAFECOPY(dst,src) (strncpy(dst,(src)==NULL?"(null)":(src),sizeof(dst)), TERMINATE(dst))
#define SAFECAT(dst, src) do { \
if(strlen((char*)(dst)) + strlen((char*)(src)) < sizeof(dst)) { \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment