diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-15 18:22:05 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-15 18:22:05 +0000 |
commit | c6ec8c96800cd5ebd884ef1bd4d6564bac747f54 (patch) | |
tree | 8df6df45baa19dddc5bfc64e5120d0ec0f11e372 | |
parent | 023b57d935dedda30e577e8be1461eec27294c93 (diff) | |
download | busybox-w32-c6ec8c96800cd5ebd884ef1bd4d6564bac747f54.tar.gz busybox-w32-c6ec8c96800cd5ebd884ef1bd4d6564bac747f54.tar.bz2 busybox-w32-c6ec8c96800cd5ebd884ef1bd4d6564bac747f54.zip |
telnetd: check ptsname() for NULL
-rw-r--r-- | networking/telnetd.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/networking/telnetd.c b/networking/telnetd.c index c6789e19c..da7911fcc 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -188,12 +188,18 @@ getpty(char *line) | |||
188 | { | 188 | { |
189 | int p; | 189 | int p; |
190 | #ifdef CONFIG_FEATURE_DEVPTS | 190 | #ifdef CONFIG_FEATURE_DEVPTS |
191 | p = open("/dev/ptmx", 2); | 191 | p = open("/dev/ptmx", O_RDWR); |
192 | if (p > 0) { | 192 | if (p > 0) { |
193 | const char *name; | ||
193 | grantpt(p); | 194 | grantpt(p); |
194 | unlockpt(p); | 195 | unlockpt(p); |
195 | strcpy(line, ptsname(p)); | 196 | name = ptsname(p); |
196 | return(p); | 197 | if (!name) { |
198 | bb_perror_msg("ptsname error (is /dev/pts mounted?)"); | ||
199 | return -1; | ||
200 | } | ||
201 | strcpy(line, name); | ||
202 | return p; | ||
197 | } | 203 | } |
198 | #else | 204 | #else |
199 | struct stat stb; | 205 | struct stat stb; |
@@ -213,7 +219,8 @@ getpty(char *line) | |||
213 | #ifdef DEBUG | 219 | #ifdef DEBUG |
214 | fprintf(stderr, "Trying to open device: %s\n", line); | 220 | fprintf(stderr, "Trying to open device: %s\n", line); |
215 | #endif | 221 | #endif |
216 | if ((p = open(line, O_RDWR | O_NOCTTY)) >= 0) { | 222 | p = open(line, O_RDWR | O_NOCTTY); |
223 | if (p >= 0) { | ||
217 | line[5] = 't'; | 224 | line[5] = 't'; |
218 | return p; | 225 | return p; |
219 | } | 226 | } |
@@ -387,7 +394,7 @@ telnetd_main(int argc, char **argv) | |||
387 | openlog(applet_name, 0, LOG_USER); | 394 | openlog(applet_name, 0, LOG_USER); |
388 | logmode = LOGMODE_SYSLOG; | 395 | logmode = LOGMODE_SYSLOG; |
389 | 396 | ||
390 | opt = getopt32(argc, argv, "f:l:" USE_FEATURE_TELNETD_INETD("p:b:"), | 397 | opt = getopt32(argc, argv, "f:l:" SKIP_FEATURE_TELNETD_INETD("p:b:"), |
391 | &issuefile, &loginpath | 398 | &issuefile, &loginpath |
392 | SKIP_FEATURE_TELNETD_INETD(, &opt_portnbr, &opt_bindaddr)); | 399 | SKIP_FEATURE_TELNETD_INETD(, &opt_portnbr, &opt_bindaddr)); |
393 | //if (opt & 1) // -f | 400 | //if (opt & 1) // -f |
@@ -435,7 +442,7 @@ telnetd_main(int argc, char **argv) | |||
435 | maxfd = master_fd; | 442 | maxfd = master_fd; |
436 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ | 443 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ |
437 | 444 | ||
438 | do { | 445 | while(1) { |
439 | struct tsession *ts; | 446 | struct tsession *ts; |
440 | 447 | ||
441 | FD_ZERO(&rdfdset); | 448 | FD_ZERO(&rdfdset); |
@@ -493,8 +500,8 @@ telnetd_main(int argc, char **argv) | |||
493 | socklen_t salen; | 500 | socklen_t salen; |
494 | 501 | ||
495 | salen = sizeof(sa); | 502 | salen = sizeof(sa); |
496 | if ((fd = accept(master_fd, (struct sockaddr *)&sa, | 503 | fd = accept(master_fd, (struct sockaddr *)&sa, &salen); |
497 | &salen)) < 0) { | 504 | if (fd < 0) { |
498 | continue; | 505 | continue; |
499 | } else { | 506 | } else { |
500 | /* Create a new session and link it into | 507 | /* Create a new session and link it into |
@@ -632,7 +639,7 @@ telnetd_main(int argc, char **argv) | |||
632 | } | 639 | } |
633 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ | 640 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ |
634 | 641 | ||
635 | } while (1); | 642 | } /* while(1) */ |
636 | 643 | ||
637 | return 0; | 644 | return 0; |
638 | } | 645 | } |