linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Xiuhong Wang <xiuhong.wang@unisoc.com>
To: <jaegeuk@kernel.org>, <chao@kernel.org>,
	<linux-f2fs-devel@lists.sourceforge.net>,
	<linux-kernel@vger.kernel.org>
Cc: ke.wang@unisoc.com, xiuhong.wang.cn@gmail.com
Subject: [f2fs-dev] [PATCH 1/1] f2fs-tools: use atoll replace atoi to avoid data truncate
Date: Wed, 12 Jun 2024 15:17:49 +0800	[thread overview]
Message-ID: <20240612071749.348843-1-xiuhong.wang@unisoc.com> (raw)

If input exceeds int range, data will be truncated, such as lseek:
unisoc:/data # ./f2fs_io lseek set 3221225000 file
returned offset=2147483647
The offset is truncated.

After patch:
unisoc:/data # ./f2fs_io lseek set 3221225000 file
returned offset=3221225000

Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com>
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
---
 tools/f2fs_io/f2fs_io.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index a7b593a..8c9d433 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -539,7 +539,7 @@ static void do_fallocate(int argc, char **argv, const struct cmd_desc *cmd)
 	if (!strcmp(argv[0], "1"))
 		mode |= FALLOC_FL_KEEP_SIZE;
 
-	offset = atoi(argv[1]);
+	offset = atoll(argv[1]);
 	length = atoll(argv[2]);
 
 	fd = xopen(argv[3], O_RDWR, 0);
@@ -957,7 +957,7 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
 
 #define fiemap_desc "get block address in file"
 #define fiemap_help					\
-"f2fs_io fiemap [offset in 4kb] [count] [file_path]\n\n"\
+"f2fs_io fiemap [offset in 4kb] [count in 4kb] [file_path]\n\n"\
 
 #if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
 static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
@@ -1546,9 +1546,9 @@ static void do_move_range(int argc, char **argv, const struct cmd_desc *cmd)
 
 	fd = xopen(argv[1], O_RDWR, 0);
 	range.dst_fd = xopen(argv[2], O_RDWR | O_CREAT, 0644);
-	range.pos_in = atoi(argv[3]);
-	range.pos_out = atoi(argv[4]);
-	range.len = atoi(argv[5]);
+	range.pos_in = atoll(argv[3]);
+	range.pos_out = atoll(argv[4]);
+	range.len = atoll(argv[5]);
 
 	ret = ioctl(fd, F2FS_IOC_MOVE_RANGE, &range);
 	if (ret < 0)
@@ -1726,7 +1726,7 @@ static void do_lseek(int argc, char **argv, const struct cmd_desc *cmd)
 		exit(1);
 	}
 
-	offset = atoi(argv[2]);
+	offset = atoll(argv[2]);
 
 	if (!strcmp(argv[1], "set"))
 		whence = SEEK_SET;
@@ -1746,7 +1746,7 @@ static void do_lseek(int argc, char **argv, const struct cmd_desc *cmd)
 	ret = lseek(fd, offset, whence);
 	if (ret < 0)
 		die_errno("lseek failed");
-	printf("returned offset=%ld\n", ret);
+	printf("returned offset=%lld\n", (long long)ret);
 	exit(0);
 }
 
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

             reply	other threads:[~2024-06-12  7:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12  7:17 Xiuhong Wang [this message]
2024-06-18  1:05 ` [f2fs-dev] [PATCH 1/1] f2fs-tools: use atoll replace atoi to avoid data truncate Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240612071749.348843-1-xiuhong.wang@unisoc.com \
    --to=xiuhong.wang@unisoc.com \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=ke.wang@unisoc.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiuhong.wang.cn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).