提交 4092eb41 编写于 作者: A anthony

6704896: FD_SET usage can cause stack corruption (sol)

Summary: Using poll() instead of select()
Reviewed-by: yan, denis
上级 324030df
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <langinfo.h> #include <langinfo.h>
#include <locale.h> #include <locale.h>
#include <fcntl.h> #include <fcntl.h>
#include <poll.h>
static Bool shapeSupported; static Bool shapeSupported;
static int shapeEventBase, shapeErrorBase; static int shapeEventBase, shapeErrorBase;
...@@ -534,40 +535,34 @@ void ...@@ -534,40 +535,34 @@ void
SplashEventLoop(Splash * splash) { SplashEventLoop(Splash * splash) {
/* Different from win32 implementation - this loop /* Different from win32 implementation - this loop
uses select timeouts instead of a timer */ uses poll timeouts instead of a timer */
/* we should have splash _locked_ on entry!!! */ /* we should have splash _locked_ on entry!!! */
int xconn = XConnectionNumber(splash->display); int xconn = XConnectionNumber(splash->display);
while (1) { while (1) {
struct pollfd pfd[2];
int timeout = -1;
int ctl = splash->controlpipe[0]; int ctl = splash->controlpipe[0];
fd_set fds[2];
int n = 0;
struct timeval tv, *ptv;
int rc; int rc;
int time;
int pipes_empty; int pipes_empty;
FD_ZERO(fds); pfd[0].fd = xconn;
FD_SET(xconn, fds); pfd[0].events = POLLIN | POLLPRI;
if (xconn+1 > n)
n = xconn+1; pfd[1].fd = ctl;
FD_SET(ctl, fds); pfd[1].events = POLLIN | POLLPRI;
if (ctl+1 > n)
n = ctl+1;
errno = 0; errno = 0;
if (splash->isVisible>0 && SplashIsStillLooping(splash)) { if (splash->isVisible>0 && SplashIsStillLooping(splash)) {
time = splash->time + splash->frames[splash->currentFrame].delay timeout = splash->time + splash->frames[splash->currentFrame].delay
- SplashTime(); - SplashTime();
if (time < 0) if (timeout < 0) {
time = 0; timeout = 0;
msec2timeval(time, &tv); }
ptv = &tv;
} else {
ptv = NULL;
} }
SplashUnlock(splash); SplashUnlock(splash);
rc = select(n, fds, NULL, NULL, ptv); rc = poll(pfd, 2, timeout);
SplashLock(splash); SplashLock(splash);
if (splash->isVisible>0 && SplashTime() >= splash->time + if (splash->isVisible>0 && SplashTime() >= splash->time +
splash->frames[splash->currentFrame].delay) { splash->frames[splash->currentFrame].delay) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册