xbps-create: fix formatting, set return value on path overflow
This commit is contained in:
parent
3ef932de2f
commit
c992049eb5
@ -493,18 +493,20 @@ out:
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
walk_dir(const char *path,
|
walk_dir(const char *path,
|
||||||
int (*fn) (const char *, const struct stat *sb, const struct dirent *dir)) {
|
int (*fn) (const char *, const struct stat *sb, const struct dirent *dir))
|
||||||
|
{
|
||||||
int rv, i;
|
int rv, i;
|
||||||
struct dirent **list;
|
struct dirent **list;
|
||||||
char tmp_path[PATH_MAX] = { 0 };
|
char tmp_path[PATH_MAX] = { 0 };
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
rv = scandir(path, &list, NULL, alphasort);
|
rv = scandir(path, &list, NULL, alphasort);
|
||||||
for(i = rv - 1; i >= 0; i--) {
|
for (i = rv - 1; i >= 0; i--) {
|
||||||
if(strcmp(list[i]->d_name, ".") == 0 || strcmp(list[i]->d_name, "..") == 0)
|
if (strcmp(list[i]->d_name, ".") == 0 || strcmp(list[i]->d_name, "..") == 0)
|
||||||
continue;
|
continue;
|
||||||
if (strlen(path) + strlen(list[i]->d_name) + 1 >= PATH_MAX - 1) {
|
if (strlen(path) + strlen(list[i]->d_name) + 1 >= PATH_MAX - 1) {
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
|
rv = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strncpy(tmp_path, path, PATH_MAX - 1);
|
strncpy(tmp_path, path, PATH_MAX - 1);
|
||||||
@ -515,7 +517,7 @@ walk_dir(const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
if(walk_dir(tmp_path, fn) < 0) {
|
if (walk_dir(tmp_path, fn) < 0) {
|
||||||
rv = -1;
|
rv = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user