SECURITY: fix integer overflows related to file descriptor parsing
bug initially found by Pawel Wylecial (LP#1440685) additional bug found and suggested fix by enh (elliott hughes) This commit also renames struct ioword.flag to ioflag to disambiguate it from other members named “flag”, changes it to an unsigned type, and packs ioflag and unit into shorts each, to make the struct smaller (aligned even: 16 bytes on 32-bit systems) and reviews some of the code involved in fd handling, though there wasn’t much to be found.
This commit is contained in:
15
main.c
15
main.c
@ -34,7 +34,7 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.290 2015/03/14 05:23:15 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.291 2015/04/11 22:03:30 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -1453,13 +1453,20 @@ closepipe(int *pv)
|
||||
int
|
||||
check_fd(const char *name, int mode, const char **emsgp)
|
||||
{
|
||||
int fd, fl;
|
||||
int fd = 0, fl;
|
||||
|
||||
if (name[0] == 'p' && !name[1])
|
||||
return (coproc_getfd(mode, emsgp));
|
||||
for (fd = 0; ksh_isdigit(*name); ++name)
|
||||
while (ksh_isdigit(*name)) {
|
||||
fd = (fd * 10) + *name - '0';
|
||||
if (*name || fd >= FDBASE) {
|
||||
if (fd >= FDBASE) {
|
||||
if (emsgp)
|
||||
*emsgp = "file descriptor too large";
|
||||
return (-1);
|
||||
}
|
||||
++name;
|
||||
}
|
||||
if (*name) {
|
||||
if (emsgp)
|
||||
*emsgp = "illegal file descriptor name";
|
||||
return (-1);
|
||||
|
Reference in New Issue
Block a user