Bug 991: Replace '%s' by % in the mailcap.c
commita6966e94725cda2eb9e437e42bccb561682f2236
authorWitold Filipczyk <witekfl@poczta.gazeta.pl>
Fri, 7 Mar 2008 18:56:15 +0000 (7 19:56 +0100)
committerKalle Olavi Niemitalo <Kalle@Astalo.kon.iki.fi>
Sat, 8 Mar 2008 19:20:57 +0000 (8 21:20 +0200)
treea9ab23b4e96bd1b96d785ece326c2539fc201558
parent7bdeb3188e691c3944637cc8f0085d91b94519e5
Bug 991: Replace '%s' by % in the mailcap.c

Currently, when ELinks passes the name of a local file to an external
MIME handler program, it encodes the name as a URI.  Programs
typically do not expect this, and they then fail to open the file.
ELinks should instead quote the file name for the shell.
Unfortunately, Debian has lines like this in /etc/mailcap:

audio/mpeg; xmms '%s'; test=test "$DISPLAY" != ""

If ELinks were changed to replace the %s with e.g.
'/home/Kalle/doc/Topfield/How to upgraded the Firmware(English).pdf'
(quotes included), then the quotes would cancel out and the shell
would split the file name into multiple arguments.  That could even
provide a way for malicious persons to make ELinks run arbitrary
shell commands.

The examples in RFC 1524 all have %s without any quotes.
Debian has two bug reports about the quoting behaviour:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=90483
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=221717

This patch therefore tries to detect whether the %s has been quoted
already, and remove the quotes if so.  That way, the next patch will
be able to safely add its own quotes.  This removal of quotes applies
only to mailcap files; MIME handlers defined in elinks.conf should
already be in the format preferred by ELinks.

(The patch was attachment 438 of bug 991, by Witold Filipczyk.
 This commit message was written by Kalle Olavi Niemitalo.)
src/mime/backend/mailcap.c