[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix bug #28794: ps segfaults when given empty format string
From: |
Carl Fredrik Hammar |
Subject: |
[PATCH] Fix bug #28794: ps segfaults when given empty format string |
Date: |
Tue, 2 Feb 2010 19:41:02 +0100 |
* utils/ps.c (main): Move format parsing to parse_opt() and pass
state to parse_enum().
---
Hi,
This fixes ps so it does not segfault when given an empty format string.
The problem was that parse_enum() is given a NULL pointer instead of a
pointer to the parsing state, so I simply moved the parsing code into the
argp parsing function parse_opt() where the parsing state is available
and pass it to parse_enum(). It is only run when the argument parsing
is successful, just as before.
Regards,
Fredrik
utils/ps.c | 40 ++++++++++++++++++++++------------------
1 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/utils/ps.c b/utils/ps.c
index 6f20965..992b467 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");
--
1.6.5
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Fix bug #28794: ps segfaults when given empty format string,
Carl Fredrik Hammar <=