Skip to content

Commit

Permalink
f2fs-tools: use atoll replace atoi to avoid data truncate
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Zhiguo Niu <[email protected]>
Reviewed-by: Chao Yu <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
  • Loading branch information
wangxiuhong134 authored and Jaegeuk Kim committed Jun 24, 2024
1 parent b5ec029 commit 584ebc7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tools/f2fs_io/f2fs_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -964,7 +964,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)
Expand Down Expand Up @@ -1553,9 +1553,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)
Expand Down Expand Up @@ -1733,7 +1733,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;
Expand All @@ -1753,7 +1753,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);
}

Expand Down

0 comments on commit 584ebc7

Please sign in to comment.