Skip to content

Commit 47c6624

Browse files
committed
treewide: Replace 0-element memcpy() destinations with flexible arrays
The 0-element arrays that are used as memcpy() destinations are actually flexible arrays. Adjust their structures accordingly so that memcpy() can better reason able their destination size (i.e. they need to be seen as "unknown" length rather than "zero"). In some cases, use of the DECLARE_FLEX_ARRAY() helper is needed when a flexible array is alone in a struct. Cc: "Gustavo A. R. Silva" <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Kalle Valo <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Nilesh Javali <[email protected]> Cc: Manish Rangankar <[email protected]> Cc: [email protected] Cc: "James E.J. Bottomley" <[email protected]> Cc: "Martin K. Petersen" <[email protected]> Cc: Larry Finger <[email protected]> Cc: Phillip Potter <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Florian Schilhabel <[email protected]> Cc: Johannes Berg <[email protected]> Cc: Christophe JAILLET <[email protected]> Cc: Fabio Aiuto <[email protected]> Cc: Ross Schmidt <[email protected]> Cc: Marco Cesati <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent fa7845c commit 47c6624

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

drivers/net/wireless/ath/ath10k/bmi.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct bmi_cmd {
109109
struct {
110110
__le32 addr;
111111
__le32 len;
112-
u8 payload[0];
112+
u8 payload[];
113113
} write_mem;
114114
struct {
115115
__le32 addr;
@@ -138,18 +138,18 @@ struct bmi_cmd {
138138
} rompatch_uninstall;
139139
struct {
140140
__le32 count;
141-
__le32 patch_ids[0]; /* length of @count */
141+
__le32 patch_ids[]; /* length of @count */
142142
} rompatch_activate;
143143
struct {
144144
__le32 count;
145-
__le32 patch_ids[0]; /* length of @count */
145+
__le32 patch_ids[]; /* length of @count */
146146
} rompatch_deactivate;
147147
struct {
148148
__le32 addr;
149149
} lz_start;
150150
struct {
151151
__le32 len; /* max BMI_MAX_DATA_SIZE */
152-
u8 payload[0]; /* length of @len */
152+
u8 payload[]; /* length of @len */
153153
} lz_data;
154154
struct {
155155
u8 name[BMI_NVRAM_SEG_NAME_SZ];
@@ -160,7 +160,7 @@ struct bmi_cmd {
160160

161161
union bmi_resp {
162162
struct {
163-
u8 payload[0];
163+
DECLARE_FLEX_ARRAY(u8, payload);
164164
} read_mem;
165165
struct {
166166
__le32 result;

drivers/scsi/qla4xxx/ql4_def.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ struct qla4_work_evt {
366366
struct {
367367
enum iscsi_host_event_code code;
368368
uint32_t data_size;
369-
uint8_t data[0];
369+
uint8_t data[];
370370
} aen;
371371
struct {
372372
uint32_t status;
373373
uint32_t pid;
374374
uint32_t data_size;
375-
uint8_t data[0];
375+
uint8_t data[];
376376
} ping;
377377
} u;
378378
};

drivers/staging/r8188eu/include/ieee80211.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ struct ieee_param {
185185
struct {
186186
u32 len;
187187
u8 reserved[32];
188-
u8 data[0];
188+
u8 data[];
189189
} wpa_ie;
190190
struct {
191191
int command;
@@ -198,7 +198,7 @@ struct ieee_param {
198198
u8 idx;
199199
u8 seq[8]; /* sequence counter (set: RX, get: TX) */
200200
u16 key_len;
201-
u8 key[0];
201+
u8 key[];
202202
} crypt;
203203
#ifdef CONFIG_88EU_AP_MODE
204204
struct {
@@ -210,7 +210,7 @@ struct ieee_param {
210210
} add_sta;
211211
struct {
212212
u8 reserved[2];/* for set max_num_sta */
213-
u8 buf[0];
213+
u8 buf[];
214214
} bcn_ie;
215215
#endif
216216

drivers/staging/rtl8712/ieee80211.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct ieee_param {
7878
struct {
7979
u32 len;
8080
u8 reserved[32];
81-
u8 data[0];
81+
u8 data[];
8282
} wpa_ie;
8383
struct {
8484
int command;
@@ -91,7 +91,7 @@ struct ieee_param {
9191
u8 idx;
9292
u8 seq[8]; /* sequence counter (set: RX, get: TX) */
9393
u16 key_len;
94-
u8 key[0];
94+
u8 key[];
9595
} crypt;
9696
} u;
9797
};

drivers/staging/rtl8723bs/include/ieee80211.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct ieee_param {
172172
struct {
173173
u32 len;
174174
u8 reserved[32];
175-
u8 data[0];
175+
u8 data[];
176176
} wpa_ie;
177177
struct{
178178
int command;
@@ -185,7 +185,7 @@ struct ieee_param {
185185
u8 idx;
186186
u8 seq[8]; /* sequence counter (set: RX, get: TX) */
187187
u16 key_len;
188-
u8 key[0];
188+
u8 key[];
189189
} crypt;
190190
struct {
191191
u16 aid;
@@ -196,7 +196,7 @@ struct ieee_param {
196196
} add_sta;
197197
struct {
198198
u8 reserved[2];/* for set max_num_sta */
199-
u8 buf[0];
199+
u8 buf[];
200200
} bcn_ie;
201201
} u;
202202
};

include/linux/ieee80211.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ struct ieee80211_mgmt {
11431143
__le16 auth_transaction;
11441144
__le16 status_code;
11451145
/* possibly followed by Challenge text */
1146-
u8 variable[0];
1146+
u8 variable[];
11471147
} __packed auth;
11481148
struct {
11491149
__le16 reason_code;
@@ -1152,26 +1152,26 @@ struct ieee80211_mgmt {
11521152
__le16 capab_info;
11531153
__le16 listen_interval;
11541154
/* followed by SSID and Supported rates */
1155-
u8 variable[0];
1155+
u8 variable[];
11561156
} __packed assoc_req;
11571157
struct {
11581158
__le16 capab_info;
11591159
__le16 status_code;
11601160
__le16 aid;
11611161
/* followed by Supported rates */
1162-
u8 variable[0];
1162+
u8 variable[];
11631163
} __packed assoc_resp, reassoc_resp;
11641164
struct {
11651165
__le16 capab_info;
11661166
__le16 status_code;
1167-
u8 variable[0];
1167+
u8 variable[];
11681168
} __packed s1g_assoc_resp, s1g_reassoc_resp;
11691169
struct {
11701170
__le16 capab_info;
11711171
__le16 listen_interval;
11721172
u8 current_ap[ETH_ALEN];
11731173
/* followed by SSID and Supported rates */
1174-
u8 variable[0];
1174+
u8 variable[];
11751175
} __packed reassoc_req;
11761176
struct {
11771177
__le16 reason_code;
@@ -1182,19 +1182,19 @@ struct ieee80211_mgmt {
11821182
__le16 capab_info;
11831183
/* followed by some of SSID, Supported rates,
11841184
* FH Params, DS Params, CF Params, IBSS Params, TIM */
1185-
u8 variable[0];
1185+
u8 variable[];
11861186
} __packed beacon;
11871187
struct {
11881188
/* only variable items: SSID, Supported rates */
1189-
u8 variable[0];
1189+
DECLARE_FLEX_ARRAY(u8, variable);
11901190
} __packed probe_req;
11911191
struct {
11921192
__le64 timestamp;
11931193
__le16 beacon_int;
11941194
__le16 capab_info;
11951195
/* followed by some of SSID, Supported rates,
11961196
* FH Params, DS Params, CF Params, IBSS Params */
1197-
u8 variable[0];
1197+
u8 variable[];
11981198
} __packed probe_resp;
11991199
struct {
12001200
u8 category;
@@ -1203,16 +1203,16 @@ struct ieee80211_mgmt {
12031203
u8 action_code;
12041204
u8 dialog_token;
12051205
u8 status_code;
1206-
u8 variable[0];
1206+
u8 variable[];
12071207
} __packed wme_action;
12081208
struct{
12091209
u8 action_code;
1210-
u8 variable[0];
1210+
u8 variable[];
12111211
} __packed chan_switch;
12121212
struct{
12131213
u8 action_code;
12141214
struct ieee80211_ext_chansw_ie data;
1215-
u8 variable[0];
1215+
u8 variable[];
12161216
} __packed ext_chan_switch;
12171217
struct{
12181218
u8 action_code;
@@ -1228,7 +1228,7 @@ struct ieee80211_mgmt {
12281228
__le16 timeout;
12291229
__le16 start_seq_num;
12301230
/* followed by BA Extension */
1231-
u8 variable[0];
1231+
u8 variable[];
12321232
} __packed addba_req;
12331233
struct{
12341234
u8 action_code;
@@ -1244,11 +1244,11 @@ struct ieee80211_mgmt {
12441244
} __packed delba;
12451245
struct {
12461246
u8 action_code;
1247-
u8 variable[0];
1247+
u8 variable[];
12481248
} __packed self_prot;
12491249
struct{
12501250
u8 action_code;
1251-
u8 variable[0];
1251+
u8 variable[];
12521252
} __packed mesh_action;
12531253
struct {
12541254
u8 action;
@@ -1292,7 +1292,7 @@ struct ieee80211_mgmt {
12921292
u8 toa[6];
12931293
__le16 tod_error;
12941294
__le16 toa_error;
1295-
u8 variable[0];
1295+
u8 variable[];
12961296
} __packed ftm;
12971297
struct {
12981298
u8 action_code;

include/uapi/linux/dlm_device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ struct dlm_lock_params {
4545
void __user *bastaddr;
4646
struct dlm_lksb __user *lksb;
4747
char lvb[DLM_USER_LVB_LEN];
48-
char name[0];
48+
char name[];
4949
};
5050

5151
struct dlm_lspace_params {
5252
__u32 flags;
5353
__u32 minor;
54-
char name[0];
54+
char name[];
5555
};
5656

5757
struct dlm_purge_params {

0 commit comments

Comments
 (0)