mirror of
https://github.com/SELinuxProject/selinux
synced 2025-02-28 15:30:31 +00:00
polciycoreutils: setsebool: error when setting multiple options
If one were to use multiple options such as both -P and -N we would have problems. The issue is that for some reason instead of looking at optind (the first non-option) we were looking at argc-optind. These happen to be the same if there are 0 or 1 options, but doesn't work with more than 1 option. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
cef1d08d1e
commit
e4f0a20ee1
@ -30,7 +30,7 @@ void usage(void)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
size_t rc, start;
|
size_t rc;
|
||||||
int clflag; /* holds codes for command line flags */
|
int clflag; /* holds codes for command line flags */
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
usage();
|
usage();
|
||||||
@ -63,30 +63,29 @@ int main(int argc, char **argv)
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
start = argc-optind;
|
|
||||||
/* Check to see which way we are being called. If a '=' is passed,
|
/* Check to see which way we are being called. If a '=' is passed,
|
||||||
we'll enforce the list syntax. If not we'll enforce the original
|
we'll enforce the list syntax. If not we'll enforce the original
|
||||||
syntax for backward compatibility. */
|
syntax for backward compatibility. */
|
||||||
if (strchr(argv[start], '=') == 0) {
|
if (strchr(argv[optind], '=') == 0) {
|
||||||
int len;
|
int len;
|
||||||
char *bool_list[1];
|
char *bool_list[1];
|
||||||
|
|
||||||
if ((argc - start) != 2)
|
if ((argc - optind) != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
/* Add 1 for the '=' */
|
/* Add 1 for the '=' */
|
||||||
len = strlen(argv[start]) + strlen(argv[start + 1]) + 2;
|
len = strlen(argv[optind]) + strlen(argv[optind + 1]) + 2;
|
||||||
bool_list[0] = (char *)malloc(len);
|
bool_list[0] = (char *)malloc(len);
|
||||||
if (bool_list[0] == 0) {
|
if (bool_list[0] == 0) {
|
||||||
fputs("Out of memory - aborting\n", stderr);
|
fputs("Out of memory - aborting\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
snprintf(bool_list[0], len, "%s=%s", argv[start],
|
snprintf(bool_list[0], len, "%s=%s", argv[optind],
|
||||||
argv[start + 1]);
|
argv[optind + 1]);
|
||||||
rc = setbool(bool_list, 0, 1);
|
rc = setbool(bool_list, 0, 1);
|
||||||
free(bool_list[0]);
|
free(bool_list[0]);
|
||||||
} else
|
} else
|
||||||
rc = setbool(argv, start, argc);
|
rc = setbool(argv, optind, argc);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user