]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: avoid a static analysis warning in csplit
authorPádraig Brady <P@draigBrady.com>
Tue, 26 Jun 2012 10:13:45 +0000 (11:13 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 26 Jun 2012 10:27:32 +0000 (11:27 +0100)
The Canalyze static code analyzer correctly surmised
that there is a use-after-free bug in free_buffer()
at the line "struct line *n = l->next", if that
function is called multiple times.

This is not a runtime issue since a list of lines
will not be present in the !lines_found case.

* src/csplit.c (free_buffer): Set list head to NULL so
that this function can be called multiple times.
(load_buffer): Remove a redundant call to free_buffer().

Reported-by: Xu Zhongxing
THANKS.in
src/csplit.c

index 51b2c7dda7f7b9c9bd120c0efde5a3e0e05d864c..2bdeab5e3c11b2d961751d4ad4a259d93815b352 100644 (file)
--- a/THANKS.in
+++ b/THANKS.in
@@ -636,6 +636,7 @@ Wis Macomson                        wis.macomson@intel.com
 Wojciech Purczynski                 cliph@isec.pl
 Wolfram Kleff                       kleff@cs.uni-bonn.de
 Won-kyu Park                        wkpark@chem.skku.ac.kr
+Xu Zhongxing                        xu_zhong_xing@163.com
 Yang Ren                            ryang@redhat.com
 Yanko Kaneti                        yaneti@declera.com
 Yann Dirson                         dirson@debian.org
index fb43350a2c6d1950343955241408b66a1b06b326..c10562bcbfb1c0852979ce331901857cda0fd8d6 100644 (file)
@@ -425,6 +425,7 @@ free_buffer (struct buffer_record *buf)
       free (l);
       l = n;
     }
+  buf->line_start = NULL;
   free (buf->buffer);
   buf->buffer = NULL;
 }
@@ -499,8 +500,6 @@ load_buffer (void)
       b->bytes_used += read_input (p, bytes_avail);
 
       lines_found = record_line_starts (b);
-      if (!lines_found)
-        free_buffer (b);
 
       if (lines_found || have_read_eof)
         break;
@@ -515,7 +514,10 @@ load_buffer (void)
   if (lines_found)
     save_buffer (b);
   else
-    free (b);
+    {
+      free_buffer (b);
+      free (b);
+    }
 
   return lines_found != 0;
 }