Skip to content
Snippets Groups Projects
Commit c0e857c9 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
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
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3664 passed
......@@ -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)) { \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment