wc: avoid NULL dereference on out-of-memory error
authorJim Meyering <meyering@redhat.com>
Wed, 2 Mar 2011 17:54:43 +0000 (18:54 +0100)
committerJim Meyering <meyering@redhat.com>
Thu, 3 Mar 2011 08:01:17 +0000 (09:01 +0100)
* src/wc.c (main): Diagnose failed argv_iter_init_* failure,
rather than falling through and dereferencing NULL.
Bug introduced by 2008-11-25 commit c2e56e0d,
"wc: read and process --files0-from= input a name at a time,".
* NEWS (Bug fixes): Mention it.

NEWS
src/wc.c

diff --git a/NEWS b/NEWS
index a367d8d..9993469 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   delimiter and an unbounded range like "-f1234567890-".
   [bug introduced in coreutils-5.3.0]
 
+  wc would dereference a NULL pointer upon an early out-of-memory error
+  [bug introduced in coreutils-7.1]
+
 
 * Noteworthy changes in release 8.10 (2011-02-04) [stable]
 
index 3afd4de..ccf4ccf 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -709,6 +709,9 @@ main (int argc, char **argv)
       ai = argv_iter_init_argv (files);
     }
 
+  if (!ai)
+    xalloc_die ();
+
   fstatus = get_input_fstatus (nfiles, files);
   number_width = compute_number_width (nfiles, fstatus);