unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* scm_to_sockaddr mishandles IPv6 addresses
@ 2009-09-30  3:16 Scott McPeak
  2009-10-01 22:29 ` Neil Jerram
  0 siblings, 1 reply; 2+ messages in thread
From: Scott McPeak @ 2009-09-30  3:16 UTC (permalink / raw)
  To: bug-guile

Hi,

In Guile-1.8.7, the function 'scm_to_sockaddr' mishandles IPv6
addresses.  Specifically, it passes the 'address' parameter (which is
a vector) to the 'scm_to_ipv6' function, which expects an integer.

I have a patch, at the end, that fixes the problem.

The patch also improves the error message produced by 'scm_to_ipv6'
when passed the wrong type of argument.  I realize it's somewhat
unconventional to use the C function name as the 'subr' in
'scm_wrong_type_arg_msg', but it to me it seems preferable to NULL; if
the message had included that name when it originally manifested in my
program, diagnosis would have taken less time.

Here is a demonstration of the problem.  I have a service listening on
port 8080 of the IPv6 loopback interface, "::1".  This code is running
on linux/x86_64.

Test program:

   $ cat testipv6.scm
   (define INADDR_LOOPBACK_IPV6 1)          ; "::1"
   (define sock (socket PF_INET6 SOCK_STREAM 0))
   (define addr (make-socket-address AF_INET6 INADDR_LOOPBACK_IPV6 8080))
   (display "about to connect\n")
   (connect sock addr)
   (display "connected!\n")
   (close-port sock)

Original behavior with Guile 1.8.7:

   $ guile testipv6.scm
   about to connect
   ERROR: Wrong type: #(10 1 8080 0 0)

After improving the scm_to_ipv6 error message:

   $ guile testipv6.scm
   about to connect
   ERROR: In procedure scm_to_ipv6:
   ERROR: Wrong type (expecting integer): #(10 1 8080 0 0)

After fixing the bug in scm_to_sockaddr:

   $ guile testipv6.scm
   about to connect
   connected!

-Scott


diff --git a/libguile/socket.c b/libguile/socket.c
index f34b6d4..b51e4f1 100644
--- a/libguile/socket.c
+++ b/libguile/socket.c
@@ -347,7 +347,7 @@ scm_to_ipv6 (scm_t_uint8 dst[16], SCM src)
        scm_remember_upto_here_1 (src);
      }
    else
-    scm_wrong_type_arg (NULL, 0, src);
+    scm_wrong_type_arg_msg ("scm_to_ipv6", 0, src, "integer");
  }

  #ifdef HAVE_INET_PTON
@@ -1167,7 +1167,7 @@ scm_to_sockaddr (SCM address, size_t *address_size)
  	  {
  	    struct sockaddr_in6 c_inet6;

-	    scm_to_ipv6 (c_inet6.sin6_addr.s6_addr, address);
+	    scm_to_ipv6 (c_inet6.sin6_addr.s6_addr, SCM_SIMPLE_VECTOR_REF 
(address, 1));
  	    c_inet6.sin6_port =
  	      htons (scm_to_ushort (SCM_SIMPLE_VECTOR_REF (address, 2)));
  	    c_inet6.sin6_flowinfo =




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: scm_to_sockaddr mishandles IPv6 addresses
  2009-09-30  3:16 scm_to_sockaddr mishandles IPv6 addresses Scott McPeak
@ 2009-10-01 22:29 ` Neil Jerram
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Jerram @ 2009-10-01 22:29 UTC (permalink / raw)
  To: Scott McPeak; +Cc: bug-guile

Scott McPeak <smcpeak@coverity.com> writes:

> Hi,
>
> In Guile-1.8.7, the function 'scm_to_sockaddr' mishandles IPv6
> addresses.  Specifically, it passes the 'address' parameter (which is
> a vector) to the 'scm_to_ipv6' function, which expects an integer.
>
> I have a patch, at the end, that fixes the problem.

Many thanks, I've applied this (plus some tests).

     Neil




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-01 22:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-30  3:16 scm_to_sockaddr mishandles IPv6 addresses Scott McPeak
2009-10-01 22:29 ` Neil Jerram

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).