Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
flow: Fix string corruption in sol-conffile.c
Browse files Browse the repository at this point in the history
According to the manual, 'dirname' and 'basename' may change the input
string and 'sol_argv' return was being provided directly to them which
in turn was corruption it's internal string since it doesn't return a
copy.

Also, each call needs it's own copy to guarantee that none will receive
corrupted that as input.

Signed-off-by: Murilo Belluzzo <murilo.belluzzo@intel.com>
  • Loading branch information
mbelluzzo-intel committed Sep 30, 2015
1 parent 4975b55 commit 5794103
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/shared/sol-conffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ _add_lookup_path(struct sol_vector *vector, char *appname, char *appdir, const c
static void
_load_vector_defaults(void)
{
char *appdir, *appname, **argv;
char *appdir = NULL, *appname = NULL, **argv;
char *dir_str = NULL, *name_str = NULL;
const char *board_name;
uint16_t i;
struct sol_str_slice *slice;
Expand All @@ -825,11 +826,12 @@ _load_vector_defaults(void)

board_name = sol_platform_get_board_name();
argv = sol_argv();
appname = appdir = NULL;

if (argv) {
appname = basename(argv[0]);
appdir = dirname(argv[0]);
if (argv && argv[0]) {
dir_str = strdup(argv[0]);
name_str = strdup(argv[0]);
appname = basename(name_str);
appdir = dirname(dir_str);
}

_add_lookup_path(&fallback_paths, appname, appdir, board_name);
Expand All @@ -843,6 +845,8 @@ _load_vector_defaults(void)

sol_vector_clear(&fallback_paths);
first_call = false;
free(dir_str);
free(name_str);
}

static int
Expand Down

0 comments on commit 5794103

Please sign in to comment.