Add strncpy and strncat to banned function list as we have better replacements: strlcpy and strlcat.

remotes/origin/master-1.1.x
Victor Julien 16 years ago
parent 0814e41e50
commit 076d77cd80

@ -1,5 +1,5 @@
@banned@ @banned@
identifier func ~= "^\(sprintf\|strcat\|strcpy\)$"; identifier func ~= "^\(sprintf\|strcat\|strcpy\|strncpy\|strncat\)$";
position p1; position p1;
@@ @@

@ -110,11 +110,11 @@ void hexdump(/*Flow *f,*/ const void *buf, size_t len) {
/* store hex str (for left side) */ /* store hex str (for left side) */
snprintf(bytestr, sizeof(bytestr), "%02X ", *p); snprintf(bytestr, sizeof(bytestr), "%02X ", *p);
strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1); strlcat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1);
/* store char str (for right side) */ /* store char str (for right side) */
snprintf(bytestr, sizeof(bytestr), "%c", c); snprintf(bytestr, sizeof(bytestr), "%c", c);
strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1); strlcat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1);
if(n%16 == 0) { if(n%16 == 0) {
/* line completed */ /* line completed */
@ -123,8 +123,8 @@ void hexdump(/*Flow *f,*/ const void *buf, size_t len) {
charstr[0] = 0; charstr[0] = 0;
} else if(n%8 == 0) { } else if(n%8 == 0) {
/* half line: add whitespaces */ /* half line: add whitespaces */
strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1); strlcat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1);
strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1); strlcat(charstr, " ", sizeof(charstr)-strlen(charstr)-1);
} }
p++; /* next byte */ p++; /* next byte */
} }

@ -503,7 +503,7 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) {
SCFree(ptv); SCFree(ptv);
SCReturnInt(TM_ECODE_FAILED); SCReturnInt(TM_ECODE_FAILED);
} }
strncpy(ptv->iface, PCAP_IFACE_NAME_LENGTH, initdata); strlcpy(ptv->iface, PCAP_IFACE_NAME_LENGTH, (char *)initdata);
char errbuf[PCAP_ERRBUF_SIZE] = ""; char errbuf[PCAP_ERRBUF_SIZE] = "";
ptv->pcap_handle = pcap_open_live((char *)initdata, LIBPCAP_SNAPLEN, ptv->pcap_handle = pcap_open_live((char *)initdata, LIBPCAP_SNAPLEN,

@ -69,7 +69,7 @@ int GetIfaceMTU(char *pcap_dev)
struct ifreq ifr; struct ifreq ifr;
int fd; int fd;
(void)strncpy(ifr.ifr_name, pcap_dev, sizeof(ifr.ifr_name)); (void)strlcpy(ifr.ifr_name, pcap_dev, sizeof(ifr.ifr_name));
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd == -1) { if (fd == -1) {
return -1; return -1;

@ -228,8 +228,8 @@ int SCServiceInstall(int argc, char **argv)
if ((strlen(argv[i]) <= strlen("--service-install")) && (strncmp("--service-install", argv[i], strlen(argv[i])) == 0)) { if ((strlen(argv[i]) <= strlen("--service-install")) && (strncmp("--service-install", argv[i], strlen(argv[i])) == 0)) {
continue; continue;
} }
strncat(path, " ", sizeof(path) - strlen(path) - 1); strlcat(path, " ", sizeof(path) - strlen(path) - 1);
strncat(path, argv[i], sizeof(path) - strlen(path) - 1); strlcat(path, argv[i], sizeof(path) - strlen(path) - 1);
} }
if ((scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL) { if ((scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL) {
@ -353,8 +353,8 @@ int SCServiceChangeParams(int argc, char **argv)
if ((strlen(argv[i]) <= strlen("--service-change-params")) && (strncmp("--service-change-params", argv[i], strlen(argv[i])) == 0)) { if ((strlen(argv[i]) <= strlen("--service-change-params")) && (strncmp("--service-change-params", argv[i], strlen(argv[i])) == 0)) {
continue; continue;
} }
strncat(path, " ", sizeof(path) - strlen(path) - 1); strlcat(path, " ", sizeof(path) - strlen(path) - 1);
strncat(path, argv[i], sizeof(path) - strlen(path) - 1); strlcat(path, argv[i], sizeof(path) - strlen(path) - 1);
} }
if ((scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL) { if ((scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL) {

Loading…
Cancel
Save