malloc(strlen(X) + 1) followed by strcpy(result-of-malloc, str) is
equivalent to strdup(str); use that, so people don't freak out upon seeing a strcpy() call that, out of context, looks as if it's not buffer-overflow-safe.
This commit is contained in:
parent
f254ca4520
commit
0a9a829a65
|
@ -51,7 +51,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/Win32/Src/getaddrinfo.c,v 1.2 2003-11-15 23:24:06 guy Exp $";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/Win32/Src/getaddrinfo.c,v 1.3 2008-09-15 23:37:51 guy Exp $";
|
||||
#endif
|
||||
|
||||
#include <pcap-stdinc.h>
|
||||
|
@ -981,10 +981,9 @@ get_canonname(pai, ai, str)
|
|||
const char *str;
|
||||
{
|
||||
if ((pai->ai_flags & AI_CANONNAME) != 0) {
|
||||
ai->ai_canonname = (char *)malloc(strlen(str) + 1);
|
||||
ai->ai_canonname = strdup(str);
|
||||
if (ai->ai_canonname == NULL)
|
||||
return EAI_MEMORY;
|
||||
strcpy(ai->ai_canonname, str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Reference in New Issue