From a60a5fddb13d4563e03f078877be041fdccbffc9 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Fri, 20 Jul 2012 15:17:44 -0400 Subject: [PATCH] Remove use of dynamic memory (strlist_t) from linux.c. --- ifchd/ifchd-defines.h | 1 + ifchd/linux.c | 21 +++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ifchd/ifchd-defines.h b/ifchd/ifchd-defines.h index 3377ec6..f8ceeff 100644 --- a/ifchd/ifchd-defines.h +++ b/ifchd/ifchd-defines.h @@ -8,6 +8,7 @@ #define MAX_BUF 1024 #define SOCK_QUEUE 2 #define CONN_TIMEOUT 60 +#define MAX_IFACES 10 #include #include "strlist.h" diff --git a/ifchd/linux.c b/ifchd/linux.c index 62900e2..9541c0e 100644 --- a/ifchd/linux.c +++ b/ifchd/linux.c @@ -1,6 +1,6 @@ /* linux.c - ifchd Linux-specific functions * - * Copyright (c) 2004-2011 Nicholas J. Kain + * Copyright (c) 2004-2012 Nicholas J. Kain * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,37 +47,34 @@ #include "ifchd-defines.h" #include "log.h" -#include "strlist.h" #include "ifch_proto.h" #include "strl.h" extern struct ifchd_client clients[SOCK_QUEUE]; -static strlist_t *okif; + +static size_t numokif; +static char okif[MAX_IFACES][IFNAMSIZ]; /* Adds to the list of interface names ifchd clients are allowed to change. */ void add_permitted_if(char *s) { - if (!s) + if (numokif >= MAX_IFACES) return; - add_to_strlist(&okif, s); + strlcpy(okif[numokif++], s, IFNAMSIZ); } /* Checks if changes are permitted to a given interface. 1 == allowed */ static int is_permitted(char *name) { - strlist_t *p; - /* If empty, permit all. */ - if (!okif) + if (!numokif) return 1; if (!name || strlen(name) == 0) return 0; - p = okif; - while (p) { - if (strcmp(name, p->str) == 0) + for (size_t i = 0; i < numokif; ++i) { + if (strcmp(name, okif[i]) == 0) return 1; - p = p->next; } log_line("attempt to modify interface %s denied\n", name); return 0;