Selaa lähdekoodia

libdpkg: Return error in error_context_errmsg_format() only if truncated

In case we have to use the emergency buffer because the previous
vasprintf() call failed, we should only return an error code if the
vsnprintf() call on the emergency buffer truncates the output.
Guillem Jover 10 vuotta sitten
vanhempi
commit
d1f570622c
2 muutettua tiedostoa jossa 9 lisäystä ja 1 poistoa
  1. 4 0
      debian/changelog
  2. 5 1
      lib/dpkg/ehandle.c

+ 4 - 0
debian/changelog

@@ -34,6 +34,10 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
     Reported by Helmut Grohne <helmut@subdivi.de>.
   * Only set the error context message in libdpkg if it has been formatted
     correctly.
+  * Return error in error_context_errmsg_format() only if the error message
+    gets truncated. In case we have to use the emergency buffer because the
+    previous vasprintf() call failed, we should only return an error code if
+    the vsnprintf() call on the emergency buffer truncates the output.
   * Architecture support:
     - Add support for AIX operating system.
   * Portability:

+ 5 - 1
lib/dpkg/ehandle.c

@@ -202,7 +202,11 @@ error_context_errmsg_format(const char *fmt, va_list args)
     /* If there was any error, just use the emergency error message buffer,
      * even if it ends up being truncated, at least we will have a big part
      * of the problem. */
-    vsnprintf(emergency.errmsg, sizeof(emergency.errmsg), fmt, args);
+    rc = vsnprintf(emergency.errmsg, sizeof(emergency.errmsg), fmt, args);
+
+    /* Return failure only if we get truncated. */
+    if (rc >= (int)sizeof(emergency.errmsg))
+      rc = -1;
 
     error_context_errmsg_set(econtext, emergency.errmsg);
   }