Package: file
Version: 4.24-2
Severity: normal
Tags: patch

When I made my original change suggested in Bug#481512 (libmagic1:
"couldn't open file"  doesn't say which file or why), I ran into a crash
in strlen from vasprintf caused by a regression introduced between 4.23
and 4.24 upstream, in the file_error_core function in funcs.c.  As I
reported upstream (in a message entitled "distressingly obscure error
message on failing to open a file"), the file_printf(ms, f, va) line -
the one with the unusual indentation - is passing a va_list to a
printf-style function rather than a vprintf-style function.  I suggested
that file_printf should be renamed file_vprintf and given a va_list
argument and submitted a patch, which Christos accepted, saying:

"Thanks a lot, I applied your fix."

I didn't try very hard to reproduce this with an unpatched file but what
attempts I did make, failed.  So perhaps this is unimportant but, if
anyone else finds themselves with a more compelling reason to apply the
patch before 4.25 comes out, I have attached it here.

-- System Information:
Debian Release: lenny/sid
  APT prefers oldstable
  APT policy: (500, 'oldstable'), (500, 'unstable'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.24-1-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored:
LC_ALL set to en_US.UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages libmagic1 depends on:
ii  libc6                  2.7-11            GNU C Library: Shared
libraries
ii  zlib1g                 1:1.2.3.3.dfsg-12 compression library -
runtime

libmagic1 recommends no packages.

Versions of packages file depends on:
ii  libc6                         2.7-11     GNU C Library: Shared
libraries

-- no debconf information
--- funcs.c	2008-03-07 07:00:07.000000000 -0800
+++ funcs.c	2008-05-16 09:55:16.000000000 -0700
@@ -45,18 +45,15 @@
  * Like printf, only we append to a buffer.
  */
 protected int
-file_printf(struct magic_set *ms, const char *fmt, ...)
+file_vprintf(struct magic_set *ms, const char *fmt, va_list ap)
 {
-	va_list ap;
 	size_t size;
 	int len;
 	char *buf, *newstr;
 
-	va_start(ap, fmt);
 	len = vasprintf(&buf, fmt, ap);
 	if (len < 0)
 		goto out;
-	va_end(ap);
 
 	if (ms->o.buf != NULL) {
 		len = asprintf(&newstr, "%s%s", ms->o.buf, buf);
@@ -73,6 +70,18 @@
 	return -1;
 }
 
+protected int
+file_printf(struct magic_set *ms, const char *fmt, ...)
+{
+	va_list ap;
+	int len;
+	
+	va_start(ap, fmt);
+	len = file_vprintf(ms, fmt, ap);
+	va_end(ap);
+	return len;
+}
+
 /*
  * error - print best error message possible
  */
@@ -89,7 +98,7 @@
 		ms->o.buf = NULL;
 		file_printf(ms, "line %u: ", lineno);
 	}
-        file_printf(ms, f, va);
+	file_vprintf(ms, f, va);
 	if (error > 0)
 		file_printf(ms, " (%s)", strerror(error));
 	ms->haderr++;

Reply via email to