[libvirt] [PATCH] network utilities: Allocate space for terminating NUL in virSocketFormatAddr
* src/util/network.c: Allocate an additional byte for virSocketFormatAddr's return buffer --- src/util/network.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/network.c b/src/util/network.c index 56426e7..f6588c7 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -135,12 +135,12 @@ virSocketFormatAddr(virSocketAddrPtr addr) { return NULL; if (addr-stor.ss_family == AF_INET) { -outlen = INET_ADDRSTRLEN; +outlen = INET_ADDRSTRLEN + 1; inaddr = addr-inet4.sin_addr; } else if (addr-stor.ss_family == AF_INET6) { -outlen = INET6_ADDRSTRLEN; +outlen = INET6_ADDRSTRLEN + 1; inaddr = addr-inet6.sin6_addr; } -- 1.6.2.5 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] network utilities: Allocate space for terminating NUL in virSocketFormatAddr
On Wed, Nov 04, 2009 at 11:00:14AM +, Matthew Booth wrote: * src/util/network.c: Allocate an additional byte for virSocketFormatAddr's return buffer --- src/util/network.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/network.c b/src/util/network.c index 56426e7..f6588c7 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -135,12 +135,12 @@ virSocketFormatAddr(virSocketAddrPtr addr) { return NULL; if (addr-stor.ss_family == AF_INET) { -outlen = INET_ADDRSTRLEN; +outlen = INET_ADDRSTRLEN + 1; inaddr = addr-inet4.sin_addr; } else if (addr-stor.ss_family == AF_INET6) { -outlen = INET6_ADDRSTRLEN; +outlen = INET6_ADDRSTRLEN + 1; inaddr = addr-inet6.sin6_addr; } Are you sure about this? According to the man page for inet_ntop the INET*_ADDRSTRLEN macro should be long enough already: AF_INET src points to a struct in_addr (in network byte order) which is converted to an IPv4 network address in the dotted-decimal for- mat, ddd.ddd.ddd.ddd. The buffer dst must be at least INET_ADDRSTRLEN bytes long. AF_INET6 src points to a struct in6_addr (in network byte order) which is converted to a representation of this address in the most appro- priate IPv6 network address format for this address. The buffer dst must be at least INET6_ADDRSTRLEN bytes long. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] network utilities: Allocate space for terminating NUL in virSocketFormatAddr
On 04/11/09 11:06, Richard W.M. Jones wrote: Are you sure about this? According to the man page for inet_ntop the INET*_ADDRSTRLEN macro should be long enough already: AF_INET src points to a struct in_addr (in network byte order) which is converted to an IPv4 network address in the dotted-decimal for- mat, ddd.ddd.ddd.ddd. The buffer dst must be at least INET_ADDRSTRLEN bytes long. AF_INET6 src points to a struct in6_addr (in network byte order) which is converted to a representation of this address in the most appro- priate IPv6 network address format for this address. The buffer dst must be at least INET6_ADDRSTRLEN bytes long. No, I wasn't sure :) However, reading this and realising I miscalculated the maximum size of an IPv4 address[1], I'll withdraw this patch. Thanks, Matt [1] INET_ADDRSTRLEN == 16. I forgot there's only 3 dots, so I didn't think it was leaving space. -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team M: +44 (0)7977 267231 GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list