summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsa Peuha <esa.peuha@gmail.com>2015-06-05 20:28:28 +0530
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2015-06-05 19:48:32 +0200
commitf5bc22b18e3c3042dbf7e4ecc38e046b13a2a992 (patch)
treef9ec1aa6752a16a34e4ccafd3b96b6a0be9b41f7
parent921af9c9865a3f54c388b0836f20c9ae3b30b247 (diff)
Fix ps -o %r infinite loop
* libps/fmt.c (_fmt_create): When nothing at all was recognized, break out instead of looping.
-rw-r--r--libps/fmt.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/libps/fmt.c b/libps/fmt.c
index 0465555d..580b097e 100644
--- a/libps/fmt.c
+++ b/libps/fmt.c
@@ -68,6 +68,8 @@ _fmt_create (char *src, int posix, struct ps_fmt_specs *fmt_specs,
src = new_fmt->src;
while (*src != '\0')
{
+ char *start = src;
+
if (field - fields == fields_alloced)
/* Time to grow FIELDS to make room for more. */
{
@@ -172,6 +174,19 @@ _fmt_create (char *src, int posix, struct ps_fmt_specs *fmt_specs,
/* This field spec doesn't have a name, so use its flags fields
to set the global ones, and skip it. */
{
+ /* if we didn't use any chars, don't loop indefinitely */
+ if (src == start)
+ {
+ if (err_string)
+ asprintf (err_string, "%s: Unknown format spec", src);
+
+ FREE (new_fmt->src);
+ FREE (new_fmt);
+ FREE (fields);
+
+ return EINVAL;
+ }
+
global_clr_flags = clr_flags;
global_inv_flags = inv_flags;
continue;