diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Kbuild | 1 | ||||
-rw-r--r-- | libbb/lineedit.c | 6 | ||||
-rw-r--r-- | libbb/login.c | 14 | ||||
-rw-r--r-- | libbb/obscure.c | 13 |
4 files changed, 13 insertions, 21 deletions
diff --git a/libbb/Kbuild b/libbb/Kbuild index 515368d..aab016e 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild @@ -73,6 +73,7 @@ lib-y += recursive_action.o lib-y += remove_file.o lib-y += restricted_shell.o lib-y += run_shell.o +lib-y += safe_gethostname.o lib-y += safe_poll.o lib-y += safe_strncpy.o lib-y += safe_write.o diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 9aab637..c6aa45c 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1203,11 +1203,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) break; #endif case 'h': - pbuf = free_me = xzalloc(256); - if (gethostname(pbuf, 255) < 0) { - pbuf[0] = '?'; - pbuf[1] = '\0'; - } + pbuf = free_me = safe_gethostname(); *strchrnul(pbuf, '.') = '\0'; break; case '$': diff --git a/libbb/login.c b/libbb/login.c index d1f5d64..a711a54 100644 --- a/libbb/login.c +++ b/libbb/login.c @@ -50,6 +50,7 @@ void print_login_issue(const char *issue_file, const char *tty) outbuf = uts.sysname; break; case 'n': + case 'h': outbuf = uts.nodename; break; case 'r': @@ -72,10 +73,6 @@ void print_login_issue(const char *issue_file, const char *tty) case 't': strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); break; - case 'h': - gethostname(buf, sizeof(buf) - 1); - buf[sizeof(buf) - 1] = '\0'; - break; case 'l': outbuf = tty; break; @@ -91,13 +88,12 @@ void print_login_issue(const char *issue_file, const char *tty) void print_login_prompt(void) { - char buf[MAXHOSTNAMELEN+1]; - - if (gethostname(buf, MAXHOSTNAMELEN) == 0) - fputs(buf, stdout); - + char *hostname = safe_gethostname(); + + fputs(hostname, stdout); fputs(LOGIN, stdout); fflush(stdout); + free(hostname); } /* Clear dangerous stuff, set PATH */ diff --git a/libbb/obscure.c b/libbb/obscure.c index 5cc9062..1841b27 100644 --- a/libbb/obscure.c +++ b/libbb/obscure.c @@ -93,7 +93,7 @@ static const char *obscure_msg(const char *old_p, const char *new_p, const struc /* Add 2 for each type of characters to the minlen of password */ int size = CONFIG_PASSWORD_MINLEN + 8; const char *p; - char hostname[255]; + char *hostname; /* size */ if (!new_p || (length = strlen(new_p)) < CONFIG_PASSWORD_MINLEN) @@ -108,12 +108,11 @@ static const char *obscure_msg(const char *old_p, const char *new_p, const struc return "similar to gecos"; } /* hostname as-is, as sub-string, reversed, capitalized, doubled */ - if (gethostname(hostname, 255) == 0) { - hostname[254] = '\0'; - if (string_checker(new_p, hostname)) { - return "similar to hostname"; - } - } + hostname = safe_gethostname(); + i = string_checker(new_p, hostname); + free(hostname); + if (i) + return "similar to hostname"; /* Should / Must contain a mix of: */ for (i = 0; i < length; i++) { |