unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Noah Lavine <noah.b.lavine@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel@gnu.org
Subject: Re: Bug in Guile's Posix Networking
Date: Sat, 12 Feb 2011 21:22:39 -0500	[thread overview]
Message-ID: <AANLkTi=gX2=B-LOXmfM28PGBsL10_S9Wzw6_trzVdgA9@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinMAAXT+tJFh0OR60KMXnyvOmadxUw=drqAOiMF@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1767 bytes --]

Hello again,

The attached patch fixes the problem for me, and I believe zeroing
some data structures before they're used won't hurt things for anyone
else.

Noah

On Sat, Feb 12, 2011 at 8:45 PM, Noah Lavine <noah.b.lavine@gmail.com> wrote:
> Hi all,
>
> I think I have isolated the error (although in fact there are two
> things that should be fixed).
>
> I gdb'd Guile's executable and looked at the struct sockaddr just
> before it was passed to bind. There were two mistakes.
>
> First of all, that struct has an sa_len field which is supposed to
> contain its length, but in fact contained junk. Second of all, it
> should have been padded with 8 bytes of zeros at the end, but it
> wasn't. After experimenting a bit, it turns out that padding with
> zeros was what made the difference, but probably the sa_len field
> should be fixed anyway. I'll work on a patch for this.
>
> Noah
>
> On Sat, Feb 12, 2011 at 8:22 PM, Noah Lavine <noah.b.lavine@gmail.com> wrote:
>> Hi,
>>
>>> #x49 is 73 :)
>>
>> If I knew a facepalm emoticon, I would use it now. :)
>>
>>> Could the lseek could be the problem?
>>
>> Maybe, but I suspect not. My man page for lseek says that lseek will
>> fail with ESPIPE if it is called on a socket, and my errno.h defines
>> ESPIPE to be 29, which is the error we got. So that's what's happening
>> there.
>>
>> However, I looked to see where the lseek call was coming from, and it
>> happens in scm_fdes_to_port, on line 564 of fports.c. The lseek is
>> done for the purpose of checking whether the port supports lseek, and
>> when it returns -1, we put an entry into some data structure (port
>> table?) saying that it doesn't support random access. So it looks like
>> that error is actually expected in the port code.
>>
>> Noah
>>
>

[-- Attachment #2: 0001-libguile-socket.c-fix-use-of-uninitialized-memory.patch --]
[-- Type: application/octet-stream, Size: 1126 bytes --]

From 6daec8ce9ecc4784a42479d1ad101435a0408ecf Mon Sep 17 00:00:00 2001
From: Noah Lavine <nlavine@haverford.edu>
Date: Sat, 12 Feb 2011 21:05:34 -0500
Subject: [PATCH]  * libguile/socket.c: fix use of uninitialized memory.

---
 libguile/socket.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/libguile/socket.c b/libguile/socket.c
index aa52cac..d8ab005 100644
--- a/libguile/socket.c
+++ b/libguile/socket.c
@@ -796,6 +796,7 @@ scm_fill_sockaddr (int fam, SCM address, SCM *args, int which_arg,
 	port = scm_to_int (SCM_CAR (*args));
 	*args = SCM_CDR (*args);
 	soka = (struct sockaddr_in *) scm_malloc (sizeof (struct sockaddr_in));
+        memset (soka, '\0', sizeof (struct sockaddr_in));
 
 #ifdef HAVE_STRUCT_SOCKADDR_SIN_LEN
 	soka->sin_len = sizeof (struct sockaddr_in);
@@ -1131,6 +1132,8 @@ scm_to_sockaddr (SCM address, size_t *address_size)
 	  {
 	    struct sockaddr_in c_inet;
 
+            memset (&c_inet, '\0', sizeof (struct sockaddr_in));
+
 	    c_inet.sin_addr.s_addr =
 	      htonl (scm_to_ulong (SCM_SIMPLE_VECTOR_REF (address, 1)));
 	    c_inet.sin_port =
-- 
1.7.4


  reply	other threads:[~2011-02-13  2:22 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-07  6:28 Bug in Guile's Posix Networking Noah Lavine
2011-02-07 23:49 ` Andreas Rottmann
2011-02-12 20:47   ` Noah Lavine
2011-02-12 21:02     ` Andy Wingo
2011-02-12 21:35       ` Noah Lavine
2011-02-12 22:00         ` Andy Wingo
2011-02-13  1:22           ` Noah Lavine
2011-02-13  1:45             ` Noah Lavine
2011-02-13  2:22               ` Noah Lavine [this message]
2011-02-13  3:00                 ` Noah Lavine
2011-02-13  5:42                   ` Ken Raeburn
2011-02-13 13:55                     ` Noah Lavine
2011-02-13 13:57                       ` Noah Lavine
2011-02-13 18:34                       ` Ken Raeburn
2011-02-13 20:07                         ` Andy Wingo
2011-02-13 20:10                           ` Noah Lavine
2011-02-13 20:34                             ` Noah Lavine
2011-02-13 21:10                               ` Andy Wingo
2011-02-13 20:04                 ` Andy Wingo
2011-02-12 11:26 ` Andy Wingo
2011-02-12 20:33   ` Noah Lavine
2011-02-12 20:59     ` Andy Wingo
2011-02-12 21:00       ` Noah Lavine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=gX2=B-LOXmfM28PGBsL10_S9Wzw6_trzVdgA9@mail.gmail.com' \
    --to=noah.b.lavine@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).