changeset 14652:200834674626

quotearg: avoid uninitialized variable use Coverity correctly deduced: Error: UNINIT: m4-1.4.16/lib/quotearg.c:171: var_decl: Declaring variable "o" without initializer. m4-1.4.16/lib/quotearg.c:175: uninit_use: Using uninitialized value "o": field "o".right_quote is uninitialized. When custom_quoting_style was introduced in commit 12247f77, this method was not updated, and any caller that passed the new enum value to any of the existing quotearg_*style functions could trigger a crash from the uninitialized memory. That was already documented as unspecified behavior, though, so changing to an abort makes it easier to spot bad code that passes the wrong enum value, rather than waiting for the eventual bad memory dereference later on. Most callers of quotearg_*style were using quoting_style_args and quoting_style_vals to map strings to particular enum values, and custom_quoting_style is (intentionally) not covered by these arrays, so the pre-patch bug/post-patch abort are not possible with those callers. * lib/quotearg.c (quoting_options_from_style): Initialize remaining fields, and ensure that custom styles are only used via quoting_options rather than quoting_style. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Thu, 28 Apr 2011 17:25:49 -0600
parents dab11becac47
children 4867b9dad286
files ChangeLog lib/quotearg.c
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Apr 29 18:58:43 2011 +0200
+++ b/ChangeLog	Thu Apr 28 17:25:49 2011 -0600
@@ -1,3 +1,10 @@
+2011-04-29  Eric Blake  <eblake@redhat.com>
+
+	quotearg: avoid uninitialized variable use
+	* lib/quotearg.c (quoting_options_from_style): Initialize
+	remaining fields, and ensure that custom styles are only used via
+	quoting_options rather than quoting_style.
+
 2011-04-29  Jim Meyering  <meyering@redhat.com>
 
 	maint.mk: remove unused VC-tag variable
--- a/lib/quotearg.c	Fri Apr 29 18:58:43 2011 +0200
+++ b/lib/quotearg.c	Thu Apr 28 17:25:49 2011 -0600
@@ -168,10 +168,10 @@
 static struct quoting_options
 quoting_options_from_style (enum quoting_style style)
 {
-  struct quoting_options o;
+  struct quoting_options o = { 0 };
+  if (style == custom_quoting_style)
+    abort ();
   o.style = style;
-  o.flags = 0;
-  memset (o.quote_these_too, 0, sizeof o.quote_these_too);
   return o;
 }