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
@@ -1538,7 +1538,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure
|
||||
insert_ptr[0] = (struct buffer_head *)body;
|
||||
/* we must prepare insert_key */
|
||||
|
||||
if (PATH_H_B_ITEM_ORDER(tb->tb_path, 0) /*LAST_POSITION (tb->tb_path) */
|
||||
if ((int)PATH_H_B_ITEM_ORDER(tb->tb_path, 0) /*LAST_POSITION (tb->tb_path) */
|
||||
/*item_pos */ == -1) {
|
||||
/* get delimiting key from buffer in tree */
|
||||
copy_key(&insert_key[0].ih_key,
|
||||
|
||||
+1
-27
@@ -22,7 +22,7 @@
|
||||
// r5
|
||||
//
|
||||
|
||||
#include <asm/types.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
#define DELTA 0x9E3779B9
|
||||
#define FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */
|
||||
@@ -190,29 +190,3 @@ u32 r5_hash(const signed char *msg, int len)
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *name = 0;
|
||||
size_t n = 0;
|
||||
|
||||
while (1) {
|
||||
getline(&name, &n, stdin);
|
||||
if (!strcmp(name, "\n"))
|
||||
break;
|
||||
name[strlen(name) - 1] = 0;
|
||||
printf("tea %lu\n, r5 %lu\nyura %lu\n",
|
||||
keyed_hash(name, strlen(name)) & 0x7fffff80,
|
||||
r5_hash(name, strlen(name)) & 0x7fffff80,
|
||||
yura_hash(name, strlen(name)) & 0x7fffff80);
|
||||
free(name);
|
||||
name = 0;
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -15,8 +15,6 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <asm/types.h>
|
||||
#include <linux/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <time.h>
|
||||
@@ -506,7 +506,7 @@ int reiserfs_open_journal(reiserfs_filsys_t fs, const char *j_filename,
|
||||
if (fs->fs_journal_dev == -1)
|
||||
return -1;
|
||||
|
||||
asprintf(&fs->fs_j_file_name, "%s", j_filename);
|
||||
xasprintf(&fs->fs_j_file_name, "%s", j_filename);
|
||||
|
||||
if (get_jp_journal_size(sb_jp(sb)) < JOURNAL_MIN_SIZE) {
|
||||
reiserfs_warning(stderr, "Journal of (%lu) block size found on "
|
||||
@@ -694,7 +694,7 @@ int reiserfs_create_journal(reiserfs_filsys_t fs, const char *j_device, /* journ
|
||||
return 0;
|
||||
}
|
||||
|
||||
asprintf(&fs->fs_j_file_name, "%s", j_device);
|
||||
xasprintf(&fs->fs_j_file_name, "%s", j_device);
|
||||
|
||||
if (len < JOURNAL_MIN_SIZE + 1) {
|
||||
reiserfs_warning(stderr,
|
||||
|
||||
@@ -610,7 +610,7 @@ int find_hash_in_use(const char *name, int namelen, __u32 offset,
|
||||
|
||||
char *code2name(unsigned int code)
|
||||
{
|
||||
if (code >= HASH_AMOUNT || code < 0)
|
||||
if (code >= HASH_AMOUNT)
|
||||
return NULL;
|
||||
return hashes[code].name;
|
||||
}
|
||||
@@ -1031,22 +1031,22 @@ int name_length(const char *name, int key_format)
|
||||
/* key format is stored in 12 bits starting from 0-th of item_head's ih2_format*/
|
||||
__u16 get_ih_key_format(const struct item_head * ih)
|
||||
{
|
||||
get_bit_field_XX(16, &ih->ih_format, 0, 12);
|
||||
get_bit_field_XX(16, ih_format_ptr(ih), 0, 12);
|
||||
}
|
||||
|
||||
__u16 get_ih_flags(const struct item_head *ih)
|
||||
{
|
||||
get_bit_field_XX(16, &ih->ih_format, 12, 4);
|
||||
get_bit_field_XX(16, ih_format_ptr(ih), 12, 4);
|
||||
}
|
||||
|
||||
void set_ih_key_format(struct item_head *ih, __u16 val)
|
||||
{
|
||||
set_bit_field_XX(16, &ih->ih_format, val, 0, 12);
|
||||
set_bit_field_XX(16, ih_format_ptr(ih), val, 0, 12);
|
||||
}
|
||||
|
||||
void set_ih_flags(struct item_head *ih, __u16 val)
|
||||
{
|
||||
set_bit_field_XX(16, &ih->ih_format, val, 12, 4);
|
||||
set_bit_field_XX(16, ih_format_ptr(ih), val, 12, 4);
|
||||
}
|
||||
|
||||
/* access to fields of stat data (both v1 and v2) */
|
||||
|
||||
@@ -82,7 +82,7 @@ reiserfs_filsys_t reiserfs_open(const char *filename, int flags,
|
||||
fs = getmem(sizeof(*fs));
|
||||
fs->fs_dev = fd;
|
||||
fs->fs_vp = vp;
|
||||
asprintf(&fs->fs_file_name, "%s", filename);
|
||||
xasprintf(&fs->fs_file_name, "%s", filename);
|
||||
|
||||
/* reiserfs super block is either in 16-th or in 2-nd 4k block of the
|
||||
device */
|
||||
@@ -215,7 +215,7 @@ reiserfs_filsys_t reiserfs_create(const char *filename,
|
||||
}
|
||||
|
||||
fs->fs_blocksize = block_size;
|
||||
asprintf(&fs->fs_file_name, "%s", filename);
|
||||
xasprintf(&fs->fs_file_name, "%s", filename);
|
||||
fs->fs_format = version;
|
||||
|
||||
if (new_format)
|
||||
@@ -664,7 +664,7 @@ struct reiserfs_key *uget_rkey(const struct reiserfs_path *path)
|
||||
|
||||
struct reiserfs_key *reiserfs_next_key(const struct reiserfs_path *path)
|
||||
{
|
||||
if (get_item_pos(path) < B_NR_ITEMS(get_bh(path)) - 1)
|
||||
if (get_item_pos(path) + 1 < B_NR_ITEMS(get_bh(path)))
|
||||
return leaf_key(get_bh(path), get_item_pos(path) + 1);
|
||||
|
||||
return uget_rkey(path);
|
||||
@@ -1054,7 +1054,7 @@ int reiserfs_add_entry(reiserfs_filsys_t fs, const struct reiserfs_key *dir,
|
||||
const char *name, int name_len,
|
||||
const struct reiserfs_key *key, __u16 fsck_need)
|
||||
{
|
||||
struct item_head entry_ih = { {0,}, };
|
||||
struct item_head entry_ih = { 0 };
|
||||
char *entry;
|
||||
int retval;
|
||||
INITIALIZE_REISERFS_PATH(path);
|
||||
@@ -1458,7 +1458,7 @@ void add_badblock_list(reiserfs_filsys_t fs, int replace)
|
||||
}
|
||||
|
||||
int reiserfs_iterate_file_data(reiserfs_filsys_t fs,
|
||||
const struct reiserfs_key const *short_key,
|
||||
const struct reiserfs_key *short_key,
|
||||
reiserfs_file_iterate_indirect_fn indirect_fn,
|
||||
reiserfs_file_iterate_direct_fn direct_fn,
|
||||
void *data)
|
||||
@@ -1555,7 +1555,7 @@ fail:
|
||||
}
|
||||
|
||||
int reiserfs_iterate_dir(reiserfs_filsys_t fs,
|
||||
const struct reiserfs_key const *dir_short_key,
|
||||
const struct reiserfs_key *dir_short_key,
|
||||
const reiserfs_iterate_dir_fn callback, void *data)
|
||||
{
|
||||
INITIALIZE_REISERFS_PATH(path);
|
||||
|
||||
Reference in new issue
Block a user