From 5c468432f64d4b4dc81690c63d7030e2a1eb9363 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 16 May 2015 16:44:26 +0100 Subject: [PATCH] df: fix multiple bugs - sizeof(number) is not number but 1 or 2 - check strtok return rather than trying to play with NULL Not clear with is the root cause of the trs80 df crash but at least it works now --- Applications/util/df.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Applications/util/df.c b/Applications/util/df.c index 074b6050..b2830af4 100644 --- a/Applications/util/df.c +++ b/Applications/util/df.c @@ -125,13 +125,14 @@ void df_all(void) f = fopen("/etc/mtab", "r"); if (f) { - while (fgets(tmp, sizeof(MTAB_LINE), f)) { - dev = strtok(tmp, " "); - mntpt = strtok(NULL, " "); - df_path(mntpt); + while (fgets(tmp, MTAB_LINE, f)) { + dev = strtok(tmp, " "); + mntpt = strtok(NULL, " "); + if (mntpt) + df_path(mntpt); } fclose(f); - }else{ + } else { fprintf(stderr, "df: cannot open /etc/mtab: %s\n", strerror(errno)); } } @@ -156,9 +157,11 @@ const char *devname(dev_t devno) continue; if (fstat.st_rdev != devno) continue; + closedir(dp); return namebuf; } } + closedir(dp); sprintf(namebuf, "%d", devno); return namebuf; -- 2.34.1