Fix security issue with gv.

When GV detects that the document is either a PDF file or a
GZip compressed file, it executes some commands with the help of the
system() function. Unfortunately, these commands contain the
filename, which can be considered as untrusted user input. It is then
possible to distribute a file (with a meticulously chosen filename,
that even seems innocent) that causes execution of arbitrary
shell commands when it is read with GV.

http://www.epita.fr/~bevand_m/asa/asa-0000
This commit is contained in:
brad 2002-10-04 18:29:14 +00:00
parent 6709a2465e
commit 36a9392a98
4 changed files with 83 additions and 4 deletions

View File

@ -1,13 +1,12 @@
# $OpenBSD: Makefile,v 1.17 2001/11/13 22:13:24 espie Exp $
# $OpenBSD: Makefile,v 1.18 2002/10/04 18:29:14 brad Exp $
COMMENT= "PostScript and PDF previewer"
DISTNAME= gv-3.5.8
PKGNAME= ${DISTNAME}p1
CATEGORIES= print
NEED_VERSION= 1.496
MASTER_SITES= ftp://ftpthep.physik.uni-mainz.de/pub/gv/unix/
# GPL
PERMIT_PACKAGE_CDROM= Yes
PERMIT_PACKAGE_FTP= Yes
@ -17,7 +16,6 @@ PERMIT_DISTFILES_FTP= Yes
LIB_DEPENDS= Xaw3d.6.1::x11/Xaw3d
RUN_DEPENDS= :ghostscript-*:print/ghostscript/gnu
CONFIGURE_STYLE= imake
INSTALL_TARGET=install install.man install.doc

View File

@ -0,0 +1,26 @@
$OpenBSD: patch-source_file_c,v 1.1 2002/10/04 18:29:14 brad Exp $
--- source/file.c.orig Fri Jun 6 18:00:00 1997
+++ source/file.c Fri Oct 4 14:20:31 2002
@@ -285,6 +285,22 @@ file_fileIsNotUseful(fn)
}
/*############################################################*/
+/* file_nameIsDangerous */
+/*############################################################*/
+
+char *file_charsAllowedInName = "+,-./:=@\\^_";
+
+int
+file_nameIsDangerous(fn)
+ char *fn;
+{
+ for (; *fn; fn++)
+ if (!isalnum(*fn) && !strchr(file_charsAllowedInName, *fn))
+ return(1);
+ return(0);
+}
+
+/*############################################################*/
/* file_pdfname2psname */
/* If the file ends in .pdf, change this to .ps.*/
/* Return pointer to temp copy if changed, else to input string. */

View File

@ -0,0 +1,18 @@
$OpenBSD: patch-source_file_h,v 1.1 2002/10/04 18:29:14 brad Exp $
--- source/file.h.orig Fri Apr 25 18:00:00 1997
+++ source/file.h Fri Oct 4 14:20:31 2002
@@ -70,6 +70,14 @@ extern int file_fileIsNotUseful (
#endif
);
+extern char *file_charsAllowedInName;
+
+extern int file_nameIsDangerous (
+#if NeedFunctionPrototypes
+ char *
+#endif
+);
+
extern char* file_pdfname2psname (
#if NeedFunctionPrototypes
char * /* name */

View File

@ -0,0 +1,37 @@
$OpenBSD: patch-source_ps_c,v 1.1 2002/10/04 18:29:14 brad Exp $
--- source/ps.c.orig Fri Jun 6 18:00:00 1997
+++ source/ps.c Fri Oct 4 14:20:31 2002
@@ -420,6 +420,16 @@ psscan(fileP,filename,filename_raw,filen
char cmd[512];
char s[512];
filename_unc=file_getTmpFilename(NULL,filename_raw);
+ if (file_nameIsDangerous(filename))
+ {
+ INFMESSAGE(the filename is dangerous)
+ sprintf(s, "The filename \"%s\" is dangerous: only alphanumeric "
+ "characters and \"%s\" are allowed.\n",
+ filename, file_charsAllowedInName);
+ NotePopupShowMessage(s);
+ ENDMESSAGE(psscan)
+ return(NULL);
+ }
sprintf(cmd,cmd_uncompress,filename,filename_unc);
INFMESSAGE(is compressed)
INFSMESSAGE(uncompress command,cmd)
@@ -491,6 +501,16 @@ unc_ok:
char cmd[512];
char s[512];
filename_dsc=file_getTmpFilename(NULL,filename_raw);
+ if (file_nameIsDangerous(filename))
+ {
+ INFMESSAGE(the filename is dangerous)
+ sprintf(s, "The filename \"%s\" is dangerous: only alphanumeric "
+ "characters and \"%s\" are allowed.\n",
+ filename, file_charsAllowedInName);
+ NotePopupShowMessage(s);
+ ENDMESSAGE(psscan)
+ return(NULL);
+ }
sprintf(cmd,cmd_scan_pdf,filename,filename_dsc);
INFMESSAGE(is PDF)
INFSMESSAGE(scan command,cmd)