diff options
author | Thomas Hindoe Paaboel Andersen <phomes@gmail.com> | 2013-02-14 22:03:40 +0100 |
---|---|---|
committer | Thomas Hindoe Paaboel Andersen <phomes@gmail.com> | 2013-02-14 22:04:17 +0100 |
commit | 0e4ffbff01cb6b8ca1dd9f0afe61c4e4918872e7 (patch) | |
tree | 6a0f0889d1665086e9dfc860f77c22beabd2f725 /src/bootchart/bootchart.c | |
parent | f7900e258dfb8ab55f333d02d96f908ca0ea8899 (diff) |
bootchart: stricter checks of cli input
Diffstat (limited to 'src/bootchart/bootchart.c')
-rw-r--r-- | src/bootchart/bootchart.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index db345ee71f..0c4d3e3432 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -43,6 +43,7 @@ #include "macro.h" #include "conf-parser.h" #include "strxcpyx.h" +#include "path-util.h" double graph_start; double log_start; @@ -131,17 +132,17 @@ int main(int argc, char *argv[]) while (1) { static struct option opts[] = { - {"rel", 0, NULL, 'r'}, - {"freq", 1, NULL, 'f'}, - {"samples", 1, NULL, 'n'}, - {"pss", 0, NULL, 'p'}, - {"output", 1, NULL, 'o'}, - {"init", 1, NULL, 'i'}, - {"filter", 0, NULL, 'F'}, - {"help", 0, NULL, 'h'}, - {"scale-x", 1, NULL, 'x'}, - {"scale-y", 1, NULL, 'y'}, - {"entropy", 0, NULL, 'e'}, + {"rel", no_argument, NULL, 'r'}, + {"freq", required_argument, NULL, 'f'}, + {"samples", required_argument, NULL, 'n'}, + {"pss", no_argument, NULL, 'p'}, + {"output", required_argument, NULL, 'o'}, + {"init", required_argument, NULL, 'i'}, + {"filter", no_argument, NULL, 'F'}, + {"help", no_argument, NULL, 'h'}, + {"scale-x", required_argument, NULL, 'x'}, + {"scale-y", required_argument, NULL, 'y'}, + {"entropy", no_argument, NULL, 'e'}, {NULL, 0, NULL, 0} }; @@ -155,28 +156,30 @@ int main(int argc, char *argv[]) relative = true; break; case 'f': - hz = atof(optarg); + safe_atod(optarg, &hz); break; case 'F': filter = false; break; case 'n': - len = atoi(optarg); + safe_atoi(optarg, &len); break; case 'o': - strncpy(output_path, optarg, PATH_MAX - 1); + path_kill_slashes(optarg); + strscpy(output_path, sizeof(output_path), optarg); break; case 'i': - strncpy(init_path, optarg, PATH_MAX - 1); + path_kill_slashes(optarg); + strscpy(init_path, sizeof(init_path), optarg); break; case 'p': pss = true; break; case 'x': - scale_x = atof(optarg); + safe_atod(optarg, &scale_x); break; case 'y': - scale_y = atof(optarg); + safe_atod(optarg, &scale_y); break; case 'e': entropy = true; @@ -225,7 +228,7 @@ int main(int argc, char *argv[]) execl(init_path, init_path, NULL); } } - argv[0][0] = '@'; + argv[0][0] = '@'; /* start with empty ps LL */ ps_first = calloc(1, sizeof(struct ps_struct)); |