summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2023-01-29 10:42:31 +0800
committerZorro Lang <zlang@kernel.org>2023-02-04 02:06:30 +0800
commit8d8d05a8e222658931310f55dfbe65edd8e80932 (patch)
tree261e24188de58f320a5e30b1eb658c973073285d /src
parent7fa8a9a25bd1415c67e7bf0ed6c02727ba94fc40 (diff)
fstests: fstest.c, fix compile warnings replace sprintf with snprintf
Fixes the buffer overflow warnings, by using snprintf instead of sprintf. fstest.c:95:20: warning: '/file' directive writing 5 bytes into a region of size between 1 and 1024 [-Wformat-overflow=] sprintf(fname, "%s/file%d", dir, fnum); ^~~~~ fstest.c:166:20: warning: '/file' directive writing 5 bytes into a region of size between 1 and 1024 [-Wformat-overflow=] sprintf(fname, "%s/file%d", dir, fnum); Signed-off-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: Bill O'Donnell <bodonnel@redhat.com> Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'src')
-rw-r--r--src/fstest.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/fstest.c b/src/fstest.c
index e4b9e081..4f6dc643 100644
--- a/src/fstest.c
+++ b/src/fstest.c
@@ -88,11 +88,16 @@ static void check_buffer(uchar *buf, int loop, int child, int fnum, int ofs)
static void create_file(const char *dir, int loop, int child, int fnum)
{
char *buf;
- int size, fd;
+ int size, fd, ret;
char fname[1024];
buf = x_malloc(block_size);
- sprintf(fname, "%s/file%d", dir, fnum);
+ ret = snprintf(fname, sizeof(fname), "%s/file%d", dir, fnum);
+ if (ret < 0 || ret >= sizeof(fname)) {
+ fprintf(stderr,"file path '%s' too long %d\n", dir, ret);
+ exit(1);
+ }
+
fd = open(fname, O_RDWR|O_CREAT|O_TRUNC | (use_sync?O_SYNC:0), 0644);
if (fd == -1) {
perror(fname);
@@ -158,12 +163,16 @@ bozo!
static void check_file(const char *dir, int loop, int child, int fnum)
{
uchar *buf;
- int size, fd;
+ int size, fd, ret;
char fname[1024];
buf = x_malloc(block_size);
- sprintf(fname, "%s/file%d", dir, fnum);
+ ret = snprintf(fname, sizeof(fname), "%s/file%d", dir, fnum);
+ if (ret < 0 || ret >= sizeof(fname)) {
+ fprintf(stderr,"file path is '%s' too long %d\n", dir, ret);
+ exit(1);
+ }
fd = open(fname, O_RDONLY);
if (fd == -1) {
perror(fname);