dosfstools/0004-Fix-gcc-sprintf-length-warnings.patch
2020-07-01 15:15:47 +08:00

62 lines
2.1 KiB
Diff

From fb0cc0df4ce3d349796ce4960c4e32d16532b203 Mon Sep 17 00:00:00 2001
From: Andreas Bombe <aeb@debian.org>
Date: Tue, 14 Aug 2018 12:58:58 +0200
Subject: [PATCH 71/86] Fix gcc sprintf() length warnings
There are two sprintf() calls that receive warnings from current
versions of gcc for possibly overrunning the temporary buffers they're
writing into.
The first one in src/check.c is theoretically safe since strftime()
shouldn't generate such a long string. Reduce the maximum length of the
strftime() string to fix this warning. Also detect strftime() errors
and overwrite the buffer with a message in that case.
The second one in src/boot.c should not be possible and is a limitation
of gcc's detection. It assumes that %02x could write up to 8
characters, even though the arguments are pointers to uint8_t which
can't be more than two characters. Placate gcc by lengthening the
temporary buffer by 12 bytes.
---
src/boot.c | 2 +-
src/check.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/boot.c b/src/boot.c
index 947703c..bedd45a 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -297,7 +297,7 @@ static void check_backup_boot(DOS_FS * fs, struct boot_sector *b, unsigned int l
/* there are any differences */
uint8_t *p, *q;
int i, pos, first = 1;
- char buf[20];
+ char buf[32];
printf("There are differences between boot sector and its backup.\n");
printf("This is mostly harmless. Differences: (offset:original/backup)\n ");
diff --git a/src/check.c b/src/check.c
index 76c9c3d..13a5fd6 100644
--- a/src/check.c
+++ b/src/check.c
@@ -137,13 +137,14 @@ static char *file_stat(DOS_FILE * file)
{
static char temp[100];
struct tm *tm;
- char tmp[100];
+ char tmp[40];
time_t date;
date =
date_dos2unix(le16toh(file->dir_ent.time), le16toh(file->dir_ent.date));
tm = localtime(&date);
- strftime(tmp, 99, "%H:%M:%S %b %d %Y", tm);
+ if (!strftime(tmp, 40, "%H:%M:%S %b %d %Y", tm))
+ strcpy(tmp, "<internal format error>");
sprintf(temp, " Size %u bytes, date %s", le32toh(file->dir_ent.size), tmp);
return temp;
}
--
1.8.3.1