]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
posix: remove deprecated index/rindex calls
authorVictor Julien <victor@inliniac.net>
Wed, 25 Sep 2019 20:23:51 +0000 (22:23 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 26 Sep 2019 09:04:25 +0000 (11:04 +0200)
Replace index by strchr and rindex by strrchr.

index(3) states "POSIX.1-2008 removes the specifications of index() and
rindex(), recommending strchr(3) and strrchr(3) instead."

Add index/rindex to banned function check so they don't get reintroduced.

Bug #1443.

configure.ac
qa/coccinelle/banned-functions.cocci
src/decode.c
src/detect-dce-opnum.c
src/output-json-stats.c
src/util-affinity.c
src/util-debug.c
src/util-host-os-info.c
src/win32-misc.h

index 48e026817a3f32f9a318dfbb1b19c9ad8a6f4b15..b219eaefaa185d686e89921be59387fa3efc8b21 100644 (file)
     # Checks for library functions.
     AC_FUNC_MALLOC
     AC_FUNC_REALLOC
-    AC_CHECK_FUNCS([gettimeofday memset strcasecmp strchr strdup strndup strerror strncasecmp strtol strtoul memchr memrchr clock_gettime])
+    AC_CHECK_FUNCS([gettimeofday memset strcasecmp strchr strrchr strdup strndup strerror strncasecmp strtol strtoul memchr memrchr clock_gettime])
     AC_CHECK_FUNCS([strptime])
 
     AC_CHECK_DECL([getrandom],
index e011cb3bf2ef9fcc29e19c66167782c73127a453..d64aa728a4cc8c16c4218000d14e80aa5ae81642 100644 (file)
@@ -3,7 +3,7 @@ identifier i;
 position p1;
 @@
 
-\(strtok@i\|sprintf@i\|strcat@i\|strcpy@i\|strncpy@i\|strncat@i\|strndup@i\|strchrnul@i\|rand@i\|rand_r@i\|memmem@i\)(...)@p1
+\(strtok@i\|sprintf@i\|strcat@i\|strcpy@i\|strncpy@i\|strncat@i\|strndup@i\|strchrnul@i\|rand@i\|rand_r@i\|memmem@i\|index@i\|rindex@i\)(...)@p1
 
 @script:python@
 p1 << banned.p1;
index 4f32c41067494f9293eed461de962cb2deb37740..a0ad4a6ce988a7a8b34eab102a2de8bf7351aa1c 100644 (file)
@@ -547,7 +547,7 @@ void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
             }
 
             char name[256];
-            char *dot = index(DEvents[i].event_name, '.');
+            char *dot = strchr(DEvents[i].event_name, '.');
             BUG_ON(!dot);
             snprintf(name, sizeof(name), "%s.%s",
                     stats_decoder_events_prefix, dot+1);
index 8d841d6e36c527bed2f43458506e4eaadf9213c1..93c83e98db4cbc4019e028bc5dd397eddce4d238 100644 (file)
@@ -157,7 +157,7 @@ static DetectDceOpnumData *DetectDceOpnumArgParse(const char *arg)
      * once we are done using it */
     dup_str_head = dup_str;
     dup_str_temp = dup_str;
-    while ( (comma_token = index(dup_str, ',')) != NULL) {
+    while ( (comma_token = strchr(dup_str, ',')) != NULL) {
         comma_token[0] = '\0';
         dup_str = comma_token + 1;
 
@@ -172,7 +172,7 @@ static DetectDceOpnumData *DetectDceOpnumArgParse(const char *arg)
             prev_dor = dor;
         }
 
-        if ((hyphen_token = index(dup_str_temp, '-')) != NULL) {
+        if ((hyphen_token = strchr(dup_str_temp, '-')) != NULL) {
             hyphen_token[0] = '\0';
             hyphen_token++;
             dor->range1 = atoi(dup_str_temp);
@@ -200,7 +200,7 @@ static DetectDceOpnumData *DetectDceOpnumArgParse(const char *arg)
         prev_dor->next = dor;
     }
 
-    if ( (hyphen_token = index(dup_str, '-')) != NULL) {
+    if ( (hyphen_token = strchr(dup_str, '-')) != NULL) {
         hyphen_token[0] = '\0';
         hyphen_token++;
         dor->range1 = atoi(dup_str);
index c6e7e3844edb66d980684bc69c2a6035c0d4bac4..b22b8df7cf192311fd904b1effa2e031a743866c 100644 (file)
@@ -171,12 +171,12 @@ static json_t *OutputStats2Json(json_t *js, const char *key)
 {
     void *iter;
 
-    const char *dot = index(key, '.');
+    const char *dot = strchr(key, '.');
     if (dot == NULL)
         return NULL;
     if (strlen(dot) > 2) {
         if (*(dot + 1) == '.' && *(dot + 2) != '\0')
-            dot = index(dot + 2, '.');
+            dot = strchr(dot + 2, '.');
     }
 
     size_t predot_len = (dot - key) + 1;
@@ -184,7 +184,7 @@ static json_t *OutputStats2Json(json_t *js, const char *key)
     strlcpy(s, key, predot_len);
 
     iter = json_object_iter_at(js, s);
-    const char *s2 = index(dot+1, '.');
+    const char *s2 = strchr(dot+1, '.');
 
     json_t *value = json_object_iter_value(iter);
     if (value == NULL) {
@@ -232,8 +232,8 @@ json_t *StatsToJSON(const StatsTable *st, uint8_t flags)
                 continue;
             const char *name = st->stats[u].name;
             const char *shortname = name;
-            if (rindex(name, '.') != NULL) {
-                shortname = &name[rindex(name, '.') - name + 1];
+            if (strrchr(name, '.') != NULL) {
+                shortname = &name[strrchr(name, '.') - name + 1];
             }
             json_t *js_type = OutputStats2Json(js_stats, name);
             if (js_type != NULL) {
@@ -270,7 +270,7 @@ json_t *StatsToJSON(const StatsTable *st, uint8_t flags)
 
                 char str[256];
                 snprintf(str, sizeof(str), "%s.%s", st->tstats[u].tm_name, st->tstats[u].name);
-                char *shortname = &str[rindex(str, '.') - str + 1];
+                char *shortname = &str[strrchr(str, '.') - str + 1];
                 json_t *js_type = OutputStats2Json(threads, str);
 
                 if (js_type != NULL) {
index d78c509fbb4423e4734cf2a73040b40a575bcfea..c0216c5c804b4fe9e73f97a9c9c5493e6ac7250d 100644 (file)
@@ -109,8 +109,8 @@ void BuildCpusetWithCallback(const char *name, ConfNode *node,
             a = 0;
             b = max;
             stop = 1;
-        } else if (index(lnode->val, '-') != NULL) {
-            char *sep = index(lnode->val, '-');
+        } else if (strchr(lnode->val, '-') != NULL) {
+            char *sep = strchr(lnode->val, '-');
             char *end;
             a = strtoul(lnode->val, &end, 10);
             if (end != sep) {
index 678b0e00504742f49b96af6cf8574c8eaf08e413..608580f5059799c5fce2d35f6831e53abf0c0279 100644 (file)
@@ -324,7 +324,7 @@ static SCError SCLogMessageGetBuffer(
     char *temp_fmt = local_format;
     char *substr = temp_fmt;
 
-       while ( (temp_fmt = index(temp_fmt, SC_LOG_FMT_PREFIX)) ) {
+       while ( (temp_fmt = strchr(temp_fmt, SC_LOG_FMT_PREFIX)) ) {
         if ((temp - buffer) > SC_LOG_MAX_LOG_MSG_LEN) {
             return SC_OK;
         }
index e4ab989cd6f3891ddf5e737c24e2b8155678791e..d22443abb58fcd841eaef8439df560f431ad22f0 100644 (file)
@@ -161,19 +161,19 @@ int SCHInfoAddHostOSInfo(const char *host_os, const char *host_os_ip_range, int
     }
 
     /* check if we have more addresses in the host_os_ip_range */
-    if ((ip_str_rem = index(ip_str, ',')) != NULL) {
+    if ((ip_str_rem = strchr(ip_str, ',')) != NULL) {
         ip_str_rem[0] = '\0';
         ip_str_rem++;
         recursive = TRUE;
     }
 
     /* check if we have received a netblock */
-    if ( (netmask_str = index(ip_str, '/')) != NULL) {
+    if ( (netmask_str = strchr(ip_str, '/')) != NULL) {
         netmask_str[0] = '\0';
         netmask_str++;
     }
 
-    if (index(ip_str, ':') == NULL) {
+    if (strchr(ip_str, ':') == NULL) {
         /* if we are here, we have an IPV4 address */
         if ( (ipv4_addr = ValidateIPV4Address(ip_str)) == NULL) {
             SCLogError(SC_ERR_INVALID_IPV4_ADDR, "Invalid IPV4 address");
@@ -252,10 +252,10 @@ int SCHInfoGetHostOSFlavour(const char *ip_addr_str)
     struct in6_addr *ipv6_addr = NULL;
     void *user_data = NULL;
 
-    if (ip_addr_str == NULL || index(ip_addr_str, '/') != NULL)
+    if (ip_addr_str == NULL || strchr(ip_addr_str, '/') != NULL)
         return -1;
 
-    if (index(ip_addr_str, ':') != NULL) {
+    if (strchr(ip_addr_str, ':') != NULL) {
         if ( (ipv6_addr = ValidateIPV6Address(ip_addr_str)) == NULL) {
             SCLogError(SC_ERR_INVALID_IPV4_ADDR, "Invalid IPV4 address");
             return -1;
@@ -344,7 +344,7 @@ void SCHInfoLoadFromConfig(void)
         ConfNode *host;
         TAILQ_FOREACH(host, &policy->head, next) {
             int is_ipv4 = 1;
-            if (host->val != NULL && index(host->val, ':') != NULL)
+            if (host->val != NULL && strchr(host->val, ':') != NULL)
                 is_ipv4 = 0;
             if (SCHInfoAddHostOSInfo(policy->name, host->val, is_ipv4) == -1) {
                 SCLogError(SC_ERR_INVALID_ARGUMENT,
index 24bb42e31d3b674bf981b583e0b43950857c4fc1..5f2e262aa3ba33590df8f58840ee485f34403abf 100644 (file)
@@ -26,9 +26,6 @@
 
 #include <sdkddkver.h>
 
-#define index strchr
-#define rindex strrchr
-
 #define bzero(s, n) memset(s, 0, n)
 
 #ifndef O_NOFOLLOW