threads / patch / 31467

v3, 4 partsRE: [PATCH v3 1/4] poll() exits too early with EFAULT if 1st arg is NULL

Subject: RE: [PATCH v3 1/4] poll() exits too early with EFAULT if 1st arg is NULL

## tl;dr

3 messages between Sep 7, 2012 and Sep 13, 2012. Diffs are folded; open one to read it.

replies: 2people: 1as markdown or json

Joachim Schmitz· Sep 7, 2012, 12:52 UTC · lore

If poll() is used as a milli-second sleep, like in help.c, by passing a NULL in the 1st and a 0 in the 2nd arg, it exits with EFAULT.

As per Paolo Bonzini, the original author, this is a bug and to be fixed like in this commit, which is not to exit if the 2nd arg is 0.

Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de>
---
 compat/win32/poll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to compat/win32/poll.c +1 −1
diff --git a/compat/win32/poll.c b/compat/win32/poll.c
index 403eaa7..9e7a25c 100644
--- a/compat/win32/poll.c
+++ b/compat/win32/poll.c
@@ -349,7 +349,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
 
   /* EFAULT is not necessary to implement, but let's do it in the
      simplest case. */
-  if (!pfd)
+  if (!pfd && nfd)
     {
       errno = EFAULT;
       return -1;
-- 
1.7.12
Joachim Schmitz· Sep 11, 2012, 11:28 UTC · re: Joachim Schmitz · lore

Re: [PATCH v3 1/4] poll() exits too early with EFAULT if 1st arg is NULL

Joachim Schmitz wrote:
Show 24 quoted lines
> If poll() is used as a milli-second sleep, like in help.c, by passing
> a NULL in the 1st and a 0 in the 2nd arg, it exits with EFAULT.
>
> As per Paolo Bonzini, the original author, this is a bug and to be
> fixed like in this commit, which is not to exit if the 2nd arg is 0.
>
> Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de>
> ---
> compat/win32/poll.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/compat/win32/poll.c b/compat/win32/poll.c
> index 403eaa7..9e7a25c 100644
> --- a/compat/win32/poll.c
> +++ b/compat/win32/poll.c
> @@ -349,7 +349,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
>
>   /* EFAULT is not necessary to implement, but let's do it in the
>      simplest case. */
> -  if (!pfd)
> +  if (!pfd && nfd)
>     {
>       errno = EFAULT;
>       return -1;

Actually this one is not needed for win32 (nor does win32 suffer from a similar bug), so should probably better get added after patch 2/2 (or as part of it), the move to compat/poll/.

Bye, Jojo
Joachim Schmitz· Sep 13, 2012, 07:15 UTC · re: Joachim Schmitz · lore

Re: [PATCH v3 1/4] poll() exits too early with EFAULT if 1st arg is NULL

Joachim Schmitz wrote:
Show 30 quoted lines
> Joachim Schmitz wrote:
>> If poll() is used as a milli-second sleep, like in help.c, by passing
>> a NULL in the 1st and a 0 in the 2nd arg, it exits with EFAULT.
>> 
>> As per Paolo Bonzini, the original author, this is a bug and to be
>> fixed like in this commit, which is not to exit if the 2nd arg is 0.
>> 
>> Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de>
>> ---
>> compat/win32/poll.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/compat/win32/poll.c b/compat/win32/poll.c
>> index 403eaa7..9e7a25c 100644
>> --- a/compat/win32/poll.c
>> +++ b/compat/win32/poll.c
>> @@ -349,7 +349,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int
>> timeout) 
>> 
>>   /* EFAULT is not necessary to implement, but let's do it in the
>>      simplest case. */
>> -  if (!pfd)
>> +  if (!pfd && nfd)
>>     {
>>       errno = EFAULT;
>>       return -1;
> 
> Actually this one is not needed for win32 (nor does win32 suffer from
> a similar bug), so should probably better get added after patch 2/2
> (or as part of it), the move to compat/poll/.
It just got added that was to gnulib, with a commit message of:

don't exit early if NULL is the 1st arg to poll(), but nfd is 0. In that case poll should behave like select.

Bye, Jojo

← back to recent threads