fix uninitialized buffer for getnameinfo on failure - geomyidae - A small C-based gopherd. (HTM) git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/ (DIR) Log (DIR) Files (DIR) Refs (DIR) Tags (DIR) README (DIR) LICENSE --- (DIR) commit bc06de10b6d279ef57ad0ba294610447bd2988fc (DIR) parent f02d57cfae2c18951b665353b21aed02d29731a9 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Wed, 29 Aug 2018 20:31:30 +0200 fix uninitialized buffer for getnameinfo on failure POSIX says for getnameinfo: "Upon successful completion, getnameinfo() shall return the node and service names, if requested, in the buffers provided. The returned names are always null-terminated strings." How I interpret it is on failure these buffers can be undefined, so make sure to clear them on failure. Signed-off-by: Christoph Lohmann <20h@r-36.net> Diffstat: M main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- (DIR) diff --git a/main.c b/main.c @@ -558,9 +558,11 @@ main(int argc, char *argv[]) } } - getnameinfo((struct sockaddr *)&clt, cltlen, clienth, + if (getnameinfo((struct sockaddr *)&clt, cltlen, clienth, sizeof(clienth), clientp, sizeof(clientp), - NI_NUMERICHOST|NI_NUMERICSERV); + NI_NUMERICHOST|NI_NUMERICSERV)) { + clienth[0] = clientp[0] = '\0'; + } if (!strncmp(clienth, "::ffff:", 7)) memmove(clienth, clienth+7, strlen(clienth)-6);