mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-12 17:08:39 -09:00
Fixed buffer overflow when supplying a path longer than PATH_MAX (patch by Tobias Stoeckmann)
git-svn-id: svn://blicky.net/ncdu/trunk@28 ce56bc8d-f834-0410-b703-f827bd498a76
This commit is contained in:
parent
db920f8dab
commit
8a71f8860c
2 changed files with 7 additions and 1 deletions
|
|
@ -60,6 +60,8 @@ char *rpath(const char *from, char *to) {
|
||||||
strcpy(tmp, cwd);
|
strcpy(tmp, cwd);
|
||||||
else
|
else
|
||||||
tmp[0] = 0;
|
tmp[0] = 0;
|
||||||
|
if(strlen(cur) + 2 > PATH_MAX - strlen(tmp))
|
||||||
|
return(NULL);
|
||||||
strcat(tmp, "/");
|
strcat(tmp, "/");
|
||||||
strcat(tmp, cur);
|
strcat(tmp, cur);
|
||||||
} else
|
} else
|
||||||
|
|
@ -357,6 +359,7 @@ struct dir *showCalc(char *path) {
|
||||||
*lasterr = '\0';
|
*lasterr = '\0';
|
||||||
anpos = 0;
|
anpos = 0;
|
||||||
lastupdate = 999;
|
lastupdate = 999;
|
||||||
|
memset(tmp, 0, PATH_MAX);
|
||||||
|
|
||||||
/* init parent dir */
|
/* init parent dir */
|
||||||
if(rpath(path, tmp) == NULL || lstat(tmp, &fs) != 0 || !S_ISDIR(fs.st_mode)) {
|
if(rpath(path, tmp) == NULL || lstat(tmp, &fs) != 0 || !S_ISDIR(fs.st_mode)) {
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,10 @@ void parseCli(int argc, char **argv) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
strcpy(sdir, argv[i]);
|
sdir[PATH_MAX - 1] = 0;
|
||||||
|
strncpy(sdir, argv[i], PATH_MAX);
|
||||||
|
if(sdir[PATH_MAX - 1] != 0)
|
||||||
|
sdir[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(s_export && !sdir[0]) {
|
if(s_export && !sdir[0]) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue