summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2013-06-29 22:13:16 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-06-29 22:13:16 +0200
commitea6ea2f554bc81b856d5286c23c2b4c8ba303fb9 (patch)
treea7612150e315e6a74638e0d9eee91409be488802 /main.c
parent26b18d8e7d8bb5f1bf9ae20e40e8b291db3cebd6 (diff)
procfs: keep old config values if the parsing fails
Previously if strtol failed the previous configuration value would get overwritten. Prevent this by storing the result in a temporary variable and update the configuration if the argument was parsed correctly and passed the sanity checks. * procfs/main.c (argp_parser): Keep old configuration in case a malformed value is encountered.
Diffstat (limited to 'main.c')
-rw-r--r--main.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/main.c b/main.c
index f33ace9..0892d36 100644
--- a/main.c
+++ b/main.c
@@ -42,36 +42,45 @@ argp_parser (int key, char *arg, struct argp_state *state)
{
struct passwd *pw;
char *endp;
+ long int v;
switch (key)
{
case 'h':
- opt_clk_tck = strtol (arg, &endp, 0);
- if (*endp || ! *arg || opt_clk_tck <= 0)
+ v = strtol (arg, &endp, 0);
+ if (*endp || ! *arg || v <= 0)
argp_error (state, "--clk-tck: HZ should be a positive integer");
+ else
+ opt_clk_tck = v;
break;
case 's':
- opt_stat_mode = strtol (arg, &endp, 8);
- if (*endp || ! *arg || opt_stat_mode & ~07777)
+ v = strtol (arg, &endp, 8);
+ if (*endp || ! *arg || (mode_t) v & ~07777)
argp_error (state, "--stat-mode: MODE should be an octal mode");
+ else
+ opt_stat_mode = v;
break;
case 'S':
if (arg)
{
- opt_fake_self = strtol (arg, &endp, 0);
+ v = strtol (arg, &endp, 0);
if (*endp || ! *arg)
argp_error (state, "--fake-self: PID must be an integer");
+ else
+ opt_fake_self = v;
}
else
opt_fake_self = 1;
break;
case 'k':
- opt_kernel_pid = strtol (arg, &endp, 0);
+ v = strtol (arg, &endp, 0);
if (*endp || ! *arg || (signed) opt_kernel_pid < 0)
argp_error (state, "--kernel-process: PID must be a positive integer");
+ else
+ opt_kernel_pid = v;
break;
case 'c':
@@ -88,10 +97,12 @@ argp_parser (int key, char *arg, struct argp_state *state)
break;
}
- opt_anon_owner = strtol (arg, &endp, 0);
- if (*endp || ! *arg || (signed) opt_anon_owner < 0)
+ v = strtol (arg, &endp, 0);
+ if (*endp || ! *arg || v < 0)
argp_error (state, "--anonymous-owner: USER should be "
"a user name or a numeric UID.");
+ else
+ opt_anon_owner = v;
break;
}