[libvirt] [PATCH] network utilities: Allocate space for terminating NUL in virSocketFormatAddr
Richard W.M. Jones
rjones at redhat.com
Wed Nov 4 11:06:10 UTC 2009
On Wed, Nov 04, 2009 at 11:00:14AM +0000, 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
More information about the libvir-list
mailing list