diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-04-20 01:48:58 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2021-04-20 01:48:58 +0000 |
commit | 2c0bf67b7612a11f64e7407a69b51d909a5ae277 (patch) | |
tree | b53b11761e41cfd77262612f34d2ca03e2c47393 | |
parent | 062da0aa2e309dd8393eea7083a124d5d4f79c17 (diff) | |
download | s6-linux-init-2c0bf67b7612a11f64e7407a69b51d909a5ae277.tar.xz |
Everyone loves systems that do not define proper limits
-rw-r--r-- | src/shutdown/hpr_confirm_hostname.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/shutdown/hpr_confirm_hostname.c b/src/shutdown/hpr_confirm_hostname.c index 040c2f6..e782c80 100644 --- a/src/shutdown/hpr_confirm_hostname.c +++ b/src/shutdown/hpr_confirm_hostname.c @@ -17,15 +17,17 @@ void hpr_confirm_hostname (void) { - char name[HOST_NAME_MAX + 1] ; - char buf[HOST_NAME_MAX + 1] ; char *p ; ssize_t r ; + long hostnamemax = sysconf(_SC_HOST_NAME_MAX) ; + if (hostnamemax < 0) hostnamemax = _POSIX_HOST_NAME_MAX ; + char name[hostnamemax + 1] ; + char buf[hostnamemax + 1] ; if (!isatty(0) || !isatty(1)) strerr_diefu1x(100, "ask hostname confirmation: stdin or stdout is not a tty") ; - if (gethostname(name, HOST_NAME_MAX) < 0) + if (gethostname(name, hostnamemax) < 0) strerr_diefu1sys(111, "get host name") ; - name[HOST_NAME_MAX] = 0 ; + name[hostnamemax] = 0 ; p = strchr(name, '.') ; if (p) *p = 0 ; if (allwrite(1, PROMPT, sizeof(PROMPT)-1) < 0) @@ -34,7 +36,7 @@ void hpr_confirm_hostname (void) strerr_diefu1sys(111, "tcdrain stdout") ; if (tcflush(0, TCIFLUSH) < 0) strerr_diefu1sys(111, "empty stdin buffer") ; - r = fd_read(0, buf, HOST_NAME_MAX) ; + r = fd_read(0, buf, hostnamemax) ; if (!r) errno = EPIPE ; if (r <= 0) strerr_diefu1sys(111, "read from stdin") ; buf[byte_chr(buf, r, '\n')] = 0 ; |