diff options
author | Paul Fertser <fercerpav@gmail.com> | 2018-01-17 17:31:58 +0300 |
---|---|---|
committer | Tomas Vanek <vanekt@fbl.cz> | 2018-01-25 07:22:16 +0000 |
commit | f02327d85953152743dbb02d9ceeaa5b59da9ebe (patch) | |
tree | 1341a9c29fc3dea4c5e2abadec4567a5bd2fda41 /src | |
parent | ff623b83fc74d40adcdfb36454393cf307d70f08 (diff) | |
download | riscv-openocd-f02327d85953152743dbb02d9ceeaa5b59da9ebe.zip riscv-openocd-f02327d85953152743dbb02d9ceeaa5b59da9ebe.tar.gz riscv-openocd-f02327d85953152743dbb02d9ceeaa5b59da9ebe.tar.bz2 |
server: add safeguards against printing bogus port number
Clang static checker emits "Assigned value is garbage or undefined"
warning there as it can't prove that when the socket descriptor is
AF_INET/SOCK_STREAM and getsockname doesn't return an error, sin_port
is guaranteed to be filled in.
Pacify it by obvious means.
Change-Id: I43b5e5ceb41c07d523a81b34a25490c4c5f49a70
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/4350
Tested-by: jenkins
Reviewed-by: Tim Newsome <tim@sifive.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src')
-rw-r--r-- | src/server/server.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/server/server.c b/src/server/server.c index 1e52e97..46c860f 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -300,10 +300,11 @@ int add_service(char *name, } struct sockaddr_in addr_in; + addr_in.sin_port = 0; socklen_t addr_in_size = sizeof(addr_in); - getsockname(c->fd, (struct sockaddr *)&addr_in, &addr_in_size); - LOG_INFO("Listening on port %hu for %s connections", - ntohs(addr_in.sin_port), name); + if (getsockname(c->fd, (struct sockaddr *)&addr_in, &addr_in_size) == 0) + LOG_INFO("Listening on port %hu for %s connections", + ntohs(addr_in.sin_port), name); } else if (c->type == CONNECTION_STDINOUT) { c->fd = fileno(stdin); |