Skip to contentSkip to conversation

libf2fs: Fix using uninitialized variables error in get_device_info()

PATCH Superseded zangyangyang1 via Linux-f2fs-devel 2 participants 4 messages Nov 8, 2023 – Nov 10, 2023 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libf2fs: Fix using uninitialized variables error in get_device_info()

This 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.

---
 lib/libf2fs.c | 1 +
 1 file changed, 1 insertion(+)
lib/libf2fs.c +1 -0
index 995e42d..0398c52 100644
@@ -933,6 +933,7 @@ int get_device_info(int i)
 
        stat_buf = malloc(sizeof(struct stat));
        ASSERT(stat_buf);
+       memset(stat_buf, 0, sizeof(struct stat));
 
        if (!c.sparse_mode) {
                if (stat(dev->path, stat_buf) < 0 ) {

--
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

#1 lore raw
Quoted 15 lines · On 2023/11/8 20:38, zangyangyang1 wrote:

This 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.

---
  lib/libf2fs.c | 1 +
  1 file changed, 1 insertion(+)
lib/libf2fs.c +0 -0
index 995e42d..0398c52 100644

lib/libf2fs.c int get_device_info(int i) · line 934

Quoted 2 lines
lib/libf2fs.c +0 -0
@@ -933,6 +933,7 @@ int get_device_info(int i)
 
         stat_buf = malloc(sizeof(struct stat));

Use calloc() instead of malloc()?

Thanks,

Quoted 7 lines
lib/libf2fs.c +1 -1
         ASSERT(stat_buf);
+       memset(stat_buf, 0, sizeof(struct stat));
 
         if (!c.sparse_mode) {
                 if (stat(dev->path, stat_buf) < 0 ) {
--

2.40.1

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw

PATCH v2 1/1 libf2fs: Fix using uninitialized variables error in get_device_info()

This 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
index 995e42d..47d4e49 100644
@@ -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

Reviewed-by on v2 1/1
#3 lore raw
Quoted 6 lines · On 2023/11/9 23:47, zangyangyang1 wrote:

This 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.

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel