1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix use of strdup on a NULL pointer (#63)

The following set of commands can rarely cause a memory fault
when auditing[*] is enabled, although most of the time it will
simply cause ksh to write '(null)' to the auditing file in place
of a tty name:

$ [ -e /etc/ksh_audit ] || echo "/tmp/ksh_auditfile;$(id -u)" | sudo tee /etc/ksh_audit;
$ v=$(ksh  2> /dev/null +o rc -ic $'getopts a:bc: opt --man\nprint $?')
$ cat /tmp/ksh_auditfile
1000;1593599493;(null); getopts a:bc: opt --man

This happens because strdup is used unconditionally on the pointer
returned by 'ttyname', which can be NULL if stderr is closed. This
then causes 'hp->tty' to be set to null, as strdup returns NULL.
See https://github.com/att/ast/issues/1028

src/cmd/ksh93/edit/history.c:
- Make strdup duplicate 'notty' instead of NULL to prevent
  crashes.

[*] https://blog.fpmurphy.com/2008/12/ksh93-auditing-and-accounting.html
This commit is contained in:
Johnothan King 2020-07-06 13:51:44 -07:00 committed by GitHub
parent 300cd19987
commit 9a9da2c299
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

5
NEWS
View file

@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs. Any uppercase BUG_* names are modernish shell bug IDs.
2020-07-06:
- 'notty' is now written to the ksh auditing file instead of '(null)' if
the user's tty could not be determined.
2020-07-05: 2020-07-05:
- In UTF-8 locales, fix corruption of the shell's internal string quoting - In UTF-8 locales, fix corruption of the shell's internal string quoting

View file

@ -395,7 +395,7 @@ retry:
if(fd>=0) if(fd>=0)
{ {
fcntl(fd,F_SETFD,FD_CLOEXEC); fcntl(fd,F_SETFD,FD_CLOEXEC);
hp->tty = strdup(ttyname(2)); hp->tty = strdup(isatty(2)?ttyname(2):"notty");
hp->auditfp = sfnew((Sfio_t*)0,NULL,-1,fd,SF_WRITE); hp->auditfp = sfnew((Sfio_t*)0,NULL,-1,fd,SF_WRITE);
} }
} }

View file

@ -17,4 +17,4 @@
* David Korn <dgk@research.att.com> * * David Korn <dgk@research.att.com> *
* * * *
***********************************************************************/ ***********************************************************************/
#define SH_RELEASE "93u+m 2020-07-05" #define SH_RELEASE "93u+m 2020-07-06"