summaryrefslogtreecommitdiffstats
path: root/htop.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2011-08-26 21:04:26 +0000
committerHisham Muhammad <hisham@gobolinux.org>2011-08-26 21:04:26 +0000
commit5dfb46e14f1f31bb4354be91590c90a91a6b3a34 (patch)
tree67318e5b572bc2b92c0872c670c936430511c265 /htop.c
parent7eeb52dfbb881e6094c2043c8ee87495b4c72a17 (diff)
Stricter checks for command-line options
(thanks to Sebastian Pipping)
Diffstat (limited to 'htop.c')
-rw-r--r--htop.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/htop.c b/htop.c
index 88ef59d9..d737ff35 100644
--- a/htop.c
+++ b/htop.c
@@ -228,12 +228,14 @@ static void addUserToVector(int key, void* userCast, void* panelCast) {
Panel_add(panel, (Object*) ListItem_new(user, key));
}
-static void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
+static bool setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
struct passwd* user = getpwnam(userName);
if (user) {
*userOnly = true;
*userId = user->pw_uid;
+ return true;
}
+ return false;
}
static inline void setSortKey(ProcessList* pl, ProcessField sortKey, Panel* panel, Settings* settings) {
@@ -295,16 +297,25 @@ int main(int argc, char** argv) {
}
break;
case 'd':
- sscanf(optarg, "%d", &delay);
- if (delay < 1) delay = 1;
- if (delay > 100) delay = 100;
+ if (sscanf(optarg, "%d", &delay) == 1) {
+ if (delay < 1) delay = 1;
+ if (delay > 100) delay = 100;
+ } else {
+ fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
+ exit(1);
+ }
break;
case 'u':
- setUserOnly(optarg, &userOnly, &userId);
+ if (!setUserOnly(optarg, &userOnly, &userId)) {
+ fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
+ exit(1);
+ }
break;
case 'C':
usecolors=0;
break;
+ default:
+ exit(1);
}
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy