diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2011-08-26 21:04:26 +0000 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2011-08-26 21:04:26 +0000 |
commit | 5dfb46e14f1f31bb4354be91590c90a91a6b3a34 (patch) | |
tree | 67318e5b572bc2b92c0872c670c936430511c265 /htop.c | |
parent | 7eeb52dfbb881e6094c2043c8ee87495b4c72a17 (diff) |
Stricter checks for command-line options
(thanks to Sebastian Pipping)
Diffstat (limited to 'htop.c')
-rw-r--r-- | htop.c | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -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); } } |