posix: remove deprecated index/rindex calls

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.
pull/4252/head
Victor Julien 6 years ago
parent b82a0e2cad
commit 2da90a1cd8

@ -221,7 +221,7 @@
# 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],

@ -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;

@ -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);

@ -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);

@ -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) {

@ -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) {

@ -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;
}

@ -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,

@ -26,9 +26,6 @@
#include <sdkddkver.h>
#define index strchr
#define rindex strrchr
#define bzero(s, n) memset(s, 0, n)
#ifndef O_NOFOLLOW

Loading…
Cancel
Save