aboutsummaryrefslogtreecommitdiff
path: root/init/init.c
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2007-12-16 12:58:33 +0100
committerWilly Tarreau <w@1wt.eu>2007-12-16 12:58:33 +0100
commit6f39630130aaebcd96f8da06999d60a017b9de1f (patch)
treef2dc1839a51877dbccb0347a947e9af0fa22b5cf /init/init.c
parentinit: add checks for the kernel's cmdline (diff)
downloadflxutils-6f39630130aaebcd96f8da06999d60a017b9de1f.tar.xz
init: fixed variable checking out of cmdline
The cmdline parser was designed to be used only once! Fixing it also reduced the executable size by 32 bytes.
Diffstat (limited to 'init/init.c')
-rw-r--r--init/init.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/init/init.c b/init/init.c
index d8ffb3a..9b33c81 100644
--- a/init/init.c
+++ b/init/init.c
@@ -413,6 +413,7 @@ static char cfg_data[MAX_CFG_SIZE];
static char *cfg_args[MAX_CFG_ARGS];
static char *cfg_line;
static char cmdline[MAX_CMDLINE_LEN];
+static int cmdline_len;
static char *cst_str[MAX_FIELDS];
static char *var_str[MAX_FIELDS];
static struct dev_varstr var[MAX_FIELDS];
@@ -491,24 +492,25 @@ char *find_arg(char *arg) {
char *a, *c;
/* read cmdline the first time */
- if (!*cmdline) {
- int fd, len;
+ if (cmdline_len <= 0) {
+ int fd;
if ((fd = open(proc_cmdline, O_RDONLY)) == -1)
return NULL;
- if ((len = read(fd, cmdline, sizeof(cmdline)-1)) == -1) {
- close(fd);
- return NULL;
- }
- cmdline[len] = 0;
+
+ cmdline_len = read(fd, cmdline, sizeof(cmdline)-1);
close(fd);
+ if (cmdline_len <= 0)
+ return NULL;
+ cmdline[cmdline_len++] = 0;
}
/* search for the required arg in cmdline */
c = cmdline;
a = arg;
- while (*c) {
+ /* we can check up to the last byte because we know it's zero */
+ while (c <= cmdline + cmdline_len) {
if (*a == 0) {
/* complete match. is it a full word ? */
if (*c == '=') {
@@ -527,7 +529,7 @@ char *find_arg(char *arg) {
a = arg;
}
}
- if (*c == *a) {
+ else if (*c == *a) {
a++;
c++;
}
@@ -536,10 +538,7 @@ char *find_arg(char *arg) {
a = arg;
}
}
- if (*a == 0) /* complete match at end of string */
- return c; /* pointer to empty string */
- else
- return NULL; /* not found */
+ return NULL; /* not found */
}
/*