coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] df: fix crash in mem exhaustion edge case


From: Jim Meyering
Subject: Re: [PATCH] df: fix crash in mem exhaustion edge case
Date: Thu, 05 May 2011 16:49:22 +0200

Pádraig Brady wrote:
> This is a theoretical issue really, as if we're
> having issues allocating a few bytes, then the system
> will likely be hosed anyway. But for correctness
> and to aid static analysis...
>
> commit 85c6205f4366edc0d2c50c7036d559acc457509d
> Author: Pádraig Brady <address@hidden>
> Date:   Thu May 5 15:20:13 2011 +0100
>
>     df: fix crash in mem exhaustion edge case
>
>     * src/df.c (print_table): Don't try to output NULL
>     if ambsalign() can't allocate memory.  Instead just
>     output the unaligned text.

Always welcome.  Thanks!

> diff --git a/src/df.c b/src/df.c
> index 14f0790..a2675da 100644
> --- a/src/df.c
> +++ b/src/df.c
> @@ -215,7 +215,7 @@ print_table (void)
>          {
>            size_t width = widths[field];
>            char *cell = table[row][field];
> -          if (!cell)
> +          if (!cell) /* Missing type column, or mount point etc. */
>              continue;
>
>            /* Note the DEV_FIELD used to be displayed on it's own line
> @@ -227,9 +227,11 @@ print_table (void)
>              fputs (cell, stdout);
>            else
>              {
> -              cell = ambsalign (table[row][field], &width,
> -                                alignments[field], MBA_UNIBYTE_FALLBACK);
> -              fputs (cell, stdout);
> +              cell = ambsalign (cell, &width, alignments[field], 0);
> +              if (!cell) /* Output unaligned data */
> +                fputs (table[row][field], stdout);
> +              else
> +                fputs (cell, stdout);

This is a little more readable/maintainable to me (2 lines rather
than 4, less duplication), but I could go either way:

                 /* When ambsalign fails, output unaligned data.  */
                 fputs (cell ? cell : table[row][field], stdout);


>                free (cell);
>              }
>            IF_LINT (free (table[row][field]));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]