| fix uninitialized buffer for getnameinfo on failure - geomyidae - A small C-bas… | |
| git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri… | |
| Log | |
| Files | |
| Refs | |
| Tags | |
| README | |
| LICENSE | |
| --- | |
| commit bc06de10b6d279ef57ad0ba294610447bd2988fc | |
| parent f02d57cfae2c18951b665353b21aed02d29731a9 | |
| Author: Hiltjo Posthuma <[email protected]> | |
| 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 <[email protected]> | |
| Diffstat: | |
| M main.c | 6 ++++-- | |
| 1 file changed, 4 insertions(+), 2 deletions(-) | |
| --- | |
| 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); |