summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2010-02-07 23:33:51 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2010-02-07 23:33:51 +0100
commit4c0c79dd946f481cda57c4f995a062b2387e4216 (patch)
tree21d84808eed6dce45ed4d1e3f7de43bed5c50a52
parent97c5690abeaa88767acf2ffbb55552e8278052c8 (diff)
Fix ps segfault when given empty format string
2010-02-02 Carl Fredrik Hammar <hammy.lite@gmail.com> * utils/ps.c (main): Move format parsing to parse_opt() and pass state to parse_enum().
-rw-r--r--utils/ps.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/utils/ps.c b/utils/ps.c
index 6f209655..992b467d 100644
--- a/utils/ps.c
+++ b/utils/ps.c
@@ -324,6 +324,28 @@ main(int argc, char *argv[])
state->child_inputs[0] = &pids_argp_params;
break;
+ case ARGP_KEY_SUCCESS:
+ /* Select an explicit format string if FMT_STRING is a format
+ name. This is done here because parse_enum needs STATE. */
+ {
+ const char *fmt_name (unsigned n)
+ {
+ return
+ n >= (sizeof output_fmts / sizeof *output_fmts)
+ ? 0
+ : output_fmts[n].name;
+ }
+ int fmt_index = parse_enum (fmt_string, fmt_name,
+ "format type", 1, state);
+ if (fmt_index >= 0)
+ {
+ fmt_string = output_fmts[fmt_index].fmt;
+ if (sort_key_name == NULL)
+ sort_key_name = output_fmts[fmt_index].sort_key;
+ }
+ }
+ break;
+
default:
return ARGP_ERR_UNKNOWN;
}
@@ -343,24 +365,6 @@ main(int argc, char *argv[])
/* Parse our command line. This shouldn't ever return an error. */
argp_parse (&argp, argc, argv, 0, 0, 0);
- /* Select an explicit format string if FMT_STRING is a format name. */
- {
- const char *fmt_name (unsigned n)
- {
- return
- n >= (sizeof output_fmts / sizeof *output_fmts)
- ? 0
- : output_fmts[n].name;
- }
- int fmt_index = parse_enum (fmt_string, fmt_name, "format type", 1, 0);
- if (fmt_index >= 0)
- {
- fmt_string = output_fmts[fmt_index].fmt;
- if (sort_key_name == NULL)
- sort_key_name = output_fmts[fmt_index].sort_key;
- }
- }
-
err = proc_stat_list_create(context, &procset);
if (err)
error(1, err, "proc_stat_list_create");