lash is phased out. hush can be configured down to be nearly as small,
but less buggy :)
init
- General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
+ General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG).
Do a SUSv3 audit
Look at the full Single Unix Specification version 3 (available online at
"http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
retval = 0;
- s = ttyname(0);
+ s = xmalloc_ttyname(0);
if (s == NULL) {
/* According to SUSv3, ttyname can fail with EBADF or ENOTTY.
* We know the file descriptor is good, so failure means not a tty. */
extern void print_login_issue(const char *issue_file, const char *tty) FAST_FUNC;
extern void print_login_prompt(void) FAST_FUNC;
+char *xmalloc_ttyname(int fd) FAST_FUNC;
/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC;
if (--argc == 0
|| (argc == 1 && ((c = **++argv) == 'y' || c == 'n'))
) {
- tty = ttyname(STDERR_FILENO);
+ tty = xmalloc_ttyname(STDERR_FILENO);
if (tty == NULL) {
tty = "ttyname";
} else if (stat(tty, &sb) == 0) {
}
#endif
+char* FAST_FUNC xmalloc_ttyname(int fd)
+{
+ char *buf = xzalloc(128);
+ int r = ttyname_r(fd, buf, 127);
+ if (r) {
+ free(buf);
+ buf = NULL;
+ }
+ return buf;
+}
+
/* It is perfectly ok to pass in a NULL for either width or for
* height, in which case that value will not be set. */
int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *height)
if (!isatty(0) || !isatty(1) || !isatty(2))
return EXIT_FAILURE; /* Must be a terminal */
safe_strncpy(full_tty, "UNKNOWN", sizeof(full_tty));
- tmp = ttyname(0);
+ tmp = xmalloc_ttyname(STDIN_FILENO);
if (tmp) {
safe_strncpy(full_tty, tmp, sizeof(full_tty));
if (strncmp(full_tty, "/dev/", 5) == 0)
read_or_build_utent(&utent, run_by_root);
if (opt & LOGIN_OPT_h) {
- USE_FEATURE_UTMP(
+ if (ENABLE_FEATURE_UTMP)
safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host));
- )
fromhost = xasprintf(" on '%s' from '%s'", short_tty, opt_host);
- } else
+ } else {
fromhost = xasprintf(" on '%s'", short_tty);
+ }
/* Was breaking "login <username>" from shell command line: */
/*bb_setpgrp();*/
But getlogin can fail -- usually due to lack of utmp entry.
in this case resort to getpwuid. */
old_user = xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : "");
- tty = ttyname(2) ? : "none";
+ tty = xmalloc_ttyname(2) ? : "none";
openlog(applet_name, 0, LOG_AUTH);
}
/* files contexts */
puts("\nFile contexts:");
- cterm = ttyname(0);
+ cterm = xmalloc_ttyname(0);
+//FIXME: if cterm == NULL, we segfault!??
puts(cterm);
if (cterm && lgetfilecon(cterm, &con) >= 0) {
printf(COL_FMT "%s\n", "Controlling term:", con);
freecon(con);
}
- for (i=0; fc[i] != NULL; i++) {
+ for (i = 0; fc[i] != NULL; i++) {
struct stat stbuf;
if (lgetfilecon(fc[i], &con) < 0)
int ash_main(int argc UNUSED_PARAM, char **argv)
{
char *shinit;
- volatile int state;
+ volatile smallint state;
struct jmploc jmploc;
struct stackmark smark;
state = 0;
if (setjmp(jmploc.loc)) {
int e;
- int s;
+ smallint s;
reset();
}
}
#endif
- if (argv[0] && argv[0][0] == '-')
+ if (/* argv[0] && */ argv[0][0] == '-')
isloginsh = 1;
if (isloginsh) {
state = 1;