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.
# 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],
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;
}
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);
* 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;
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);
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);
{
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;
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) {
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) {
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) {
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) {
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;
}
}
/* 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");
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;
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,
#include <sdkddkver.h>
-#define index strchr
-#define rindex strrchr
-
#define bzero(s, n) memset(s, 0, n)
#ifndef O_NOFOLLOW