Fix real bugs and clean up the build with -Wall -Wextra
Build: add --enable-warnings (-Wall -Wextra); the tree is now warning-free with it, so distributions can opt in without risking a surprise -Werror breakage from a future compiler. Real bugs fixed (each verified by a reproducer): - lib/io.c: open_rollback_file() read 28 bytes into char[28] with no NUL and then strcmp()'d it against a 28-character magic, reading one byte past the array. The condition was also inverted, so a *valid* rollback file was rejected -- but only sometimes: the missing NUL made the result depend on stack garbage (verified: -O0 rejects, -O2 accepts). The whole --save-rollback/--rollback-changes path was unreliable. Now the buffer is sized for the terminator, zeroed, and the comparison is `!= 0`. Verified end to end: save -> reopen -> restore reports "2 blocks restored, 0 skipped"; a random file is rejected. - reiserfscore/reiserfslib.c, reiserfscore/journal.c: asprintf() was called with &fs->fs_file_name / &fs->fs_j_file_name, but those fields are `char *`, not `char **`. Passing a `char **` where `char *` is expected wrote through the wrong pointer -- silent memory corruption on any allocation. Fixed by using the new checked helper. - reiserfscore/node_formats.c: `code < 0` on an unsigned parameter was dead code; the guard never fired. - resize_reiserfs: missing `break` after -j made -j fall into -f, so "-j dev" silently also forced the operation. Sign-compare on the count_blocks() ternary and on count + blocks. - lib/misc.c: strncat with bound == strlen(src) (equivalent to strcat) into char[256] from a char[256] dirent name -- up to 261 bytes. Replaced with snprintf plus an explicit fit check. - lib/misc.c: die() used vsprintf into a fixed 1024-byte buffer. - strncpy with bound == destination size (mkreiserfs, tune, progbar) never terminated; replaced with snprintf. Allocator: drop the homegrown magic-header allocator. It wrote "_mem_begin_" / "mem_end" through strcpy inside the allocation, kept the size in an `int`, and its only safety check (checkmem) was never called -- every call site is commented out. Replaced with a size_t header that is over-aligned via max_align_t, so malloc alignment guarantees still hold. expandmem() now takes the old size from the header instead of a caller-supplied value that could disagree with it. Warnings: annotate the deliberate fallthroughs (fsck pass cascade, unit suffix parsing, percentage parsing), fix the remaining sign-compare and missing-field-initializer sites, and compute addresses of packed members via char* + offsetof instead of &member. Portability: asm/types.h -> linux/types.h, malloc.h and sys/vfs.h dropped from includes.h (nothing used them), sys/vfs.h -> sys/statfs.h for statfs(2). Version: reiserfsprogs.spec said 3.6.23 while configure.ac said 3.6.25. Remove the dead `#if 0` main() from hashes.c. Add .github/workflows/build.yml: gcc, clang, --enable-warnings and --enable-io-failure-emulation, each followed by a format/check/inspect smoke test on a real image. Verified: ./autogen.sh && ./configure --enable-warnings && make is clean from scratch (0 warnings, 51 compile/link steps). mkreiserfs, reiserfsck --check, debugreiserfs -S, reiserfstune -l and a real resize_reiserfs 128M -> 256M all succeed, and fsck reports the resized image clean.
This commit is contained in:
1 parent
41fb30313e
commit
293e6a7280
28 files changed
+258
-190
No files matched your search
+14
-2
@@ -32,6 +32,7 @@
|
||||
#ifndef REISERFSPROGS_FS_H
|
||||
#define REISERFSPROGS_FS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <linux/types.h>
|
||||
#include "swab.h"
|
||||
|
||||
@@ -174,7 +175,12 @@ struct reiserfs_super_block_v1 {
|
||||
|
||||
#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1)) /* 76 bytes */
|
||||
|
||||
#define sb_jp(sb) (&((sb)->s_v1.sb_journal))
|
||||
/* &(sb)->s_v1.sb_journal would take the address of a member inside a
|
||||
packed struct, which is legal here (offset 12) but trips
|
||||
-Waddress-of-packed-member on every use. Spell it out instead. */
|
||||
#define sb_jp(sb) ((struct journal_params *) \
|
||||
((char *)(sb) + offsetof(struct reiserfs_super_block, s_v1) + \
|
||||
offsetof(struct reiserfs_super_block_v1, sb_journal)))
|
||||
|
||||
/* values for sb_version field of struct reiserfs_super_block. sb_version is
|
||||
only reliable on filesystem with non-standard journal */
|
||||
@@ -636,6 +642,12 @@ struct item_head {
|
||||
/* size of item header */
|
||||
#define IH_SIZE (sizeof(struct item_head))
|
||||
|
||||
/* Address of the packed ih_format field, computed without forming a pointer
|
||||
to a member of a packed struct (which trips -Waddress-of-packed-member).
|
||||
ih_format is naturally aligned, so dereferencing the result is fine. */
|
||||
#define ih_format_ptr(ih) \
|
||||
((__le16 *)((char *)(ih) + offsetof(struct item_head, ih_format)))
|
||||
|
||||
/* set/get fields of item head on disk with these defines */
|
||||
#define get_ih_entry_count(ih) get_le16 (ih, u.ih2_entry_count)
|
||||
#define set_ih_entry_count(ih,val) set_le16 (ih, u.ih2_entry_count, val)
|
||||
@@ -1061,7 +1073,7 @@ struct reiserfs_path {
|
||||
};
|
||||
|
||||
#define INITIALIZE_REISERFS_PATH(var) \
|
||||
struct reiserfs_path var = {ILLEGAL_PATH_ELEMENT_OFFSET, }
|
||||
struct reiserfs_path var = { .path_length = ILLEGAL_PATH_ELEMENT_OFFSET }
|
||||
|
||||
/* Get path element by path and path position. */
|
||||
#define PATH_OFFSET_PELEMENT(p_s_path,n_offset) ((p_s_path)->path_elements +(n_offset))
|
||||
|
||||
Reference in new issue
Block a user