me again ;)
- bad file descriptor handling is missing in select(). if we know that, system has no idea about 'fd' which was given in one of the sets 'read/write/except' we should return '-1' and set errno to 'EBADF'. we might increse the count and set exceptfd for that 'fd', but it is safe to obey select manual.
Code: Select all
from manual;
On error, -1 is returned, and errno is set appropriately; the sets and timeout become undefined, so do not rely on their contents after an error.
Code: Select all
# wget http://gsulinux.org/~distch/pspdev/newlib-1.15.0-PSP-select.patch
Code: Select all
--- select.orig.c 2007-06-01 18:00:20.000000000 +0300
+++ select.c 2007-06-01 18:01:40.000000000 +0300
@@ -7,6 +7,9 @@
*
* Copyright (c) 2006 Rafael Cabezas <rafpsp@gmail.com>
*
+ * - 20070701 Alper Akcan "anhanguera" <distchx@yahoo.com>
+ * select EBADF fix
+ *
*/
#include <fcntl.h>
#include <errno.h>
@@ -43,6 +46,12 @@
if ( (count > 0) || ((timeout != NULL) && ((clock() - start_time) >= time)) ) {
break;
}
+ if (count < 0) {
+ /* anhanguera - 20070701
+ * error, lets let the caller to handle error state
+ */
+ break;
+ }
else {
/* Nothing found, and not timed-out yet; let's yield for SELECT_POLLING_DELAY_IN_us, so we're not in a busy loop */
sceKernelDelayThread(SELECT_POLLING_DELAY_IN_us);
@@ -155,6 +164,24 @@
}
break;
}
+ } else {
+ /* anhanguera - 20070701
+ *
+ * here we know that, system has no idea about 'fd'. if caller requested
+ * information about 'fd', return '-1' and set errno to 'EBADF'. we should
+ * increse the count and set exceptfd for fd, but it is safe to obey select
+ * manual.
+ *
+ * from manual;
+ * On error, -1 is returned, and errno is set appropriately; the sets and
+ * timeout become undefined, so do not rely on their contents after an error.
+ */
+ if ((readfds && FD_ISSET(fd, readfds)) ||
+ (writefds && FD_ISSET(fd, writefds)) ||
+ (exceptfds && FD_ISSET(fd, exceptfds))) {
+ errno = EBADF;
+ return -1;
+ }
}
}
anhanguera