From: Scott McPeak <smcpeak@coverity.com>
To: bug-guile@gnu.org
Subject: scm_to_sockaddr mishandles IPv6 addresses
Date: Tue, 29 Sep 2009 20:16:50 -0700 [thread overview]
Message-ID: <4AC2CDA2.3050409@coverity.com> (raw)
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 =
next reply other threads:[~2009-09-30 3:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-30 3:16 Scott McPeak [this message]
2009-10-01 22:29 ` scm_to_sockaddr mishandles IPv6 addresses Neil Jerram
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=4AC2CDA2.3050409@coverity.com \
--to=smcpeak@coverity.com \
--cc=bug-guile@gnu.org \
/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).