diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-10-12 22:40:14 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-10-12 22:40:14 +0000 |
commit | e7e1e2dcadc48d9de9b3ad64e589c8d419b58aa9 (patch) | |
tree | 52e5299b778c0af473a95070cddffce8e7a9e1b7 /coreutils/ls.c | |
parent | 0d5835a7674e8f36a5669e567be32d53dff401ac (diff) | |
download | busybox-w32-e7e1e2dcadc48d9de9b3ad64e589c8d419b58aa9.tar.gz busybox-w32-e7e1e2dcadc48d9de9b3ad64e589c8d419b58aa9.tar.bz2 busybox-w32-e7e1e2dcadc48d9de9b3ad64e589c8d419b58aa9.zip |
Apply a patch from Matt Kraai to fix buffer overrun and convert to
using synamically allocated storage.
-Erik
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r-- | coreutils/ls.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 8d975fd13..a35070f20 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -450,45 +450,41 @@ struct dnode **list_dir(char *path) | |||
450 | struct dnode *dn, *cur, **dnp; | 450 | struct dnode *dn, *cur, **dnp; |
451 | struct dirent *entry; | 451 | struct dirent *entry; |
452 | DIR *dir; | 452 | DIR *dir; |
453 | char *fnend, fullname[BUFSIZ+1] ; | ||
454 | int i, nfiles; | 453 | int i, nfiles; |
455 | 454 | ||
456 | if (path==NULL) return(NULL); | 455 | if (path==NULL) return(NULL); |
457 | strcpy(fullname, path); | ||
458 | fnend = fullname + strlen(fullname); | ||
459 | if (fnend[-1] != '/') { | ||
460 | strcat(fullname, "/"); | ||
461 | fnend++; | ||
462 | } | ||
463 | 456 | ||
464 | dn= NULL; | 457 | dn= NULL; |
465 | nfiles= 0; | 458 | nfiles= 0; |
466 | dir = opendir(fullname); | 459 | dir = opendir(path); |
467 | if (dir == NULL) { | 460 | if (dir == NULL) { |
468 | errorMsg("%s: %s\n", fullname, strerror(errno)); | 461 | errorMsg("%s: %s\n", path, strerror(errno)); |
469 | return(NULL); /* could not open the dir */ | 462 | return(NULL); /* could not open the dir */ |
470 | } | 463 | } |
471 | while ((entry = readdir(dir)) != NULL) { | 464 | while ((entry = readdir(dir)) != NULL) { |
472 | /* are we going to list the file- it may be . or .. or a hidden file */ | 465 | /* are we going to list the file- it may be . or .. or a hidden file */ |
473 | strcpy(fnend, entry->d_name); | 466 | if ((strcmp(entry->d_name, ".")==0) && !(disp_opts & DISP_DOT)) continue; |
474 | if ((strcmp(fnend, ".")==0) && !(disp_opts & DISP_DOT)) continue; | 467 | if ((strcmp(entry->d_name, "..")==0) && !(disp_opts & DISP_DOT)) continue; |
475 | if ((strcmp(fnend, "..")==0) && !(disp_opts & DISP_DOT)) continue; | 468 | if ((entry->d_name[0] == '.') && !(disp_opts & DISP_HIDDEN)) continue; |
476 | if ((fnend[0] == '.') && !(disp_opts & DISP_HIDDEN)) continue; | ||
477 | cur= (struct dnode *)xmalloc(sizeof(struct dnode)); | 469 | cur= (struct dnode *)xmalloc(sizeof(struct dnode)); |
478 | cur->fullname= xstrdup(fullname); | 470 | cur->fullname = xmalloc(strlen(path)+1+strlen(entry->d_name)+1); |
479 | cur->name= cur->fullname + (int)(fnend - fullname) ; | 471 | strcpy(cur->fullname, path); |
472 | if (cur->fullname[strlen(cur->fullname)-1] != '/') | ||
473 | strcat(cur->fullname, "/"); | ||
474 | cur->name= cur->fullname + strlen(cur->fullname); | ||
475 | strcat(cur->fullname, entry->d_name); | ||
480 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 476 | #ifdef BB_FEATURE_LS_FOLLOWLINKS |
481 | if (follow_links == TRUE) { | 477 | if (follow_links == TRUE) { |
482 | if (stat(fullname, &cur->dstat)) { | 478 | if (stat(cur->fullname, &cur->dstat)) { |
483 | errorMsg("%s: %s\n", fullname, strerror(errno)); | 479 | errorMsg("%s: %s\n", cur->fullname, strerror(errno)); |
484 | free(cur->fullname); | 480 | free(cur->fullname); |
485 | free(cur); | 481 | free(cur); |
486 | continue; | 482 | continue; |
487 | } | 483 | } |
488 | } else | 484 | } else |
489 | #endif | 485 | #endif |
490 | if (lstat(fullname, &cur->dstat)) { /* get file stat info into node */ | 486 | if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */ |
491 | errorMsg("%s: %s\n", fullname, strerror(errno)); | 487 | errorMsg("%s: %s\n", cur->fullname, strerror(errno)); |
492 | free(cur->fullname); | 488 | free(cur->fullname); |
493 | free(cur); | 489 | free(cur); |
494 | continue; | 490 | continue; |