diff options
Diffstat (limited to 'Build/source/texk/web2c/mplibdir/mpost.w')
-rw-r--r-- | Build/source/texk/web2c/mplibdir/mpost.w | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/Build/source/texk/web2c/mplibdir/mpost.w b/Build/source/texk/web2c/mplibdir/mpost.w index d4066e84192..54147b24ec6 100644 --- a/Build/source/texk/web2c/mplibdir/mpost.w +++ b/Build/source/texk/web2c/mplibdir/mpost.w @@ -1,4 +1,4 @@ -% $Id: mpost.w 1219 2010-04-01 09:05:51Z taco $ +% $Id: mpost.w 1422 2010-10-19 07:26:52Z taco $ % % Copyright 2008-2009 Taco Hoekwater. % @@ -69,6 +69,7 @@ static char *job_area = NULL; static int dvitomp_only = 0; static int ini_version_test = false; @<getopt structures@>; +@<Declarations@>; @ Allocating a bit of memory, with error detection: @@ -209,8 +210,11 @@ static string normalize_quotes (const char *name, const char *mesg) { @ Helpers for the filename recorder. -@c -static void recorder_start(char *jobname) { +@<Declarations@>= +void recorder_start(char *jobname); + +@ @c +void recorder_start(char *jobname) { char cwd[1024]; if (jobname==NULL) { recorder_name = mpost_xstrdup("mpout.fls"); @@ -235,6 +239,9 @@ static void recorder_start(char *jobname) { int fmt; boolean req; (void) mpx; + if ((mode[0]=='r' && !kpse_in_name_ok(nam)) || + (mode[0]=='w' && !kpse_out_name_ok(nam))) + return NULL; /* disallowed filename */ if (mode[0] != 'r') { return strdup(nam); } @@ -282,6 +289,8 @@ static int mpost_run_make_mpx (MP mp, char *mpname, char *mpxname) { } else { tmp = normalize_quotes(mpname, "mpname"); } + if (!kpse_in_name_ok(tmp)) + return 0; /* disallowed filename */ qmpname = kpse_find_file (tmp,kpse_mp_format, true); mpost_xfree(tmp); if (qmpname != NULL && job_area != NULL) { @@ -297,13 +306,13 @@ static int mpost_run_make_mpx (MP mp, char *mpname, char *mpxname) { int nothingtodo = 0; if ((stat(qmpxname, &target_stat) >= 0) && (stat(qmpname, &source_stat) >= 0)) { -#if HAVE_STRUCT_STAT_ST_MTIM - if (source_stat.st_mtim.tv_sec <= target_stat.st_mtim.tv_sec || +#if HAVE_ST_MTIM + if (source_stat.st_mtim.tv_sec < target_stat.st_mtim.tv_sec || (source_stat.st_mtim.tv_sec == target_stat.st_mtim.tv_sec && - source_stat.st_mtim.tv_nsec <= target_stat.st_mtim.tv_nsec)) + source_stat.st_mtim.tv_nsec < target_stat.st_mtim.tv_nsec)) nothingtodo = 1; #else - if (source_stat.st_mtime <= target_stat.st_mtime) + if (source_stat.st_mtime < target_stat.st_mtime) nothingtodo = 1; #endif } @@ -423,6 +432,8 @@ static int mpost_run_dvitomp (char *dviname, char *mpxname) { mpost_xfree (m); m = s ; } + if (!(kpse_in_name_ok(d) && kpse_out_name_ok(m))) + return EXIT_FAILURE; /* disallowed filename */ mpxopt->mpname = d; mpxopt->mpxname = m; @@ -454,7 +465,7 @@ static int get_random_seed (void) { #if defined (HAVE_GETTIMEOFDAY) struct timeval tv; gettimeofday(&tv, NULL); - ret = (int)(tv.tv_usec + 1000000 * tv.tv_usec); + ret = (tv.tv_usec + 1000000 * tv.tv_usec); #elif defined (HAVE_FTIME) struct timeb tb; ftime(&tb); @@ -477,6 +488,9 @@ static char *mpost_find_file(MP mp, const char *fname, const char *fmode, int ft char *s; (void)mp; s = NULL; + if ((fmode[0]=='r' && !kpse_in_name_ok(fname)) || + (fmode[0]=='w' && !kpse_out_name_ok(fname))) + return NULL; /* disallowed filename */ if (fmode[0]=='r') { if ((job_area != NULL) && (ftype>=mp_filetype_text || ftype==mp_filetype_program )) { @@ -494,10 +508,10 @@ static char *mpost_find_file(MP mp, const char *fname, const char *fmode, int ft struct stat source_stat, target_stat; char *mpname = mpost_xstrdup(f); *(mpname + strlen(mpname) -1 ) = '\0'; - printf("statting %s and %s\n", mpname, f); + /* printf("statting %s and %s\n", mpname, f); */ if ((stat(f, &target_stat) >= 0) && (stat(mpname, &source_stat) >= 0)) { -#if HAVE_STRUCT_STAT_ST_MTIM +#if HAVE_ST_MTIM if (source_stat.st_mtim.tv_sec <= target_stat.st_mtim.tv_sec || (source_stat.st_mtim.tv_sec == target_stat.st_mtim.tv_sec && source_stat.st_mtim.tv_nsec <= target_stat.st_mtim.tv_nsec)) @@ -588,8 +602,11 @@ processing takes place. As a special hidden feature, a missing right hand side is treated as if it was the integer value |1|. -@c -static void internal_set_option(const char *opt) { +@<Declarations@>= +void internal_set_option(const char *opt); + +@ @c +void internal_set_option(const char *opt) { struct set_list_item *itm; char *s, *v; int isstring = 0; @@ -628,8 +645,11 @@ static void internal_set_option(const char *opt) { runs thourgh the list of options and feeds them to the MPlib function |mp_set_internal|. -@c -static void run_set_list (MP mp) { +@<Declarations@>= +void run_set_list (MP mp); + +@ @c +void run_set_list (MP mp) { struct set_list_item *itm; itm = set_list; while (itm!=NULL) { @@ -727,7 +747,7 @@ static struct option mpost_options[] } if (ARGUMENT_IS ("kpathsea-debug")) { - kpathsea_debug |= atoi (optarg); + kpathsea_debug |= (unsigned)atoi (optarg); } else if (ARGUMENT_IS("jobname")) { if (optarg!=NULL) { @@ -830,7 +850,7 @@ static struct option dvitomp_options[] } if (option_is ("kpathsea-debug")) { if (optarg!=NULL) - kpathsea_debug |= atoi (optarg); + kpathsea_debug |= (unsigned)atoi (optarg); } else if (option_is ("progname")) { user_progname = optarg; } else if (option_is("help")) { @@ -994,13 +1014,11 @@ static int setup_var (int def, const char *var_name, boolean nokpse) { mpost_xfree(options->banner); options->banner = mpost_xmalloc(strlen(banner)+ strlen(mpversion)+ - strlen(WEB2CVERSION)+ strlen(kpsebanner_start)+ strlen(kpathsea_version_string)+ strlen(kpsebanner_stop)+1); strcpy (options->banner, banner); strcat (options->banner, mpversion); - strcat (options->banner, WEB2CVERSION); strcat (options->banner, kpsebanner_start); strcat (options->banner, kpathsea_version_string); strcat (options->banner, kpsebanner_stop); @@ -1110,9 +1128,10 @@ so we have to fix up |job_name| and |job_area|. If there was a \.{--jobname} on the command line, we have to reset the options structure as well. -@d IS_DIR_SEP(c) (c=='/' || c=='\\') - @<Discover the job name@>= +#ifndef IS_DIR_SEP +#define IS_DIR_SEP(c) (c=='/' || c=='\\') +#endif { char *tmp_job = NULL; if (options->job_name != NULL) { @@ -1232,18 +1251,12 @@ int main (int argc, char **argv) { /* |start_here| */ @= /*@@=nullpass@@*/ @> if(putenv(xstrdup("engine=metapost"))) fprintf(stdout,"warning: could not set up $engine\n"); - options->main_memory = setup_var (50000,"main_memory",nokpse); - options->hash_size = (unsigned)setup_var (16384,"hash_size",nokpse); - options->max_in_open = setup_var (25,"max_in_open",nokpse); - options->param_size = setup_var (1500,"param_size",nokpse); options->error_line = setup_var (79,"error_line",nokpse); options->half_error_line = setup_var (50,"half_error_line",nokpse); options->max_print_line = setup_var (100,"max_print_line",nokpse); @<Set up the banner line@>; @<Copy the rest of the command line@>; - if (options->ini_version!=(int)true) { - @<Discover the mem name@>; - } + @<Discover the mem name@>; @<Discover the job name@>; @<Register the callback routines@>; mp = mp_initialize(options); |