libopkg: specify "/bin/sh" instead of "sh"
authorGlenn Strauss <gstrauss@gluelogic.com>
Thu, 2 Mar 2017 22:53:09 +0000 (17:53 -0500)
committerJo-Philipp Wich <jo@mein.io>
Wed, 15 Mar 2017 00:39:14 +0000 (01:39 +0100)
avoid strange behavior with execvp() when PATH is not set in environment
(in which case confstr(_CS_PATH) should return something reasonable)

reproducable running openwrt 15.05 and 15.05.1 and attempting to install
a software package (e.g. libuuid) via LuCI (prior to openwrt/luci#1048).
(https://github.com/openwrt/luci/pull/1048) libuuid.postinst fails with
status 255 on 15.05 and opkg segfaults in 15.05.1.  This probably merits
further exploration.

Originally reported in https://github.com/openwrt/packages/issues/1922

Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
CMakeLists.txt
libopkg/opkg_cmd.c
libopkg/pkg.c

index 9d022e0..30a5d44 100644 (file)
@@ -5,6 +5,7 @@ PROJECT(opkg C)
 SET(HOST_CPU "" CACHE STRING "Override Host CPU")
 SET(BUILD_CPU "" CACHE STRING "Override Host CPU")
 SET(LOCK_FILE "/var/lock/opkg.lock" CACHE STRING "Override lock file path")
+SET(PATH_SPEC "/usr/sbin:/usr/bin:/sbin:/bin" CACHE STRING "Override default PATH value")
 SET(VERSION "" CACHE STRING "Override version")
 
 OPTION(STATIC_UBOX "Statically link libubox" OFF)
@@ -37,6 +38,7 @@ ADD_DEFINITIONS(-Os -Wall --std=gnu99 -g3 -Wmissing-declarations
        -DOPKGLIBDIR="/usr/lib"
        -DHOST_CPU_STR="${HOST_CPU}"
        -DBUILD_CPU=${BUILD_CPU}
+       -DPATH_SPEC="${PATH_SPEC}"
        -DVERSION="${VERSION}"
 )
 
index 543eef4..d52bcb1 100644 (file)
@@ -254,7 +254,7 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
                        sprintf_alloc(&path, "%s/%s", ctx->statedir,
                                      de->d_name);
                        if (access(path, X_OK) == 0) {
-                               const char *argv[] = { "sh", "-c", path, NULL };
+                               const char *argv[] = { "/bin/sh", "-c", path, NULL };
                                xsystem(argv);
                        }
                        free(path);
index 5370cf9..313e691 100644 (file)
@@ -1401,7 +1401,7 @@ int pkg_run_script(pkg_t * pkg, const char *script, const char *args)
        sprintf_alloc(&cmd, "%s %s", path, args);
        free(path);
        {
-               const char *argv[] = { "sh", "-c", cmd, NULL };
+               const char *argv[] = { "/bin/sh", "-c", cmd, NULL };
                err = xsystem(argv);
        }
        free(cmd);