Skip to content

Commit ba47ba4

Browse files
committed
Add warning for unused results for plist_append
1 parent 58d51a5 commit ba47ba4

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

audisp/audispd-llist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ unsigned int plist_count_active(const conf_llist *l) __nonnull ((1));
5353
void plist_last(conf_llist *l) __nonnull ((1));
5454
lnode *plist_next(conf_llist *l) __nonnull ((1));
5555
static inline lnode *plist_get_cur(conf_llist *l) __nonnull ((1));
56-
int plist_append(conf_llist *l, plugin_conf_t *p) __nonnull ((1));
56+
int plist_append(conf_llist *l, plugin_conf_t *p) __wur __nonnull ((1));
5757
void plist_clear(conf_llist* l) __nonnull ((1));
5858
void plist_mark_all_unchecked(conf_llist* l) __nonnull ((1));
5959
lnode *plist_find_unchecked(conf_llist* l) __nonnull ((1));

audisp/audispd.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,23 @@ static void load_plugin_conf(conf_llist *plugin)
131131
reason = "file without .conf suffix";
132132

133133
if (reason) {
134-
audit_msg(LOG_DEBUG, "Skipping %s plugin due to %s", e->d_name, reason);
134+
audit_msg(LOG_DEBUG,
135+
"Skipping %s plugin due to %s",
136+
e->d_name, reason);
135137
continue;
136138
}
137139

138140
clear_pconfig(&config);
139141
if (load_pconfig(&config, dfd, e->d_name) == 0) {
140142
/* Push onto config list only if active */
141-
if (config.active == A_YES)
142-
plist_append(plugin, &config);
143-
else
143+
if (config.active == A_YES) {
144+
if (plist_append(plugin, &config) != 0) {
145+
audit_msg(LOG_ERR,
146+
"Failed adding %s plugin to list",
147+
e->d_name);
148+
free_pconfig(&config);
149+
}
150+
} else
144151
free_pconfig(&config);
145152
} else
146153
audit_msg(LOG_ERR,
@@ -257,10 +264,17 @@ static int reconfigure(void)
257264
if (tpconf->p->active == A_YES) {
258265
tpconf->p->checked = 1;
259266
plist_last(&plugin_conf);
260-
plist_append(&plugin_conf, tpconf->p);
261-
free(tpconf->p);
267+
if (plist_append(&plugin_conf,
268+
tpconf->p) != 0) {
269+
audit_msg(LOG_ERR,
270+
"Failed adding %s plugin to list",
271+
tpconf->p->name);
272+
free(tpconf->p);
273+
} else {
274+
free(tpconf->p);
275+
start_one_plugin(plist_get_cur(&plugin_conf));
276+
}
262277
tpconf->p = NULL;
263-
start_one_plugin(plist_get_cur(&plugin_conf));
264278
}
265279
} else {
266280
if (opconf->p->active == tpconf->p->active) {

audisp/test/test-audispd-llist.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,12 @@ test_plugin_hup_signal_handling(void)
252252
if (!old_config1 || !old_config2 || !old_config3)
253253
TEST_FAIL("failed to create old plugin configs");
254254

255-
plist_append(&old_plugin_list, old_config1);
256-
plist_append(&old_plugin_list, old_config2);
257-
plist_append(&old_plugin_list, old_config3);
255+
if (plist_append(&old_plugin_list, old_config1) != 0)
256+
TEST_FAIL("failed to append old_config1");
257+
if (plist_append(&old_plugin_list, old_config2) != 0)
258+
TEST_FAIL("failed to append old_config2");
259+
if (plist_append(&old_plugin_list, old_config3) != 0)
260+
TEST_FAIL("failed to append old_config3");
258261

259262
// Create new configuration (remove audit-af_unix, add audit-custom-plugin, keep others)
260263
new_config1 = create_test_plugin("audit-remote", A_YES, "/usr/sbin/audit-remote");
@@ -264,9 +267,12 @@ test_plugin_hup_signal_handling(void)
264267
if (!new_config1 || !new_config2 || !new_config4)
265268
TEST_FAIL("failed to create new plugin configs");
266269

267-
plist_append(&new_plugin_list, new_config1);
268-
plist_append(&new_plugin_list, new_config2);
269-
plist_append(&new_plugin_list, new_config4);
270+
if (plist_append(&new_plugin_list, new_config1) != 0)
271+
TEST_FAIL("failed to append new_config1");
272+
if (plist_append(&new_plugin_list, new_config2) != 0)
273+
TEST_FAIL("failed to append new_config2");
274+
if (plist_append(&new_plugin_list, new_config4) != 0)
275+
TEST_FAIL("failed to append new_config4");
270276

271277
// Simulate HUP signal handling: mark all old plugins as unchecked
272278
plist_mark_all_unchecked(&old_plugin_list);
@@ -283,17 +289,21 @@ test_plugin_hup_signal_handling(void)
283289
// Plugin exists in old list, mark as checked
284290
old_node->p->checked = 1;
285291

286-
// Verify configuration update (audit-syslog changed from A_YES to A_NO)
292+
// Verify configuration update (audit-syslog changed
293+
// from A_YES to A_NO)
287294
if (strcmp(new_node->p->name, "audit-syslog") == 0) {
288-
if (old_node->p->active == A_YES && new_node->p->active == A_NO) {
289-
// This simulates updating the configuration
295+
if (old_node->p->active ==
296+
A_YES && new_node->p->active == A_NO) {
297+
// This simulates updating the
298+
// configuration
290299
old_node->p->active = A_NO;
291300
}
292301
}
293302
} else {
294303
// New plugin, add to old list
295304
plist_last(&old_plugin_list);
296-
plist_append(&old_plugin_list, new_node->p);
305+
if (plist_append(&old_plugin_list, new_node->p) != 0)
306+
TEST_FAIL("failed to append new plugin to old list");
297307
}
298308

299309
new_node = plist_next(&new_plugin_list);
@@ -374,7 +384,8 @@ test_plugin_iteration_and_startup(void)
374384
for (i = 0; i < 5; i++) {
375385
if (!configs[i])
376386
TEST_FAIL("failed to create plugin config");
377-
plist_append(&plugin_list, configs[i]);
387+
if (plist_append(&plugin_list, configs[i]) != 0)
388+
TEST_FAIL("failed to append plugin config");
378389
}
379390

380391
// Simulate plugin startup iteration (like start_plugins in audispd.c)
@@ -413,7 +424,8 @@ test_plugin_iteration_and_startup(void)
413424
TEST_FAIL("failed to create new plugin config");
414425

415426
plist_last(&plugin_list);
416-
plist_append(&plugin_list, config_new);
427+
if (plist_append(&plugin_list, config_new) != 0)
428+
TEST_FAIL("failed to append new plugin");
417429

418430
if (plist_count(&plugin_list) != 6)
419431
TEST_FAIL("should have 6 plugins after append");

0 commit comments

Comments
 (0)