Skip to content
Permalink
Browse files

net: sockets: Initialize IP socket addresses in getsockname()

Make sure the IPv4 and IPv6 socket addresses are initialized before
copying them. This avoids uninitialized memory access.

Coverity-CID: 199436
Fixes #17202

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Jul 2, 2019
1 parent a18bd3a commit 2f95f4afe7bc437b3038f9bb1336668527a6baf4
Showing with 2 additions and 2 deletions.
  1. +2 −2 subsys/net/lib/sockets/sockets.c
@@ -1250,7 +1250,7 @@ int zsock_getsockname_ctx(struct net_context *ctx, struct sockaddr *addr,
}

if (IS_ENABLED(CONFIG_NET_IPV4) && ctx->local.family == AF_INET) {
struct sockaddr_in addr4;
struct sockaddr_in addr4 = { 0 };

addr4.sin_family = AF_INET;
addr4.sin_port = net_sin_ptr(&ctx->local)->sin_port;
@@ -1261,7 +1261,7 @@ int zsock_getsockname_ctx(struct net_context *ctx, struct sockaddr *addr,
memcpy(addr, &addr4, MIN(*addrlen, newlen));
} else if (IS_ENABLED(CONFIG_NET_IPV6) &&
ctx->local.family == AF_INET6) {
struct sockaddr_in6 addr6;
struct sockaddr_in6 addr6 = { 0 };

addr6.sin6_family = AF_INET6;
addr6.sin6_port = net_sin6_ptr(&ctx->local)->sin6_port;

0 comments on commit 2f95f4a

Please sign in to comment.
You can’t perform that action at this time.