coreutils
[Top][All Lists]
Advanced

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

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


From: Pádraig Brady
Subject: [PATCH] df: fix crash in mem exhaustion edge case
Date: Thu, 05 May 2011 15:38:20 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3

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.

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);
               free (cell);
             }
           IF_LINT (free (table[row][field]));



reply via email to

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