diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 187a8c0..eeb8545 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -165,8 +165,15 @@ static char *fw_string_blank(char *s, int noblank) char *fw_getenv (char *name) { char *env, *nxt; + for (nxt = env = environment.data; !(*nxt); ++nxt) { + if (nxt >= &environment.data[ENV_SIZE]) { + fprintf (stderr, "## Error: " + "environment is empty\n"); + return NULL; + } + } - for (env = environment.data; *env; env = nxt + 1) { + for (env = nxt; *env; env = nxt + 1) { char *val; for (nxt = env; *nxt; ++nxt) { @@ -191,8 +198,15 @@ char *fw_getenv (char *name) char *fw_getdefenv(char *name) { char *env, *nxt; + for (nxt = env = default_environment; !(*nxt); ++nxt) { + if (nxt >= &default_environment[ENV_SIZE]) { + fprintf (stderr, "## Error: " + "default environment is empty\n"); + return NULL; + } + } - for (env = default_environment; *env; env = nxt + 1) { + for (env = nxt; *env; env = nxt + 1) { char *val; for (nxt = env; *nxt; ++nxt) { @@ -267,7 +281,14 @@ int fw_printenv (int argc, char *argv[]) return -1; if (argc == 1) { /* Print all env variables */ - for (env = environment.data; *env; env = nxt + 1) { + for (nxt = env = environment.data; !(*nxt); ++nxt) { + if (nxt >= &environment.data[ENV_SIZE]) { + fprintf (stderr, "## Error: " + "environment is empty\n"); + return -1; + } + } + for (env = nxt; *env; env = nxt + 1) { for (nxt = env; *nxt; ++nxt) { if (nxt >= &environment.data[ENV_SIZE]) { fprintf (stderr, "## Error: " @@ -298,8 +319,14 @@ int fw_printenv (int argc, char *argv[]) char *name = argv[i]; char *val = NULL; - for (env = environment.data; *env; env = nxt + 1) { - + for (nxt = env = environment.data; !(*nxt); ++nxt) { + if (nxt >= &environment.data[ENV_SIZE]) { + fprintf (stderr, "## Error: " + "environment is empty\n"); + return -1; + } + } + for (env = nxt; *env; env = nxt + 1) { for (nxt = env; *nxt; ++nxt) { if (nxt >= &environment.data[ENV_SIZE]) { fprintf (stderr, "## Error: " @@ -369,7 +396,14 @@ int fw_env_write(char *name, char *value) /* * search if variable with this name already exists */ - for (nxt = env = environment.data; *env; env = nxt + 1) { + for (nxt = env = environment.data; !(*nxt); ++nxt) { + if (nxt >= &environment.data[ENV_SIZE]) { + fprintf (stderr, "## Error: " + "environment is empty\n"); + return -1; + } + } + for (env = nxt; *env; env = nxt + 1) { for (nxt = env; *nxt; ++nxt) { if (nxt >= &environment.data[ENV_SIZE]) { fprintf(stderr, "## Error: "