Skip to content

Commit

Permalink
CID 437903 fix
Browse files Browse the repository at this point in the history
The strdup-ed pointer was actually not leaked but assigned to
s->dir. There was, anyways, just one poblem, when the dir started with
':', so. `strtok(cfg_copy, ":")` would skip leading ':' returning
cfg_copy+1. That would then be passed to free in export_destroy(), which
would most likely crash on invalid pointer.
  • Loading branch information
MartinPulec committed Feb 28, 2024
1 parent 502fb0c commit 854c554
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ struct exporter *export_init(struct module *parent, const char *cfg, bool should
export_destroy(s);
return NULL;
}
char *cfg_copy = strdup(cfg);
s->dir = strdup(cfg);
char *save_ptr = NULL;
s->dir = strtok_r(cfg_copy, ":", &save_ptr);
if (s->dir == NULL) {
char *item = strtok_r(s->dir, ":", &save_ptr); // skip the dir
if (item == NULL) {
HANDLE_ERROR
}
if (!parse_options(s, save_ptr, &should_export)) {
Expand Down

0 comments on commit 854c554

Please sign in to comment.