Control: tags -1 + upstream
Control: forwarded -1 https://bugs.debian.org/716517

Testing 20200726.

The report can be reduced to 
  env -i MALLOC_CHECK_=0 xjobs '>' @. .. < <(printf AAAAAAAAAAAAAAAAAAAAAAAA)
which segfaults.

I can further reduce it to
  $ env -i xjobs < <(echo a)
  Segmentation fault
logging
  $ env -i /bin/xjobs -v5 < <(echo a)
  24 processors currently online (default job limit)
  looking for config file /home/nabijaczleweli/uwu/xjobs//bin/../etc/xjobs.rc
  no config file /home/nabijaczleweli/uwu/xjobs//bin/../etc/xjobs.rc
  stdout is a terminal
  tty mode 2
  pager not setyyinput() = 2
  add_job(0x5643b44fb380,1,"","","","",0)
  PATH="(null)"
  Segmentation fault

gdb says
  #0  __strchr_sse2 () at ../sysdeps/x86_64/multiarch/strchr-sse2.S:41
  #1  0x000055555555c95c in complete_exe (exe=0x55555556d3b0 'A' <repeats 24 
times>) at ./support.c:354
  #2  0x000055555555b1a9 in add_job (a=<optimized out>, a@entry=0x55555556d390, 
n=<optimized out>, n@entry=1, in=in@entry=0x0, out=out@entry=0x0, 
err=err@entry=0x0,
      pwd=pwd@entry=0x0, app=0) at ./jobctrl.c:156
  #3  0x0000555555556a86 in main (argc=<optimized out>, argv=<optimized out>, 
env=<optimized out>) at ./xjobs.c:463

353 is the strchr in
        // resolve via PATH environment variable
        char *token = Path;
        char *next = strchr(Path,':');
        while (token && *token) {
and naturally
  $ git grep -w Path
  settings.c:char *Path = 0;
  settings.c:                     Path = valuestr;
  settings.c:                     dbug("PATH set to %s\n",Path);
  settings.h:extern char **Env, *Path;
  support.c:      if (Path == 0) {
  support.c:              Path = getenv("PATH");
  support.c:              dbug("PATH=\"%s\"\n", Path);
  support.c:      char *token = Path;
  support.c:      char *next = strchr(Path,':');

Thomas: below you'll find a patch I applied to 20200726 that fixes this
with the standard  if (!Path) Path = strdup(_PATH_STDPATH);  solution.
(You need strdup() here becase you write to Path.)

Therewith, I see:
  $ env -i xjobs  < <(echo a)
  cannot find executable a
  ### error starting job: a
  summary: 0 succeeded, executed in 0.000259sng
  $ env -i xjobs  < <(echo ls)
  ### started job #1, pid 830278: /usr/bin/ls
  /usr/bin/lsd, 0 finished, 0 failed, 1 running
  >
  @
  @.
  argc_0.symb
  argv_1.symb
  argv_2.symb
  argv_3.symb
  crash.sh
  file___dev__stdin.symb
  summary: 1 succeeded, executed in 0.002207sng
which is expected (though note lsd).

Best,
наб
Forwarded: https://bugs.debian.org/716517

diff --git a/support.c b/support.c
index 8ba70b0..72ea7df 100644
--- a/support.c
+++ b/support.c
@@ -24,6 +24,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <paths.h>
 #include <strings.h>
 #include <unistd.h>
 
@@ -299,6 +300,8 @@ char *complete_exe(char *exe)
 {
 	if (Path == 0) {
 		Path = getenv("PATH");
+		if (!Path)
+			Path = strdup(_PATH_STDPATH);
 		dbug("PATH=\"%s\"\n", Path);
 		if (0 == getcwd(PWD,sizeof(PWD)))
 			error("current work directory exceeds maximum allowed size\n");

Attachment: signature.asc
Description: PGP signature

Reply via email to