summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-14 10:41:39 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-14 10:44:11 -0700
commitf92f80fbb8926d980a6a46c488f7f60a35c9bf9c (patch)
treedd426333ab83d88419e4b437028837551e130e02
parent5bf2e626a25f0ac1503effbf89c01573392ea658 (diff)
CheckFullyQuantifiedName: improve gethostname() handling
Handle errors and use HOST_NAME_MAX for the buffer size if it is defined by <limits.h> Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--smproxy.c13
1 files 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 <unistd.h>
#include <X11/Xmu/WinUtil.h>
+#include <limits.h>
+
+#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)
{