summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-15 00:27:15 (EST)
committer ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-15 00:27:15 (EST)
commit8c4195884fa30ef76e17835266745fb2c6d920f7 (patch)
tree4d2bee00c536855c36c447ec4683161668bf5d57
parentde5dd0f527d23b68beb4d0acba0dff84f2c18ea9 (diff)
[opkg] fix opkg crashes if PATH is unset
Thanks for chgros git-svn-id: http://opkg.googlecode.com/svn/trunk@146 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r--libopkg/opkg_cmd.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c
index fcf74f6..2fe74e9 100644
--- a/libopkg/opkg_cmd.c
+++ b/libopkg/opkg_cmd.c
@@ -312,11 +312,18 @@ typedef struct opkg_intercept *opkg_intercept_t;
static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf)
{
opkg_intercept_t ctx;
+ char *oldpath;
char *newpath;
int gen;
ctx = malloc (sizeof (*ctx));
- ctx->oldpath = strdup (getenv ("PATH"));
+ oldpath = getenv ("PATH");
+ if (oldpath) {
+ ctx->oldpath = strdup (oldpath);
+ } else {
+ ctx->oldpath = 0;
+ }
+
sprintf_alloc (&newpath, "%s/opkg/intercept:%s", DATADIR, ctx->oldpath);
setenv ("PATH", newpath, 1);
@@ -344,8 +351,12 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
DIR *dir;
int err = 0;
- 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) {