aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/lsattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'e2fsprogs/lsattr.c')
-rw-r--r--e2fsprogs/lsattr.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c
index be5723c43..d3896637d 100644
--- a/e2fsprogs/lsattr.c
+++ b/e2fsprogs/lsattr.c
@@ -101,29 +101,31 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
101{ 101{
102 STRUCT_STAT st; 102 STRUCT_STAT st;
103 char *path; 103 char *path;
104 int dir_len = strlen(dir_name); 104 int i = strlen(dir_name);
105 105
106 path = malloc(dir_len + strlen(de->d_name) + 2); 106 if (i && dir_name[i-1] == '/')
107 107 i = asprintf(&path, "%s%s", dir_name, de->d_name);
108 if (dir_len && dir_name[dir_len-1] == '/')
109 sprintf(path, "%s%s", dir_name, de->d_name);
110 else 108 else
111 sprintf(path, "%s/%s", dir_name, de->d_name); 109 i = asprintf(&path, "%s/%s", dir_name, de->d_name);
110 if (i == -1)
111 bb_perror_msg_and_die("asprintf failed");
112
112 if (LSTAT(path, &st) == -1) 113 if (LSTAT(path, &st) == -1)
113 bb_perror_msg(path); 114 bb_perror_msg(path);
114 else { 115 else {
115 if (de->d_name[0] != '.' || (flags & OPT_ALL)) { 116 if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
116 list_attributes(path); 117 list_attributes(path);
117 if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && 118 if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
118 strcmp(de->d_name, ".") && 119 strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
119 strcmp(de->d_name, "..")) {
120 printf("\n%s:\n", path); 120 printf("\n%s:\n", path);
121 iterate_on_dir(path, lsattr_dir_proc, NULL); 121 iterate_on_dir(path, lsattr_dir_proc, NULL);
122 printf("\n"); 122 printf("\n");
123 } 123 }
124 } 124 }
125 } 125 }
126
126 free(path); 127 free(path);
128
127 return 0; 129 return 0;
128} 130}
129 131