Skip to content

Commit

Permalink
Fix segfault on starting ksh with no TERM env var (#723)
Browse files Browse the repository at this point in the history
This commit fixes a crash that prevented ksh from starting up 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.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
Resolves: #722
  • Loading branch information
JohnoKing and McDutchie committed Feb 22, 2024
1 parent f975f95 commit b15f632
Show file tree
Hide file tree
Showing 4 changed files with 22 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 1.0 branch of ksh 93u+m.
For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.

2024-02-22:

- Fixed a crash that occurred when starting ksh with no TERM variable in the
environment (e.g., 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 @@ -616,7 +616,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.0.9-beta" /* 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
15 changes: 15 additions & 0 deletions src/cmd/ksh93/tests/pty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1286,5 +1286,20 @@ c \Ek
r ^:prompt: "\$SHELL" -o vi -c 'read -s "foo\?:prompt: "'$
!

((multiline && (SHOPT_VSH || SHOPT_ESH))) && TERM=vt100 tst $LINENO <<"!"
L crash when TERM is undefined
# https://github.com/ksh93/ksh/issues/722
d 40
p :test-1:
w unset TERM
p :test-2:
w "$SHELL"
p :test-3:
w print Exit status $?
r print
r ^Exit status 0\r\n$
!

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

0 comments on commit b15f632

Please sign in to comment.