#973044 posh: segfaults when getcwd fails

Package:
posh
Source:
posh
Description:
Policy-compliant Ordinary SHell
Submitter:
Kacper Gutowski
Date:
2020-11-13 10:51:03 UTC
Severity:
normal
#973044#5
Date:
2020-10-27 14:27:29 UTC
From:
To:
Dear Maintainer,
Consider the following:

$ mkdir foo
$ cd foo
$ rmdir ../foo
$ posh
Memory fault

#973044#10
Date:
2020-11-13 10:46:32 UTC
From:
To:
Dear Maintainer,
this is a backtrace of the crash:

     (gdb) bt
     #0  __strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:120
     #1  0x000055a9f3c9e5d0 in set_current_wd (path=<optimized out>) at ../path.c:235
     #2  0x000055a9f3c906b7 in main (argc=1, argv=0x7fffa8fcd4b8) at ../main.c:196

It seems that in main variable pwdx intentionally is set to NULL (main.c:195).
But function set_current_wd is not prepared to receive that.

Kind regards,
Bernhard


https://sources.debian.org/src/posh/0.14.1/path.c/#L235
https://sources.debian.org/src/posh/0.14.1/main.c/#L196

191 		if (!ISABSPATH(pwd)
192 		    || stat(pwd, &s_pwd) < 0 || stat(".", &s_dot) < 0
193 		    || s_pwd.st_dev != s_dot.st_dev
194 		    || s_pwd.st_ino != s_dot.st_ino)
195 			pwdx = (char *) 0;
196 		set_current_wd(pwdx);