Sfoglia il codice sorgente

libdpkg: Do not use fixed size strings in reporting functions

Guillem Jover 10 anni fa
parent
commit
99d596bf62
2 ha cambiato i file con 15 aggiunte e 6 eliminazioni
  1. 1 0
      debian/changelog
  2. 14 6
      lib/dpkg/report.c

+ 1 - 0
debian/changelog

@@ -11,6 +11,7 @@ dpkg (1.18.7) UNRELEASED; urgency=medium
     - In start-stop-daemon to report what to stop.
     - In dselect to print main and access methods menu entries.
     - In libdpkg command-line option parsing errors.
+    - In libdpkg warning, notice and info reporting.
   * Perl modules:
     - Relax dependency restrictions parsing to allow again sloppy spaces
       around versions, architectures and profile restrictions.

+ 14 - 6
lib/dpkg/report.c

@@ -23,9 +23,11 @@
 #include <compat.h>
 
 #include <stdarg.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 
+#include <dpkg/dpkg.h>
 #include <dpkg/macros.h>
 #include <dpkg/i18n.h>
 #include <dpkg/progname.h>
@@ -60,13 +62,15 @@ warning_get_count(void)
 void
 warningv(const char *fmt, va_list args)
 {
-	char buf[1024];
+	char *buf = NULL;
 
 	warn_count++;
-	vsnprintf(buf, sizeof(buf), fmt, args);
+
+	m_vasprintf(&buf, fmt, args);
 	fprintf(stderr, "%s%s:%s %s%s:%s %s\n",
 	        color_get(COLOR_PROG), dpkg_get_progname(), color_reset(),
 	        color_get(COLOR_WARN), _("warning"), color_reset(), buf);
+	free(buf);
 }
 
 void
@@ -82,27 +86,31 @@ warning(const char *fmt, ...)
 void
 notice(const char *fmt, ...)
 {
-	char buf[1024];
+	char *buf = NULL;
 	va_list args;
 
 	va_start(args, fmt);
-	vsnprintf(buf, sizeof(buf), fmt, args);
+	m_vasprintf(&buf, fmt, args);
 	va_end(args);
 
 	fprintf(stderr, "%s%s:%s %s\n",
 	        color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), buf);
+
+	free(buf);
 }
 
 void
 info(const char *fmt, ...)
 {
-	char buf[1024];
+	char *buf;
 	va_list args;
 
 	va_start(args, fmt);
-	vsnprintf(buf, sizeof(buf), fmt, args);
+	m_vasprintf(&buf, fmt, args);
 	va_end(args);
 
 	printf("%s%s:%s %s\n",
 	       color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), buf);
+
+	free(buf);
 }