Skip to content

Commit b16d194

Browse files
committed
Fall back to "localhost" if gethostname() fails.
GitHub issue #332 --HG-- branch : 1.9
1 parent 3cbcb30 commit b16d194

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

plugins/sudoers/sethost.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <config.h>
2525

26+
#include <errno.h>
2627
#include <stdio.h>
2728
#include <stdlib.h>
2829
#include <string.h>
@@ -47,10 +48,13 @@ sudoers_sethost(struct sudoers_context *ctx, const char *host,
4748
ctx->user.host = NULL;
4849
ctx->user.shost = NULL;
4950

50-
if (host == NULL)
51+
if (host == NULL) {
5152
ctx->user.host = sudo_gethostname();
52-
else
53+
if (ctx->user.host == NULL && errno != ENOMEM)
54+
ctx->user.host = strdup("localhost");
55+
} else {
5356
ctx->user.host = strdup(host);
57+
}
5458
if (ctx->user.host == NULL)
5559
goto oom;
5660
if ((cp = strchr(ctx->user.host, '.')) != NULL) {

0 commit comments

Comments
 (0)