preserve semantics of PATH when PATH is not set in environment
error and undefined behavior reported in
https://github.com/openwrt/packages/issues/1922
when PATH not set in environment
(lighttpd executes CGI with empty base env, plus standard CGI env vars)
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
[Jo-Philipp Wich: avoid free() on NULL, use default from cmake cache string]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
ctx = xcalloc(1, sizeof(*ctx));
ctx->oldpath = xstrdup(getenv("PATH"));
ctx = xcalloc(1, sizeof(*ctx));
ctx->oldpath = xstrdup(getenv("PATH"));
- sprintf_alloc(&newpath, "%s/opkg/intercept:%s", DATADIR, ctx->oldpath);
+
+ sprintf_alloc(&newpath, "%s/opkg/intercept:%s", DATADIR,
+ ctx->oldpath ? ctx->oldpath : PATH_SPEC);
+
sprintf_alloc(&ctx->statedir, "%s/opkg-intercept-XXXXXX",
sprintf_alloc(&ctx->statedir, "%s/opkg-intercept-XXXXXX",
if (mkdtemp(ctx->statedir) == NULL) {
opkg_perror(ERROR, "Failed to make temp dir %s", ctx->statedir);
if (mkdtemp(ctx->statedir) == NULL) {
opkg_perror(ERROR, "Failed to make temp dir %s", ctx->statedir);
+
+ if (ctx->oldpath)
+ free(ctx->oldpath);
+
free(ctx->statedir);
free(newpath);
free(ctx);
free(ctx->statedir);
free(newpath);
free(ctx);
- setenv("PATH", ctx->oldpath, 1);
- free(ctx->oldpath);
+ if (ctx->oldpath) {
+ setenv("PATH", ctx->oldpath, 1);
+ free(ctx->oldpath);
+ }
+ else {
+ unsetenv("PATH");
+ }
dir = opendir(ctx->statedir);
if (dir) {
dir = opendir(ctx->statedir);
if (dir) {