Skip to content

Commit

Permalink
Args.c: do not handle -options twice
Browse files Browse the repository at this point in the history
An options string/filename can only be provided via the command line
or environment. Both are handled in the one-time init part of
ddxProcessArguments() and will not change during runtime. As we do not
want an options file to include another "options" option there's no
need to handle that a second time. Due to the (kind of crazy) way
nxagent handles all this option stuff we cannot remove the second
check completely.
  • Loading branch information
uli42 committed Nov 20, 2017
1 parent 399860a commit 836225d
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions nx-X11/programs/Xserver/hw/nxagent/Args.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,21 @@ int ddxProcessArgument(int argc, char *argv[], int i)

for (j = 0; j < argc; j++)
{
/*
* Read the _last_ options file only and only at startup.
* This had to be '-options' since the beginning
* but was '-option' by mistake. Now we have to
* handle the backward compatibility.
*/
if ((!strcmp(argv[j], "-options") || !strcmp(argv[j], "-option")) && j + 1 < argc)
{
free(nxagentOptionsFilenameOrString);
if ((nxagentOptionsFilenameOrString = strdup(argv[j + 1])) == NULL)
{
FatalError("malloc for -options failed");
}
break;
j++;
}
}

Expand Down Expand Up @@ -314,36 +321,17 @@ int ddxProcessArgument(int argc, char *argv[], int i)
}

/*
* This had to be '-options' since the beginning
* but was '-option' by mistake. Now we have to
* handle the backward compatibility.
* an options string/filename can only be provided via the command
* line or environment. Both are handled above in the one-time init
* part and will not change during runtime. As we do not want an
* options file to include another "options" option we skip this
* here. Due to the way nxagent handles all this option stuff we
* cannot remove the check completely.
*/

if (!strcmp(argv[i], "-options") || !strcmp(argv[i], "-option"))
{
if (++i < argc)
{
int size;

free(nxagentOptionsFilenameOrString);
nxagentOptionsFilenameOrString = NULL;

/* FIXME: why limit 10 1024 bytes? */
if ((size = strlen(argv[i])) < 1024)
{
if ((nxagentOptionsFilenameOrString = strndup(argv[i], size)) == NULL)
{
FatalError("malloc for -options failed");
}
}
else
{
/* there's no use in ignoring the whole options string or file */
FatalError("options parameter is too long");
}
return 2;
}
return 0;
/* skip -options and its argument */
return 2;
}

if (!strcmp(argv[i], "-sync")) {
Expand Down

0 comments on commit 836225d

Please sign in to comment.