Apply patch from Debian Security Team for CAN-2004-1184.
[enscript.git] / src / psgen.c
index 8d7a34209532bcb906d4191ab0fa42a30d6d2ce3..b827fe10aff66ac540e5aade687c2496ead9dbef 100644 (file)
@@ -6,25 +6,24 @@
  */
 
 /*
- * This file is part of GNU enscript.
+ * This file is part of GNU Enscript.
  *
- * This program is free software; you can redistribute it and/or modify
+ * Enscript is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * Enscript is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING.  If not, write to
- * the Free Software Foundation, 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * along with Enscript.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "gsint.h"
+#include <libgen.h>
 
 /*
  * Types and definitions.
@@ -2008,8 +2007,7 @@ get_next_token (InputStream *is, double linestart, double linepos,
 static void
 dump_ps_page_header (char *fname, int empty)
 {
-  char buf[512];
-  char *ftail;
+  char *dirc, *basec, *fdir, *ftail;
   int got, i;
   char *cp, *cp2;
   char *cstr = "%%";
@@ -2018,25 +2016,11 @@ dump_ps_page_header (char *fname, int empty)
   /* The N-up printing sub-page. */
   nup_subpage = (total_pages - 1) % nup;
 
-  /* Create fdir and ftail. */
-  ftail = strrchr (fname, '/');
-
-#if defined(WIN32)
-  if (ftail == NULL)
-    ftail = strrchr (fname, '\\');
-#endif /* WIN32 */
-
-  if (ftail == NULL)
-    {
-      buf[0] = '\0';
-      ftail = fname;
-    }
-  else
-    {
-      ftail++;
-      strncpy (buf, fname, ftail - fname);
-      buf[ftail - fname] = '\0';
-    }
+  /* Split fname into fdir and ftail. */
+  dirc = strdup(fname);
+  basec = strdup(fname);
+  fdir = dirname(dirc);
+  ftail = basename(basec);
 
   if (nup > 1)
     {
@@ -2182,13 +2166,15 @@ dump_ps_page_header (char *fname, int empty)
   OUTPUT ((cofp, "/fname (%s) def\n", cp));
   xfree (cp);
 
-  cp = escape_string (buf);
+  cp = escape_string (fdir);
   OUTPUT ((cofp, "/fdir (%s) def\n", cp));
   xfree (cp);
+  xfree (dirc);
 
   cp = escape_string (ftail);
   OUTPUT ((cofp, "/ftail (%s) def\n", cp));
   xfree (cp);
+  xfree (basec);
 
   /* Do we have a pending ^@font{} font? */
   if (user_fontp)
@@ -2378,6 +2364,7 @@ recognize_eps_file (Token *token)
 {
   int i;
   char buf[4096];
+  char *filename;
   int line;
   int valid_epsf;
   float llx, lly, urx, ury;
@@ -2385,52 +2372,34 @@ recognize_eps_file (Token *token)
   MESSAGE (2, (stderr, "^@epsf=\"%s\"\n", token->u.epsf.filename));
 
   i = strlen (token->u.epsf.filename);
-  if (i > 0 && token->u.epsf.filename[i - 1] == '|')
-    {
-      /* Read EPS data from pipe. */
-      token->u.epsf.pipe = 1;
-      token->u.epsf.filename[i - 1] = '\0';
-      token->u.epsf.fp = popen (token->u.epsf.filename, "r");
-      if (token->u.epsf.fp == NULL)
-       {
-         MESSAGE (0, (stderr,
-                      _("epsf: couldn't open pipe to command \"%s\": %s\n"),
-                      token->u.epsf.filename, strerror (errno)));
-         return 0;
-       }
-    }
-  else
-    {
-      char *filename;
 
-      /* Read EPS data from file. */
-      filename = tilde_subst (token->u.epsf.filename);
+  /* Read EPS data from file. */
+  filename = tilde_subst (token->u.epsf.filename);
 
-      token->u.epsf.fp = fopen (filename, "rb");
-      xfree (filename);
+  token->u.epsf.fp = fopen (filename, "rb");
+  xfree (filename);
 
-      if (token->u.epsf.fp == NULL)
+  if (token->u.epsf.fp == NULL)
+    {
+      if (token->u.epsf.filename[0] != '/')
        {
-         if (token->u.epsf.filename[0] != '/')
-           {
-             /* Name is not absolute, let's lookup path. */
-             FileLookupCtx ctx;
+         /* Name is not absolute, let's lookup path. */
+         FileLookupCtx ctx;
 
-             ctx.name = token->u.epsf.filename;
-             ctx.suffix = "";
-             ctx.fullname = buffer_alloc ();
+         ctx.name = token->u.epsf.filename;
+         ctx.suffix = "";
+         ctx.fullname = buffer_alloc ();
 
-             if (pathwalk (libpath, file_lookup, &ctx))
-               token->u.epsf.fp = fopen (buffer_ptr (ctx.fullname), "rb");
+         if (pathwalk (libpath, file_lookup, &ctx))
+           token->u.epsf.fp = fopen (buffer_ptr (ctx.fullname), "rb");
 
-             buffer_free (ctx.fullname);
-           }
-         if (token->u.epsf.fp == NULL)
-           {
-             MESSAGE (0, (stderr, _("couldn't open EPS file \"%s\": %s\n"),
-                          token->u.epsf.filename, strerror (errno)));
-             return 0;
-           }
+         buffer_free (ctx.fullname);
+       }
+      if (token->u.epsf.fp == NULL)
+       {
+         MESSAGE (0, (stderr, _("couldn't open EPS file \"%s\": %s\n"),
+                      token->u.epsf.filename, strerror (errno)));
+         return 0;
        }
     }