From f92f80fbb8926d980a6a46c488f7f60a35c9bf9c Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 14 Aug 2022 10:41:39 -0700 Subject: CheckFullyQuantifiedName: improve gethostname() handling Handle errors and use HOST_NAME_MAX for the buffer size if it is defined by Signed-off-by: Alan Coopersmith --- smproxy.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/smproxy.c b/smproxy.c index 84c8b29..5de7354 100644 --- a/smproxy.c +++ b/smproxy.c @@ -28,6 +28,11 @@ Author: Ralph Mor, X Consortium #include "smproxy.h" #include #include +#include + +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX 256 +#endif static XtAppContext appContext; static Display *disp; @@ -210,11 +215,13 @@ CheckFullyQuantifiedName(char *name, int *newstring) } else { - char hostnamebuf[80]; + char hostnamebuf[HOST_NAME_MAX + 1] = { 0 }; char *firstDot; - gethostname (hostnamebuf, sizeof hostnamebuf); - firstDot = strchr (hostnamebuf, '.'); + if (gethostname (hostnamebuf, sizeof hostnamebuf) == 0) + firstDot = strchr (hostnamebuf, '.'); + else + firstDot = NULL; if (!firstDot) { -- cgit v1.2.3