Skip to content

Commit 7c1fc7e

Browse files
committed
auditd: fail plugin_dir updates on ENOMEM
1 parent 150d8b6 commit 7c1fc7e

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

src/auditd-config.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,20 +1843,29 @@ static int max_restarts_parser(const struct nv_pair *nv, int line,
18431843
static int plugin_dir_parser(const struct nv_pair *nv, int line,
18441844
struct daemon_conf *config)
18451845
{
1846+
char *tmp;
1847+
18461848
audit_msg(LOG_DEBUG, "plugin_dir_parser called with: %s", nv->value);
18471849

1848-
if (nv->value == NULL)
1850+
if (nv->value == NULL) {
1851+
free(config->plugin_dir);
18491852
config->plugin_dir = NULL;
1850-
else {
1853+
} else {
18511854
size_t len = strlen(nv->value);
1852-
free(config->plugin_dir);
1853-
config->plugin_dir = malloc(len + 2);
1854-
if (config->plugin_dir) {
1855-
strcpy(config->plugin_dir, nv->value);
1856-
if (len > 1 && config->plugin_dir[len - 1] != '/')
1857-
config->plugin_dir[len] = '/';
1858-
config->plugin_dir[len + 1] = 0;
1855+
1856+
tmp = malloc(len + 2);
1857+
if (tmp == NULL) {
1858+
audit_msg(LOG_ERR,
1859+
"Out of memory setting plugin_dir - line %d",
1860+
line);
1861+
return 1;
18591862
}
1863+
strcpy(tmp, nv->value);
1864+
if (len > 1 && tmp[len - 1] != '/')
1865+
tmp[len++] = '/';
1866+
tmp[len] = 0;
1867+
free(config->plugin_dir);
1868+
config->plugin_dir = tmp;
18601869
}
18611870
return 0;
18621871
}

0 commit comments

Comments
 (0)