commit 3ef662c988b01cb6be993f4cb0cd749a7e20105b
parent cc2d762798aa710b7e0cc916d6523ef5b7c92f2a
Author: sin <sin@2f30.org>
Date: Thu, 23 Jan 2014 20:05:01 +0000
Check snprintf() return value
Diffstat:
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/du.c b/du.c
@@ -137,11 +137,13 @@ du(const char *path)
m = nblks(&st);
n += m;
if (aflag && !sflag) {
- if (S_ISLNK(st.st_mode))
- snprintf(file, sizeof(file), "%s/%s",
- cwd, dent->d_name);
- else
+ if (S_ISLNK(st.st_mode)) {
+ if (snprintf(file, sizeof(file), "%s/%s",
+ cwd, dent->d_name) >= sizeof(file))
+ enprintf(EXIT_FAILURE, "path too long\n");
+ } else {
realpath(dent->d_name, file);
+ }
print(m, file);
}
}