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<br...@clisp.org>

        * 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