telnetd: check ptsname() for NULL

This commit is contained in:
Denis Vlasenko 2006-10-15 18:22:05 +00:00
parent 023b57d935
commit c6ec8c9680

View File

@ -188,12 +188,18 @@ getpty(char *line)
{ {
int p; int p;
#ifdef CONFIG_FEATURE_DEVPTS #ifdef CONFIG_FEATURE_DEVPTS
p = open("/dev/ptmx", 2); p = open("/dev/ptmx", O_RDWR);
if (p > 0) { if (p > 0) {
const char *name;
grantpt(p); grantpt(p);
unlockpt(p); unlockpt(p);
strcpy(line, ptsname(p)); name = ptsname(p);
return(p); if (!name) {
bb_perror_msg("ptsname error (is /dev/pts mounted?)");
return -1;
}
strcpy(line, name);
return p;
} }
#else #else
struct stat stb; struct stat stb;
@ -213,7 +219,8 @@ getpty(char *line)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Trying to open device: %s\n", line); fprintf(stderr, "Trying to open device: %s\n", line);
#endif #endif
if ((p = open(line, O_RDWR | O_NOCTTY)) >= 0) { p = open(line, O_RDWR | O_NOCTTY);
if (p >= 0) {
line[5] = 't'; line[5] = 't';
return p; return p;
} }
@ -387,7 +394,7 @@ telnetd_main(int argc, char **argv)
openlog(applet_name, 0, LOG_USER); openlog(applet_name, 0, LOG_USER);
logmode = LOGMODE_SYSLOG; logmode = LOGMODE_SYSLOG;
opt = getopt32(argc, argv, "f:l:" USE_FEATURE_TELNETD_INETD("p:b:"), opt = getopt32(argc, argv, "f:l:" SKIP_FEATURE_TELNETD_INETD("p:b:"),
&issuefile, &loginpath &issuefile, &loginpath
SKIP_FEATURE_TELNETD_INETD(, &opt_portnbr, &opt_bindaddr)); SKIP_FEATURE_TELNETD_INETD(, &opt_portnbr, &opt_bindaddr));
//if (opt & 1) // -f //if (opt & 1) // -f
@ -435,7 +442,7 @@ telnetd_main(int argc, char **argv)
maxfd = master_fd; maxfd = master_fd;
#endif /* CONFIG_FEATURE_TELNETD_INETD */ #endif /* CONFIG_FEATURE_TELNETD_INETD */
do { while(1) {
struct tsession *ts; struct tsession *ts;
FD_ZERO(&rdfdset); FD_ZERO(&rdfdset);
@ -493,8 +500,8 @@ telnetd_main(int argc, char **argv)
socklen_t salen; socklen_t salen;
salen = sizeof(sa); salen = sizeof(sa);
if ((fd = accept(master_fd, (struct sockaddr *)&sa, fd = accept(master_fd, (struct sockaddr *)&sa, &salen);
&salen)) < 0) { if (fd < 0) {
continue; continue;
} else { } else {
/* Create a new session and link it into /* Create a new session and link it into
@ -632,7 +639,7 @@ telnetd_main(int argc, char **argv)
} }
#endif /* CONFIG_FEATURE_TELNETD_INETD */ #endif /* CONFIG_FEATURE_TELNETD_INETD */
} while (1); } /* while(1) */
return 0; return 0;
} }