mirror of https://github.com/xzeldon/htop.git
Fix crash on invalid command line arguments:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=435651
This commit is contained in:
parent
e685bdeea0
commit
f356997269
34
htop.c
34
htop.c
|
@ -208,32 +208,38 @@ int main(int argc, char** argv) {
|
||||||
uid_t userId = 0;
|
uid_t userId = 0;
|
||||||
int sortKey = 0;
|
int sortKey = 0;
|
||||||
|
|
||||||
if (argc > 0) {
|
int arg = 1;
|
||||||
if (String_eq(argv[1], "--help")) {
|
while (arg < argc) {
|
||||||
|
if (String_eq(argv[arg], "--help")) {
|
||||||
printHelpFlag();
|
printHelpFlag();
|
||||||
} else if (String_eq(argv[1], "--version")) {
|
} else if (String_eq(argv[arg], "--version")) {
|
||||||
printVersionFlag();
|
printVersionFlag();
|
||||||
} else if (String_eq(argv[1], "--sort-key")) {
|
} else if (String_eq(argv[arg], "--sort-key")) {
|
||||||
if (argc < 2) printHelpFlag();
|
if (arg == argc - 1) printHelpFlag();
|
||||||
if (String_eq(argv[2], "help")) {
|
arg++;
|
||||||
|
char* field = argv[arg];
|
||||||
|
if (String_eq(field, "help")) {
|
||||||
for (int j = 1; j < LAST_PROCESSFIELD; j++)
|
for (int j = 1; j < LAST_PROCESSFIELD; j++)
|
||||||
printf ("%s\n", Process_fieldNames[j]);
|
printf ("%s\n", Process_fieldNames[j]);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
sortKey = ColumnsPanel_fieldNameToIndex(argv[2]);
|
sortKey = ColumnsPanel_fieldNameToIndex(field);
|
||||||
if (sortKey == -1) {
|
if (sortKey == -1) {
|
||||||
fprintf(stderr, "Error: invalid column \"%s\".\n", argv[2]);
|
fprintf(stderr, "Error: invalid column \"%s\".\n", field);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else if (String_eq(argv[1], "-d")) {
|
} else if (String_eq(argv[arg], "-d")) {
|
||||||
if (argc < 2) printHelpFlag();
|
if (arg == argc - 1) printHelpFlag();
|
||||||
sscanf(argv[2], "%d", &delay);
|
arg++;
|
||||||
|
sscanf(argv[arg], "%d", &delay);
|
||||||
if (delay < 1) delay = 1;
|
if (delay < 1) delay = 1;
|
||||||
if (delay > 100) delay = 100;
|
if (delay > 100) delay = 100;
|
||||||
} else if (String_eq(argv[1], "-u")) {
|
} else if (String_eq(argv[arg], "-u")) {
|
||||||
if (argc < 2) printHelpFlag();
|
if (arg == argc - 1) printHelpFlag();
|
||||||
setUserOnly(argv[2], &userOnly, &userId);
|
arg++;
|
||||||
|
setUserOnly(argv[arg], &userOnly, &userId);
|
||||||
}
|
}
|
||||||
|
arg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(PROCDIR, R_OK) != 0) {
|
if (access(PROCDIR, R_OK) != 0) {
|
||||||
|
|
Loading…
Reference in New Issue