bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: non-null declarations, recvfrom, sendto


From: Paolo Bonzini
Subject: Re: non-null declarations, recvfrom, sendto
Date: Fri, 11 Dec 2009 00:46:28 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4pre) Gecko/20090922 Fedora/3.0-3.9.b4.fc12 Lightning/1.0pre Thunderbird/3.0b4

On 12/11/2009 12:44 AM, Bruno Haible wrote:
But this also means that our recvfrom wrapper makes invalid memory accesses.
Here is a proposed patch:


2009-12-10  Bruno Haible<address@hidden>

        * lib/recvfrom.c (rpl_recvfrom): Allow the from argument to be NULL.

--- lib/recvfrom.c.orig 2009-12-11 00:33:28.000000000 +0100
+++ lib/recvfrom.c      2009-12-11 00:14:22.000000000 +0100
@@ -1,6 +1,6 @@
  /* recvfrom.c --- wrappers for Windows recvfrom function

-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 Free Software Foundation, Inc.

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@
  rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from,
                int *fromlen)
  {
-  int frombufsize = *fromlen;
+  int frombufsize = (from != NULL ? *fromlen : 0);
    SOCKET sock = FD_TO_SOCKET (fd);
    int r = recvfrom (sock, buf, len, flags, from, fromlen);

@@ -41,7 +41,7 @@

    /* Winsock recvfrom() only returns a valid 'from' when the socket is
       connectionless.  POSIX gives a valid 'from' for all types of sockets.  */
-  else if (*fromlen == frombufsize)
+  else if (from != NULL&&  *fromlen == frombufsize)
      rpl_getpeername (fd, from, fromlen);

Ok, thanks!

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]