Skip to content

Commit

Permalink
properly null-terminate arguments after copy
Browse files Browse the repository at this point in the history
ref: https://sourceforge.net/p/lxde/bugs/827/

With g_shell_parse_argv(), the returned *argcp value does not count
the last "NULL" element. So when copying *argvp array with *argcp
element, the final element must be set to NULL manually.
  • Loading branch information
mtasaka committed Aug 4, 2016
1 parent 2cea95a commit d1827de
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lxterminal.c
Expand Up @@ -1434,11 +1434,12 @@ gboolean lxterminal_process_arguments(gint argc, gchar * * argv, CommandArgument
}
else
{
gchar * * tmp = g_malloc((cmd_len + 3) * sizeof(gchar *));
gchar * * tmp = g_malloc((cmd_len + 4) * sizeof(gchar *));
tmp[0] = g_strdup(shell);
tmp[1] = g_strdup_printf("-%s", shellname);
tmp[2] = g_strdup("-c");
memcpy((tmp + 3), arguments->command, cmd_len * sizeof(gchar *));
tmp[cmd_len + 3] = NULL;
g_free(arguments->command);
arguments->command = tmp;
}
Expand All @@ -1448,9 +1449,10 @@ gboolean lxterminal_process_arguments(gint argc, gchar * * argv, CommandArgument
{
if(arguments->command != NULL)
{
gchar * * tmp = g_malloc((cmd_len + 1) * sizeof(gchar *));
gchar * * tmp = g_malloc((cmd_len + 2) * sizeof(gchar *));
tmp[0] = g_strdup(arguments->command[0]);
memcpy((tmp + 1), arguments->command, cmd_len * sizeof(gchar *));
tmp[cmd_len + 1] = NULL;
g_free(arguments->command);
arguments->command = tmp;
}
Expand Down

0 comments on commit d1827de

Please sign in to comment.