]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - lib/env.c
tests: add sanitize_env() check
[thirdparty/util-linux.git] / lib / env.c
index b2e3d975a8d3737589ae2e28ecd633033aed7e6c..ea7d457827854966b1ccfd7de7fdb294d3f15290 100644 (file)
--- a/lib/env.c
+++ b/lib/env.c
@@ -107,3 +107,34 @@ return secure_getenv(arg);
        return getenv(arg);
 #endif
 }
+
+#ifdef TEST_PROGRAM
+int main(int argc, char **argv)
+{
+       char *const *bad;
+       char copy[32];
+       char *p;
+       int retval = EXIT_SUCCESS;
+
+       for (bad = forbid; *bad; bad++) {
+               strcpy(copy, *bad);
+               p = strchr(copy, '=');
+               if (p)
+                       *p = '\0';
+               setenv(copy, copy, 1);
+       }
+       sanitize_env();
+       for (bad = forbid; *bad; bad++) {
+               strcpy(copy, *bad);
+               p = strchr(copy, '=');
+               if (p)
+                       *p = '\0';
+               p = getenv(copy);
+               if (p) {
+                       warnx("%s was not removed", copy);
+                       retval = EXIT_FAILURE;
+               }
+       }
+       return retval;
+}
+#endif