X-Git-Url: http://git.savannah.gnu.org/gitweb/?p=enscript.git;a=blobdiff_plain;f=src%2Fpsgen.c;h=a55cc8b4be28f430375ebaecb2c4f14a91f94d06;hp=e132683b3d26e6a00168dcf7d544a26c75c47571;hb=45a1785f9dc58826fe7e0d2dcd7ed91dc1c62ea9;hpb=a3e6bf57e48bb7434cdd590732e221fd2e0b4c17 diff --git a/src/psgen.c b/src/psgen.c index e132683..a55cc8b 100644 --- a/src/psgen.c +++ b/src/psgen.c @@ -22,7 +22,9 @@ * along with Enscript. If not, see . */ +#include #include "gsint.h" +#include /* * Types and definitions. @@ -122,7 +124,7 @@ struct gs_token_st double xscale; double yscale; int llx, lly, urx, ury; /* Bounding box. */ - char filename[512]; + char filename[PATH_MAX]; char *skipbuf; unsigned int skipbuf_len; unsigned int skipbuf_pos; @@ -133,11 +135,11 @@ struct gs_token_st Color bgcolor; struct { - char name[512]; + char name[PATH_MAX]; FontPoint size; InputEncoding encoding; } font; - char filename[512]; + char filename[PATH_MAX]; } u; }; @@ -246,7 +248,7 @@ static int do_print = 1; static int user_fontp = 0; /* The user ^@font{}-defined font. */ -static char user_font_name[256]; +static char user_font_name[PATH_MAX]; static FontPoint user_font_pt; static InputEncoding user_font_encoding; @@ -976,7 +978,8 @@ large for page\n"), FATAL ((stderr, _("user font encoding can be only the system's default or `ps'"))); - strcpy (user_font_name, token.u.font.name); + memset (user_font_name, 0, sizeof(user_font_name)); + strncpy (user_font_name, token.u.font.name, sizeof(user_font_name) - 1); user_font_pt.w = token.u.font.size.w; user_font_pt.h = token.u.font.size.h; user_font_encoding = token.u.font.encoding; @@ -1442,7 +1445,7 @@ read_special_escape (InputStream *is, Token *token) buf[i] = ch; if (i + 1 >= sizeof (buf)) FATAL ((stderr, _("too long argument for %s escape:\n%.*s"), - escapes[i].name, i, buf)); + escapes[e].name, i, buf)); } buf[i] = '\0'; @@ -1450,7 +1453,8 @@ read_special_escape (InputStream *is, Token *token) switch (escapes[e].escape) { case ESC_FONT: - strcpy (token->u.font.name, buf); + memset (token->u.font.name, 0, sizeof(token->u.font.name)); + strncpy (token->u.font.name, buf, sizeof(token->u.font.name) - 1); /* Check for the default font. */ if (strcmp (token->u.font.name, "default") == 0) @@ -1463,7 +1467,8 @@ read_special_escape (InputStream *is, Token *token) FATAL ((stderr, _("malformed font spec for ^@font escape: %s"), token->u.font.name)); - strcpy (token->u.font.name, cp); + memset (token->u.font.name, 0, sizeof(token->u.font.name)); + strncpy (token->u.font.name, cp, sizeof(token->u.font.name) - 1); xfree (cp); } token->type = tFONT; @@ -1542,7 +1547,8 @@ read_special_escape (InputStream *is, Token *token) break; case ESC_SETFILENAME: - strcpy (token->u.filename, buf); + memset (token->u.filename, 0, sizeof(token->u.filename)); + strncpy (token->u.filename, buf, sizeof(token->u.filename) - 1); token->type = tSETFILENAME; break; @@ -2006,8 +2012,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 = "%%"; @@ -2016,25 +2021,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) { @@ -2180,13 +2171,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)