public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH mtd-utils 0/2] mtd-utils: fsck.ubifs: fixes several undefined behaviors
@ 2025-11-13  8:29 Yuta Hayama
  2025-11-13  8:31 ` [PATCH mtd-utils 1/2] fsck.ubifs: don't use pointers that reference out-of-scope variables Yuta Hayama
  2025-11-13  8:32 ` [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t Yuta Hayama
  0 siblings, 2 replies; 7+ messages in thread
From: Yuta Hayama @ 2025-11-13  8:29 UTC (permalink / raw)
  To: linux-mtd; +Cc: Yuta Hayama

The first patch fixes the use of pointers to out-of-scope local variables.
The second patch fixes an issue where printf reads variables from the wrong
address due to an incorrect printf format length specifier. Note that the
former issue was detected by the cppcheck tool.

  $ cppcheck fsck.ubifs/
  Checking fsck.ubifs/check_files.c ...
  fsck.ubifs/check_files.c:104:48: error: Using pointer to local variable 'ino_node' that is out of scope. [invalidLifetime]
     inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
                                                 ^
  fsck.ubifs/check_files.c:71:31: note: Address of variable taken here.
    sn = (struct scanned_node *)&ino_node;
                                ^
  fsck.ubifs/check_files.c:64:27: note: Variable created here.
    struct scanned_ino_node ino_node;
                            ^
  fsck.ubifs/check_files.c:104:48: note: Using pointer to local variable 'ino_node' that is out of scope.
     inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
                                                 ^
  fsck.ubifs/check_files.c:104:48: error: Using pointer to local variable 'dent_node' that is out of scope. [invalidLifetime]
     inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
                                                 ^
  fsck.ubifs/check_files.c:84:31: note: Address of variable taken here.
    sn = (struct scanned_node *)&dent_node;
                                ^
  fsck.ubifs/check_files.c:77:28: note: Variable created here.
    struct scanned_dent_node dent_node;
                             ^
  fsck.ubifs/check_files.c:104:48: note: Using pointer to local variable 'dent_node' that is out of scope.
     inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
                                                 ^
  fsck.ubifs/check_files.c:104:48: error: Using pointer to local variable 'data_node' that is out of scope. [invalidLifetime]
     inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
                                                 ^
  fsck.ubifs/check_files.c:96:31: note: Address of variable taken here.
    sn = (struct scanned_node *)&data_node;
                                ^
  fsck.ubifs/check_files.c:89:28: note: Variable created here.
    struct scanned_data_node data_node;
                             ^
  fsck.ubifs/check_files.c:104:48: note: Using pointer to local variable 'data_node' that is out of scope.
     inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
                                                 ^
  fsck.ubifs/check_files.c:106:40: error: Using pointer to local variable 'ino_node' that is out of scope. [invalidLifetime]
   return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
                                         ^
  fsck.ubifs/check_files.c:71:31: note: Address of variable taken here.
    sn = (struct scanned_node *)&ino_node;
                                ^
  fsck.ubifs/check_files.c:64:27: note: Variable created here.
    struct scanned_ino_node ino_node;
                            ^
  fsck.ubifs/check_files.c:106:40: note: Using pointer to local variable 'ino_node' that is out of scope.
   return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
                                         ^
  fsck.ubifs/check_files.c:106:40: error: Using pointer to local variable 'dent_node' that is out of scope. [invalidLifetime]
   return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
                                         ^
  fsck.ubifs/check_files.c:84:31: note: Address of variable taken here.
    sn = (struct scanned_node *)&dent_node;
                                ^
  fsck.ubifs/check_files.c:77:28: note: Variable created here.
    struct scanned_dent_node dent_node;
                             ^
  fsck.ubifs/check_files.c:106:40: note: Using pointer to local variable 'dent_node' that is out of scope.
   return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
                                         ^
  fsck.ubifs/check_files.c:106:40: error: Using pointer to local variable 'data_node' that is out of scope. [invalidLifetime]
   return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
                                         ^
  fsck.ubifs/check_files.c:96:31: note: Address of variable taken here.
    sn = (struct scanned_node *)&data_node;
                                ^
  fsck.ubifs/check_files.c:89:28: note: Variable created here.
    struct scanned_data_node data_node;
                             ^
  fsck.ubifs/check_files.c:106:40: note: Using pointer to local variable 'data_node' that is out of scope.
   return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
                                         ^

Yuta Hayama (2):
  fsck.ubifs: don't use pointers that reference out-of-scope variables
  fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t

 ubifs-utils/fsck.ubifs/check_files.c         |  20 +--
 ubifs-utils/fsck.ubifs/extract_files.c       | 179 ++++++++++---------
 ubifs-utils/fsck.ubifs/handle_disconnected.c |  10 +-
 ubifs-utils/fsck.ubifs/problem.c             |  36 ++--
 ubifs-utils/fsck.ubifs/rebuild_fs.c          |   8 +-
 ubifs-utils/libubifs/dir.c                   |   8 +-
 6 files changed, 130 insertions(+), 131 deletions(-)

-- 
2.43.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-02-14  1:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-13  8:29 [PATCH mtd-utils 0/2] mtd-utils: fsck.ubifs: fixes several undefined behaviors Yuta Hayama
2025-11-13  8:31 ` [PATCH mtd-utils 1/2] fsck.ubifs: don't use pointers that reference out-of-scope variables Yuta Hayama
2025-11-14  3:15   ` Zhihao Cheng
2025-11-13  8:32 ` [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t Yuta Hayama
2025-11-14  8:54   ` Zhihao Cheng
2026-02-13 13:55   ` [mtd-utils,v2,2/2] fsck.ubifs: fix platform dependant ino_t and loff_t formatting Tomas Alvarez Vanoli
2026-02-14  1:33     ` Zhihao Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox