From: Hans-Bernhard B. <br...@us...> - 2001-10-10 16:47:24
|
Update of /cvsroot/cscope/cscope/src In directory usw-pr-cvs1:/tmp/cvs-serv9136 Modified Files: dir.c Log Message: sprintf("%.*s") style buffer overflow safeguards. Remove unused argument of addsrcfile(). Index: dir.c =================================================================== RCS file: /cvsroot/cscope/cscope/src/dir.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** dir.c 2001/10/09 18:59:07 1.13 --- dir.c 2001/10/10 16:47:20 1.14 *************** *** 130,133 **** --- 130,135 ---- dir = strtok(dirlist, DIRSEPS); while (dir != NULL) { + int dir_len = strlen(dir); + addsrcdir(dir); *************** *** 138,142 **** /* compute its path from higher view path source dirs */ for (i = 1; i < nvpsrcdirs; ++i) { ! (void) sprintf(path, "%s/%s", srcdirs[i], dir); addsrcdir(path); } --- 140,146 ---- /* compute its path from higher view path source dirs */ for (i = 1; i < nvpsrcdirs; ++i) { ! (void) sprintf(path, "%.*s/%s", ! PATHLEN - 2 - dir_len, ! srcdirs[i], dir); addsrcdir(path); } *************** *** 194,197 **** --- 198,203 ---- dir = strtok(dirlist, DIRSEPS); while (dir != NULL) { + int dir_len = strlen(dir); + addincdir(dir, dir); *************** *** 202,207 **** /* compute its path from higher view path source dirs */ for (i = 1; i < nvpsrcdirs; ++i) { ! (void) snprintf(path, PATHLEN+1, ! "%s/%s", srcdirs[i], dir); addincdir(dir, path); } --- 208,214 ---- /* compute its path from higher view path source dirs */ for (i = 1; i < nvpsrcdirs; ++i) { ! (void) sprintf(path, "%.*s/%s", ! PATHLEN - 2 - dir_len, ! srcdirs[i], dir); addincdir(dir, path); } *************** *** 277,281 **** if (infilelist(file) == NO) { if ((s = inviewpath(file)) != NULL) { ! addsrcfile(file, s); } else { --- 284,288 ---- if (infilelist(file) == NO) { if ((s = inviewpath(file)) != NULL) { ! addsrcfile(s); } else { *************** *** 346,350 **** } else if ((s = inviewpath(path)) != NULL) { ! addsrcfile(path, s); } else { --- 353,357 ---- } else if ((s = inviewpath(path)) != NULL) { ! addsrcfile(s); } else { *************** *** 369,392 **** /* scan a directory (recursively?) for source files */ static void ! scan_dir(const char *adir, BOOL recurse_dir) { ! DIR *dirfile; ! if( (dirfile = opendir(adir)) != NULL ) { struct dirent *entry; char path[PATHLEN + 1]; char *file; ! while( (entry = readdir(dirfile)) != NULL ) { ! if( (strcmp(".",entry->d_name) != 0) ! && (strcmp("..",entry->d_name) != 0) ) { struct stat buf; ! sprintf(path,"%s/%s",adir,entry->d_name); ! if(lstat(path,&buf) == 0) { file = entry->d_name; ! if( recurse_dir && (buf.st_mode & S_IFDIR) ) { ! scan_dir(path, recurse_dir); } else if ( --- 376,405 ---- /* scan a directory (recursively?) for source files */ static void ! scan_dir(const char *adir, BOOL recurse_dir) ! { ! DIR *dirfile; ! int adir_len = strlen(adir); ! /* FIXME: no guards against adir_len > PATHLEN, yet */ ! ! if ((dirfile = opendir(adir)) != NULL) { struct dirent *entry; char path[PATHLEN + 1]; char *file; ! while ((entry = readdir(dirfile)) != NULL) { ! if ((strcmp(".",entry->d_name) != 0) ! && (strcmp("..",entry->d_name) != 0)) { struct stat buf; ! sprintf(path,"%s/%.*s", adir, ! PATHLEN - 2 - adir_len, ! entry->d_name); ! if (lstat(path,&buf) == 0) { file = entry->d_name; ! if (recurse_dir && (buf.st_mode & S_IFDIR) ) { ! scan_dir(path, recurse_dir); } else if ( *************** *** 398,402 **** && issrcfile(path) && infilelist(path) == NO) { ! addsrcfile(file, path); } } --- 411,415 ---- && issrcfile(path) && infilelist(path) == NO) { ! addsrcfile(path); } } *************** *** 488,506 **** /* look in current directory if it was #include "file" */ if (type[0] == '"' && (s = inviewpath(file)) != NULL) { ! addsrcfile(file, s); } else { /* search for the file in the #include directory list */ for (i = 0; i < nincdirs; ++i) { /* don't include the file from two directories */ ! (void) sprintf(name, "%s/%s", incnames[i], file); if (infilelist(name) == YES) { break; } /* make sure it exists and is readable */ ! (void) sprintf(path, "%s/%s", incdirs[i], file); if (access(compath(path), READ) == 0) { ! addsrcfile(name, path); break; } --- 501,525 ---- /* look in current directory if it was #include "file" */ if (type[0] == '"' && (s = inviewpath(file)) != NULL) { ! addsrcfile(s); } else { + int file_len = strlen(file); + /* search for the file in the #include directory list */ for (i = 0; i < nincdirs; ++i) { /* don't include the file from two directories */ ! (void) sprintf(name, "%.*s/%s", ! PATHLEN - 2 - file_len, incnames[i], ! file); if (infilelist(name) == YES) { break; } /* make sure it exists and is readable */ ! (void) sprintf(path, "%.*s/%s", ! PATHLEN - 2 - file_len, incdirs[i], ! file); if (access(compath(path), READ) == 0) { ! addsrcfile(path); break; } *************** *** 538,545 **** /* if it isn't a full path name and there is a multi-directory view path */ if (*file != '/' && vpndirs > 1) { /* compute its path from higher view path source dirs */ for (i = 1; i < nvpsrcdirs; ++i) { ! (void) sprintf(path, "%s/%s", srcdirs[i], file); if (access(compath(path), READ) == 0) { return(path); --- 557,567 ---- /* if it isn't a full path name and there is a multi-directory view path */ if (*file != '/' && vpndirs > 1) { + int file_len = strlen(file); /* compute its path from higher view path source dirs */ for (i = 1; i < nvpsrcdirs; ++i) { ! (void) sprintf(path, "%.*s/%s", ! PATHLEN - 2 - file_len, srcdirs[i], ! file); if (access(compath(path), READ) == 0) { return(path); *************** *** 552,562 **** /* add a source file to the list */ - /* TODO:-=db=-: remove the name parameter. it is not used - * any longer, since we're now using path to check for - * existence of file in srcfiles[] - */ - void ! addsrcfile(char *name, char *path) { struct listitem *p; --- 574,579 ---- /* add a source file to the list */ void ! addsrcfile(char *path) { struct listitem *p; |