bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crash in 'find_and_set_default_shell()'


From: Gisle Vanem
Subject: Re: Crash in 'find_and_set_default_shell()'
Date: Wed, 11 May 2022 08:00:42 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

Paul Smith wrote:

... else (b) make has to parse this string
and break it up into words that it can use to call exec() without going
through a shell

The crash and wild call-stack seems to be caused
by an overflow to 'sprintf(sh_path, ..)'. But replacing
with 'snprintf()' works w/o any crash:

--- a/src/main.c 2022-05-10 13:37:02
+++ b/src/main.c 2022-05-11 07:47:07
@@ -956,7 +956,7 @@
     {
       batch_mode_shell = 1;
       unixy_shell = 0;
-      sprintf (sh_path, "%s", search_token);
+      snprintf (sh_path, GET_PATH_MAX, "%s", search_token);
       default_shell = xstrdup (w32ify (sh_path, 0));
       DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"),
                        default_shell));
@@ -971,7 +971,7 @@
   else if (_access (search_token, 0) == 0)
     {
       /* search token path was found */
-      sprintf (sh_path, "%s", search_token);
+      snprintf (sh_path, GET_PATH_MAX, "%s", search_token);
       default_shell = xstrdup (w32ify (sh_path, 0));
       DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"),
                        default_shell));
@@ -994,7 +994,7 @@
             {
               *ep = '\0';

-              sprintf (sh_path, "%s/%s", p, search_token);
+              snprintf (sh_path, GET_PATH_MAX, "%s/%s", p, search_token);
               if (_access (sh_path, 0) == 0)
                 {
                   default_shell = xstrdup (w32ify (sh_path, 0));
@@ -1016,7 +1016,7 @@
           /* be sure to check last element of Path */
           if (p && *p)
             {
-              sprintf (sh_path, "%s/%s", p, search_token);
+              snprintf (sh_path, GET_PATH_MAX, "%s/%s", p, search_token);
               if (_access (sh_path, 0) == 0)
                 {
                   default_shell = xstrdup (w32ify (sh_path, 0));

--------------

And testing it with:
  set GNUMAKEFLAGS=--debug=verbose,jobs
  gnumake -f Minimal.make

seems to work okay:
  ..
  find_and_set_shell() path search set default_shell = f:/CygWin32/bin/sh.exe
  ..
  CreateProcess(f:\CygWin32\bin\sh.exe,f:/CygWin32/bin/sh.exe -c "echo 
\"Hello\"",...)
  Putting child 012E9F10 (all) PID 20053024 on the chain.
  Live child 012E9F10 (all) PID 20053024
  Main thread handle = 00000118
  Hello

--
--gv



reply via email to

[Prev in Thread] Current Thread [Next in Thread]