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

sh_close(): Set errno to EBADF for invalid file descriptors (#399)

The sh_close() function fails to set errno to EBADF when passed a
negative (invalid) file descriptor. This commit fixes the issue
by setting errno if the file descriptor is a negative value
(backported from ksh93v- 2012-08-24).
This commit is contained in:
Johnothan King 2021-12-26 09:03:51 -08:00 committed by Martijn Dekker
parent 9403d326f4
commit feeb62d15f

View file

@ -708,7 +708,10 @@ int sh_close(register int fd)
register Sfio_t *sp;
register int r = 0;
if(fd<0)
{
errno = EBADF;
return(-1);
}
if(fd >= shp->gd->lim.open_max)
sh_iovalidfd(shp,fd);
if(!(sp=shp->sftable[fd]) || sfclose(sp) < 0)