]> git.xolatile.top Git - emil-bake.git/commitdiff
BUG: chroot != chdir
authorEmil Williams <emilemilemil@cock.li>
Wed, 2 Oct 2024 19:18:46 +0000 (19:18 +0000)
committerEmil Williams <emilemilemil@cock.li>
Wed, 2 Oct 2024 19:18:46 +0000 (19:18 +0000)
Absolutely astounding bug. I found this when trying to install another
program of  mine with bake  and having it  fail to allocate  memory on
g_pipe.  I'll bump  the last tag forward so that  it doesn't have this
bug.

bake.l

diff --git a/bake.l b/bake.l
index 43464a80e33e18436e9906132c803c0096dcc19a..10f6e30370c59e87737500d4320cf1803f79e219 100644 (file)
--- a/bake.l
+++ b/bake.l
@@ -98,6 +98,8 @@ MACROS   ({CMD}|@STOP|{FILENAME}|@SHORT|@ARGS|@LINE|@RECURS|$@|$*|$+|@\{)
 
 %%
 
+#include <limits.h>
+
 # define    RED "\033[91m"
 # define  GREEN "\033[92m"
 # define YELLOW "\033[93m"
@@ -106,13 +108,12 @@ MACROS   ({CMD}|@STOP|{FILENAME}|@SHORT|@ARGS|@LINE|@RECURS|$@|$*|$+|@\{)
 # define  RESET "\033[0m"
 
 void root(char * filename) {
-  char * path, * terminator;
-  if (!(path = realpath(filename, NULL))) { return; }
+  char path[PATH_MAX], * terminator;
+  if (!realpath(filename, path)) { return; }
   if ((terminator = strrchr(path, '/'))) {
     *terminator = '\0';
-    chroot(path);
+    chdir(path);
   }
-  free(path);
 }
 
 void args(int n, int rest) {
@@ -187,6 +188,7 @@ int main (int ac, char ** av) {
 
   g_filename = av[0];
   root(g_filename);
+
   { /* ensures the filename doesn't have a relative path that would misdirect the command within the new root */
     char * tmp = strrchr(g_filename, '/');
     if (tmp) { g_filename = tmp+1; }
@@ -198,6 +200,7 @@ int main (int ac, char ** av) {
   g_ac = --ac, g_av = ++av;
 
   /* setup pipe and output */
+
   if (run) {
     pipeopen("/bin/sh -e /dev/stdin", "w");
   }