Skip to content

Commit

Permalink
Fix segfault in NetBSD and DragonFlyBSD single user mode
Browse files Browse the repository at this point in the history
This commit fixes a crash that prevented ksh from starting in single
user mode on DragonFlyBSD and NetBSD.

src/cmd/ksh93/edit/edit.c:
- Make sure the np node for $TERM is not null before checking for an
  export attribute.
  • Loading branch information
JohnoKing committed Feb 22, 2024
1 parent 4eaf25c commit 463c590
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ This documents significant changes in the dev branch of ksh 93u+m.
For full details, see the git log at: https://github.com/ksh93/ksh
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.

2024-02-22:

- Fixed a segmentation fault that occurred when starting ksh in single
user mode on NetBSD and DragonFlyBSD.

2024-02-17:

- Fixed a crash that could occur when using 'typeset -T' typed variables
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ void ed_setup(Edit_t *ep, int fd, int reedit)
static char *oldterm;
Namval_t *np = nv_search("TERM",sh.var_tree,0);
char *term = NULL;
if(nv_isattr(np,NV_EXPORT))
if(np && nv_isattr(np,NV_EXPORT))
term = nv_getval(np);
if(!term)
term = "";
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.1.0-alpha" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2024-02-17" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2024-02-22" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2024 Contributors to ksh " SH_RELEASE_FORK

/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
Expand Down
13 changes: 13 additions & 0 deletions src/cmd/ksh93/tests/pty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1322,5 +1322,18 @@ c \Ek
r ^:prompt: "\$SHELL" -o vi -c 'read -s "foo\?:prompt: "'$
!

((SHOPT_VSH || SHOPT_ESH)) && TERM=vt100 tst $LINENO <<"!"
L crash when TERM is undefined
d 40
p :test-1:
w unset TERM
p :test-2:
w exec "$SHELL"
p :test-3:
w print Did something
u ^Did something\r\n$
!

# ======
exit $((Errors<125?Errors:125))

0 comments on commit 463c590

Please sign in to comment.