* libmisc/env.c: Avoid implicit conversion of pointers / chars to

booleans.
	* libmisc/env.c: Add brackets and parenthesis.
	* libmisc/env.c: Ignore the return value of puts() and fputs().
	* libmisc/env.c: Avoid multi-statements lines.
This commit is contained in:
nekral-guest 2008-06-17 21:58:46 +00:00
parent 7c9270d7a5
commit 6298ca94cb
2 changed files with 41 additions and 21 deletions

View File

@ -1,3 +1,11 @@
2008-06-17 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/env.c: Avoid implicit conversion of pointers / chars to
booleans.
* libmisc/env.c: Add brackets and parenthesis.
* libmisc/env.c: Ignore the return value of puts() and fputs().
* libmisc/env.c: Avoid multi-statements lines.
2008-06-17 Nicolas François <nicolas.francois@centraliens.net> 2008-06-17 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/utmp.c: Avoid implicit conversion of pointers / chars to * libmisc/utmp.c: Avoid implicit conversion of pointers / chars to

View File

@ -91,7 +91,7 @@ void addenv (const char *string, const char *value)
size_t i; size_t i;
size_t n; size_t n;
if (value) { if (NULL != value) {
newstring = xmalloc (strlen (string) + strlen (value) + 2); newstring = xmalloc (strlen (string) + strlen (value) + 2);
sprintf (newstring, "%s=%s", string, value); sprintf (newstring, "%s=%s", string, value);
} else { } else {
@ -104,7 +104,7 @@ void addenv (const char *string, const char *value)
*/ */
cp = strchr (newstring, '='); cp = strchr (newstring, '=');
if (!cp) { if (NULL == cp) {
free (newstring); free (newstring);
return; return;
} }
@ -112,9 +112,10 @@ void addenv (const char *string, const char *value)
n = (size_t) (cp - newstring); n = (size_t) (cp - newstring);
for (i = 0; i < newenvc; i++) { for (i = 0; i < newenvc; i++) {
if (strncmp (newstring, newenvp[i], n) == 0 && if ( (strncmp (newstring, newenvp[i], n) == 0)
(newenvp[i][n] == '=' || newenvp[i][n] == '\0')) && (('=' == newenvp[i][n]) || ('\0' == newenvp[i][n]))) {
break; break;
}
} }
if (i < newenvc) { if (i < newenvc) {
@ -151,12 +152,14 @@ void addenv (const char *string, const char *value)
* environ so that it doesn't point to some * environ so that it doesn't point to some
* free memory area (realloc() could move it). * free memory area (realloc() could move it).
*/ */
if (environ == newenvp) if (environ == newenvp) {
environ = __newenvp; environ = __newenvp;
}
newenvp = __newenvp; newenvp = __newenvp;
} else { } else {
fputs (_("Environment overflow\n"), stderr); (void) fputs (_("Environment overflow\n"), stderr);
free (newenvp[--newenvc]); newenvc--;
free (newenvp[newenvc]);
} }
} }
@ -178,21 +181,25 @@ void set_env (int argc, char *const *argv)
char *cp; char *cp;
for (; argc > 0; argc--, argv++) { for (; argc > 0; argc--, argv++) {
if (strlen (*argv) >= sizeof variable) if (strlen (*argv) >= sizeof variable) {
continue; /* ignore long entries */ continue; /* ignore long entries */
}
if (!(cp = strchr (*argv, '='))) { cp = strchr (*argv, '=');
if (NULL == cp) {
snprintf (variable, sizeof variable, "L%d", noname++); snprintf (variable, sizeof variable, "L%d", noname++);
addenv (variable, *argv); addenv (variable, *argv);
} else { } else {
const char **p; const char **p;
for (p = forbid; *p; p++) for (p = forbid; NULL != *p; p++) {
if (strncmp (*argv, *p, strlen (*p)) == 0) if (strncmp (*argv, *p, strlen (*p)) == 0) {
break; break;
}
}
if (*p) { if (NULL != *p) {
strncpy (variable, *argv, cp - *argv); strncpy (variable, *argv, (size_t)(cp - *argv));
variable[cp - *argv] = '\0'; variable[cp - *argv] = '\0';
printf (_("You may not change $%s\n"), printf (_("You may not change $%s\n"),
variable); variable);
@ -220,27 +227,32 @@ void sanitize_env (void)
char **cur; char **cur;
char **move; char **move;
for (cur = envp; *cur; cur++) { for (cur = envp; NULL != *cur; cur++) {
for (bad = forbid; *bad; bad++) { for (bad = forbid; NULL != *bad; bad++) {
if (strncmp (*cur, *bad, strlen (*bad)) == 0) { if (strncmp (*cur, *bad, strlen (*bad)) == 0) {
for (move = cur; *move; move++) for (move = cur; NULL != *move; move++) {
*move = *(move + 1); *move = *(move + 1);
}
cur--; cur--;
break; break;
} }
} }
} }
for (cur = envp; *cur; cur++) { for (cur = envp; NULL != *cur; cur++) {
for (bad = noslash; *bad; bad++) { for (bad = noslash; NULL != *bad; bad++) {
if (strncmp (*cur, *bad, strlen (*bad)) != 0) if (strncmp (*cur, *bad, strlen (*bad)) != 0) {
continue; continue;
if (!strchr (*cur, '/')) }
if (strchr (*cur, '/') != NULL) {
continue; /* OK */ continue; /* OK */
for (move = cur; *move; move++) }
for (move = cur; NULL != *move; move++) {
*move = *(move + 1); *move = *(move + 1);
}
cur--; cur--;
break; break;
} }
} }
} }