f2fs_io: Fix integer multiplication overflow error in fiemap
PATCH 1/1 f2fs_io: Fix integer multiplication overflow error in fiemap
When using fiemap to obtain the block address of files larger than 2GB ((2147483647+1) bytes), an integer multiplication overflow error will occur. This issue is caused by the following code:
start = atoi(argv[1]) * F2FS_BLKSIZE;
length = atoi(argv[2]) * F2FS_BLKSIZE;--- tools/f2fs_io/f2fs_io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/f2fs_io/f2fs_io.c +5 -5
@@ -809,15 +809,15 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) }memset (fm,0 ,sizeof (struct fiemap )); - start =atoi (argv[1 ]) *F2FS_BLKSIZE ; - length =atoi (argv[2 ]) *F2FS_BLKSIZE ; - fm->fm_start = start; - fm->fm_length = length; + start =atoll (argv[1 ]); + length =atoll (argv[2 ]); + fm->fm_start = start *F2FS_BLKSIZE ; + fm->fm_length = length *F2FS_BLKSIZE ; fd =xopen (argv[3 ],O_RDONLY |O_LARGEFILE ,0 );printf ("Fiemap: offset = %" PRIu64" len = %" PRIu64"\n" , - start /F2FS_BLKSIZE , length /F2FS_BLKSIZE ); + start, length);if (ioctl (fd,FS_IOC_FIEMAP , fm) <0 )die_errno ("FIEMAP failed" );
--
2.40.1
#/******���ʼ����丽������С��˾�ı�����Ϣ�������ڷ��������ַ���г��ĸ��˻�Ⱥ�顣��ֹ�κ����������κ���ʽʹ�ã�������������ȫ���ֵ�й¶�����ơ���ɢ�������ʼ��е���Ϣ������������˱��ʼ������������绰���ʼ�֪ͨ�����˲�ɾ�����ʼ��� This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 17 lines · On 2023/5/23 15:24, zangyangyang1 wrote:
When using fiemap to obtain the block address of files larger than 2GB ((2147483647+1) bytes), an integer multiplication overflow error will occur. This issue is caused by the following code:
start = atoi(argv[1]) * F2FS_BLKSIZE; length = atoi(argv[2]) * F2FS_BLKSIZE;Signed-off-by zangyangyang1 <[email protected]>--- tools/f2fs_io/f2fs_io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)tools/f2fs_io/f2fs_io.c +0
-0
tools/f2fs_io/f2fs_io.c static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) · line 813
Quoted 5 lines
tools/f2fs_io/f2fs_io.c +0
-2@@ -809,15 +809,15 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) }memset (fm,0 ,sizeof (struct fiemap )); - start =atoi (argv[1 ]) *F2FS_BLKSIZE ; - length =atoi (argv[2 ]) *F2FS_BLKSIZE ;
How about?
start = (long long)atoi(argv[1]) * F2FS_BLKSIZE;
length = (long long)atoi(argv[2]) * F2FS_BLKSIZE;
Thanks,
Quoted 18 lines
tools/f2fs_io/f2fs_io.c +5
-4- fm->fm_start = start; - fm->fm_length = length; + start =atoll (argv[1 ]); + length =atoll (argv[2 ]); + fm->fm_start = start *F2FS_BLKSIZE ; + fm->fm_length = length *F2FS_BLKSIZE ; fd =xopen (argv[3 ],O_RDONLY |O_LARGEFILE ,0 );printf ("Fiemap: offset = %" PRIu64" len = %" PRIu64"\n" , - start /F2FS_BLKSIZE , length /F2FS_BLKSIZE ); + start, length);if (ioctl (fd,FS_IOC_FIEMAP , fm) <0 )die_errno ("FIEMAP failed" ); --2.40.1
Quoted 1 line
#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v2 1/1 f2fs_io: Fix integer multiplication overflow error in fiemap
When using fiemap to obtain the block address of files larger than 2GB ((2147483647+1) bytes), an integer multiplication overflow error will occur. This issue is caused by the following code:
start = atoi(argv[1]) * F2FS_BLKSIZE;
length = atoi(argv[2]) * F2FS_BLKSIZE;---
Changes since v1:
- Use type casting
--- tools/f2fs_io/f2fs_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/f2fs_io/f2fs_io.c +2 -2
@@ -809,8 +809,8 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd) }memset (fm,0 ,sizeof (struct fiemap )); - start =atoi (argv[1 ]) *F2FS_BLKSIZE ; - length =atoi (argv[2 ]) *F2FS_BLKSIZE ; + start = (u64 )atoi (argv[1 ]) *F2FS_BLKSIZE ; + length = (u64 )atoi (argv[2 ]) *F2FS_BLKSIZE ; fm->fm_start = start; fm->fm_length = length;
--
2.40.1
#/******���ʼ����丽������С��˾�ı�����Ϣ�������ڷ��������ַ���г��ĸ��˻�Ⱥ�顣��ֹ�κ����������κ���ʽʹ�ã�������������ȫ���ֵ�й¶�����ơ���ɢ�������ʼ��е���Ϣ������������˱��ʼ������������绰���ʼ�֪ͨ�����˲�ɾ�����ʼ��� This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 8 lines · On 2023/5/23 20:27, zangyangyang1 wrote:
When using fiemap to obtain the block address of files larger than 2GB ((2147483647+1) bytes), an integer multiplication overflow error will occur. This issue is caused by the following code:
start = atoi(argv[1]) * F2FS_BLKSIZE; length = atoi(argv[2]) * F2FS_BLKSIZE;Signed-off-by zangyangyang1 <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v2 1/1 libf2fs: Fix using uninitialized variables error in get_device_info()
In reply to zangyangyang1 via Linux-f2fs-develThis issue comes from a static code scanning tool.
When c.sparse_mode is 1, stat_buf will not be initialized, but it will be used next.
If this issue does not require modification, please ignore this commit.
---
Changes since v1:
- Use calloc() instead of malloc()
--- lib/libf2fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/libf2fs.c +1 -1
@@ -931,7 +931,7 @@ int get_device_info(int i) } } - stat_buf =malloc (sizeof (struct stat )); + stat_buf =calloc (1 ,sizeof (struct stat ));ASSERT (stat_buf);if (!c.sparse_mode) {
--
2.40.1
#/******���ʼ����丽������С��˾�ı�����Ϣ�������ڷ��������ַ���г��ĸ��˻�Ⱥ�顣��ֹ�κ����������κ���ʽʹ�ã�������������ȫ���ֵ�й¶�����ơ���ɢ�������ʼ��е���Ϣ������������˱��ʼ������������绰���ʼ�֪ͨ�����˲�ɾ�����ʼ��� This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH V2] libf2fs: Fix using uninitialized variables error in get_device_info()
I'm very sorry for replying to the wrong email. Please ignore this email and the previous patch email. Thanks,
zangyangyang
#/******���ʼ����丽������С��˾�ı�����Ϣ�������ڷ��������ַ���г��ĸ��˻�Ⱥ�顣��ֹ�κ����������κ���ʽʹ�ã�������������ȫ���ֵ�й¶�����ơ���ɢ�������ʼ��е���Ϣ������������˱��ʼ������������绰���ʼ�֪ͨ�����˲�ɾ�����ʼ��� This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel