Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make dup_config_arg() always duplicate the argument
.... even when conversion fails. Otherwise we end up trying to free a
member of argv[], which never works well.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
  • Loading branch information
dwmw2 committed Aug 14, 2017
1 parent 71428d0 commit cecadff
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions main.c
Expand Up @@ -913,9 +913,21 @@ static char *xstrdup(const char *arg)
#define keep_config_arg() \
(config_file ? xstrdup(config_arg) : convert_arg_to_utf8(argv, config_arg))

#define dup_config_arg() \
((config_file || is_arg_utf8(config_arg)) ? xstrdup(config_arg) : \
convert_arg_to_utf8(argv, config_arg))
#define dup_config_arg() __dup_config_arg(argv, config_arg)

static inline char *__dup_config_arg(char **argv, char *config_arg)
{
char *res;

if (config_file || is_arg_utf8(config_arg))
return xstrdup(config_arg);

res = convert_arg_to_utf8(argv, config_arg);
/* Force a copy, even if conversion failed */
if (res == config_arg)
res = xstrdup(res);
return res;
}

static int next_option(int argc, char **argv, char **config_arg)
{
Expand Down

0 comments on commit cecadff

Please sign in to comment.