Skip to content

Commit 2507db6

Browse files
authored
zdb_il: use flex array member to access ZIL records
In 6f50f8e we added flex arrays to lr_XX_t structs to silence kernel bounds check warnings. Userspace code was mostly not updated to use them though. It seems that in the right circumstances, compilers can get confused about sizes in the same way, and throw warnings. This commits switch those uses over to use the flex array fields also. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Rob Norris <[email protected]> Sponsored-by: https://despairlabs.com/sponsor/ Closes openzfs#16832
1 parent a01504b commit 2507db6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

cmd/zdb/zdb_il.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ zil_prt_rec_create(zilog_t *zilog, int txtype, const void *arg)
6767
const lr_create_t *lrc = arg;
6868
const _lr_create_t *lr = &lrc->lr_create;
6969
time_t crtime = lr->lr_crtime[0];
70-
char *name, *link;
70+
const char *name, *link;
7171
lr_attr_t *lrattr;
7272

73-
name = (char *)(lr + 1);
73+
name = (const char *)&lrc->lr_data[0];
7474

7575
if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
7676
lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
77-
lrattr = (lr_attr_t *)(lr + 1);
77+
lrattr = (lr_attr_t *)&lrc->lr_data[0];
7878
name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
7979
}
8080

8181
if (txtype == TX_SYMLINK) {
82-
link = name + strlen(name) + 1;
82+
link = (const char *)&lrc->lr_data[strlen(name) + 1];
8383
(void) printf("%s%s -> %s\n", tab_prefix, name, link);
8484
} else if (txtype != TX_MKXATTR) {
8585
(void) printf("%s%s\n", tab_prefix, name);
@@ -104,7 +104,7 @@ zil_prt_rec_remove(zilog_t *zilog, int txtype, const void *arg)
104104
const lr_remove_t *lr = arg;
105105

106106
(void) printf("%sdoid %llu, name %s\n", tab_prefix,
107-
(u_longlong_t)lr->lr_doid, (char *)(lr + 1));
107+
(u_longlong_t)lr->lr_doid, (const char *)&lr->lr_data[0]);
108108
}
109109

110110
static void
@@ -115,7 +115,7 @@ zil_prt_rec_link(zilog_t *zilog, int txtype, const void *arg)
115115

116116
(void) printf("%sdoid %llu, link_obj %llu, name %s\n", tab_prefix,
117117
(u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
118-
(char *)(lr + 1));
118+
(const char *)&lr->lr_data[0]);
119119
}
120120

121121
static void
@@ -124,8 +124,8 @@ zil_prt_rec_rename(zilog_t *zilog, int txtype, const void *arg)
124124
(void) zilog, (void) txtype;
125125
const lr_rename_t *lrr = arg;
126126
const _lr_rename_t *lr = &lrr->lr_rename;
127-
char *snm = (char *)(lr + 1);
128-
char *tnm = snm + strlen(snm) + 1;
127+
const char *snm = (const char *)&lrr->lr_data[0];
128+
const char *tnm = (const char *)&lrr->lr_data[strlen(snm) + 1];
129129

130130
(void) printf("%ssdoid %llu, tdoid %llu\n", tab_prefix,
131131
(u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
@@ -211,7 +211,7 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, const void *arg)
211211

212212
/* data is stored after the end of the lr_write record */
213213
data = abd_alloc(lr->lr_length, B_FALSE);
214-
abd_copy_from_buf(data, lr + 1, lr->lr_length);
214+
abd_copy_from_buf(data, &lr->lr_data[0], lr->lr_length);
215215
}
216216

217217
(void) printf("%s", tab_prefix);
@@ -309,7 +309,7 @@ zil_prt_rec_setsaxattr(zilog_t *zilog, int txtype, const void *arg)
309309
(void) zilog, (void) txtype;
310310
const lr_setsaxattr_t *lr = arg;
311311

312-
char *name = (char *)(lr + 1);
312+
const char *name = (const char *)&lr->lr_data[0];
313313
(void) printf("%sfoid %llu\n", tab_prefix,
314314
(u_longlong_t)lr->lr_foid);
315315

@@ -318,7 +318,7 @@ zil_prt_rec_setsaxattr(zilog_t *zilog, int txtype, const void *arg)
318318
(void) printf("%sXAT_VALUE NULL\n", tab_prefix);
319319
} else {
320320
(void) printf("%sXAT_VALUE ", tab_prefix);
321-
char *val = name + (strlen(name) + 1);
321+
const char *val = (const char *)&lr->lr_data[strlen(name) + 1];
322322
for (int i = 0; i < lr->lr_size; i++) {
323323
(void) printf("%c", *val);
324324
val++;

0 commit comments

Comments
 (0)