From db58e35d94507060b191ab0c15709f7a73e67f5d Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 7 Dec 2005 19:01:29 +0000 Subject: [PATCH] * fhandler_raw.cc (fhandler_dev_raw::ioctl): Fix INVALID_PARAMETER condition. Only copy devbuf to buf if buf is non-NULL. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/fhandler_raw.cc | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 35bd30c33..27b677b3e 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2005-12-07 Corinna Vinschen + + * fhandler_raw.cc (fhandler_dev_raw::ioctl): Fix INVALID_PARAMETER + condition. Only copy devbuf to buf if buf is non-NULL. + 2005-12-07 Corinna Vinschen * fhandler_raw.cc (fhandler_dev_raw::ioctl): Fix setting devbuf diff --git a/winsup/cygwin/fhandler_raw.cc b/winsup/cygwin/fhandler_raw.cc index 3f45703c9..e4d4e3660 100644 --- a/winsup/cygwin/fhandler_raw.cc +++ b/winsup/cygwin/fhandler_raw.cc @@ -157,22 +157,25 @@ fhandler_dev_raw::ioctl (unsigned int cmd, void *buf) mop.mt_count = op->rd_parm; ret = ioctl (MTIOCTOP, &mop); } - else if (devbuf && op->rd_parm < devbufend - devbufstart) + else if (devbuf && ((op->rd_parm <= 1 && (devbufend - devbufstart)) + || op->rd_parm < devbufend - devbufstart)) ret = ERROR_INVALID_PARAMETER; else if (!devbuf || op->rd_parm != devbufsiz) { char *buf = NULL; if (op->rd_parm > 1L) buf = new char [op->rd_parm]; - if (devbufsiz > 1L) + if (buf && devbufsiz > 1L) { memcpy (buf, devbuf + devbufstart, devbufend - devbufstart); devbufend -= devbufstart; - delete [] devbuf; } else devbufend = 0; + if (devbufsiz > 1L) + delete [] devbuf; + devbufstart = 0; devbuf = buf; devbufsiz = op->rd_parm ?: 1L;