texlive[50106] Build/source/texk/makejvf: makejvf: forbid invalid

commits+hironobu at tug.org commits+hironobu at tug.org
Sat Feb 23 23:34:30 CET 2019


Revision: 50106
          http://tug.org/svn/texlive?view=revision&revision=50106
Author:   hironobu
Date:     2019-02-23 23:34:30 +0100 (Sat, 23 Feb 2019)
Log Message:
-----------
makejvf: forbid invalid usages

Modified Paths:
--------------
    trunk/Build/source/texk/makejvf/ChangeLog
    trunk/Build/source/texk/makejvf/main.c
    trunk/Build/source/texk/makejvf/tfmread.c
    trunk/Build/source/texk/makejvf/version.h

Modified: trunk/Build/source/texk/makejvf/ChangeLog
===================================================================
--- trunk/Build/source/texk/makejvf/ChangeLog	2019-02-23 22:18:42 UTC (rev 50105)
+++ trunk/Build/source/texk/makejvf/ChangeLog	2019-02-23 22:34:30 UTC (rev 50106)
@@ -1,3 +1,14 @@
+2019-02-23  Hironobu Yamashita  <h.y.acetaminophen at gmail.com>
+
+	* main.c, tfmread.c: Forbid invalid usages.
+	  - Make sure the output TFM does not have the same
+	    basename as the input TFM.
+	  - Options -J, -U, -3, -H are useless in non-UCS mode,
+	    throw a warning and ignore.
+	  - Options -J and -U cannot be used at the same time,
+	    throw an error.
+	* version.h: Bump version.
+
 2019-02-19  Hironobu Yamashita  <h.y.acetaminophen at gmail.com>
 
 	* tfmread.c, tool.c: Avoid compiler warnings for fgetc().

Modified: trunk/Build/source/texk/makejvf/main.c
===================================================================
--- trunk/Build/source/texk/makejvf/main.c	2019-02-23 22:18:42 UTC (rev 50105)
+++ trunk/Build/source/texk/makejvf/main.c	2019-02-23 22:34:30 UTC (rev 50106)
@@ -27,7 +27,6 @@
 	while ((c = getopt (argc, argv, "k:K:Ca:b:mu:3J:U:Hiet:")) != -1)
 		switch (c) {
 
-
 		case 'k':
 			kanatume = atoi(optarg);
 			break;
@@ -111,17 +110,14 @@
 		exit(0);
 	}
 
-	atfmname = xmalloc(strlen(argv[optind])+4);
-	strcpy(atfmname, argv[optind]);
+	atfmname = xstrdup(argv[optind]);
+	if (FILESTRCASEEQ(&atfmname[strlen(atfmname)-4], ".tfm")) {
+		atfmname[strlen(atfmname)-4] = '\0';
+	}
 
-	{
-		const char *p = xbasename(argv[optind]);
-		vfname = xmalloc(strlen(p)+4);
-		strcpy(vfname, p);
-	}
-	if (FILESTRCASEEQ(&vfname[strlen(vfname)-4], ".tfm")) {
-		vfname[strlen(vfname)-4] = '\0';
-	}
+	const char *atfmname_base = xbasename(atfmname);
+	vfname = xmalloc(strlen(atfmname_base)+4);
+	strcpy(vfname, atfmname_base);
 	strcat(vfname,".vf");
 
 	vtfmname = xstrdup(argv[optind+1]);
@@ -128,9 +124,65 @@
 	if (FILESTRCASEEQ(&vtfmname[strlen(vtfmname)-4], ".tfm")) {
 		vtfmname[strlen(vtfmname)-4] = '\0';
 	}
+	if (FILESTRCASEEQ(&vtfmname[0], &atfmname_base[0])) {
+		fprintf(stderr,"Invalid usage: input TFM and output TFM must be different.\n");
+		exit(100);
+	}
 
-	tfmget(atfmname);
+	if (kanatfm) {
+		if (FILESTRCASEEQ(&kanatfm[strlen(kanatfm)-4], ".tfm")) {
+			kanatfm[strlen(kanatfm)-4] = '\0';
+		}
+		if (FILESTRCASEEQ(&kanatfm[0], &atfmname_base[0])) {
+			fprintf(stderr,"Invalid usage: input TFM and output TFM must be different.\n");
+			exit(100);
+		}
+	}
 
+	if (!ucs) {
+		if (jistfm) {
+			fprintf(stderr,"[Warning] Option -J invalid in non-UCS mode, ignored.\n");
+			jistfm = NULL;
+		}
+		if (ucsqtfm) {
+			fprintf(stderr,"[Warning] Option -U invalid in non-UCS mode, ignored.\n");
+			ucsqtfm = NULL;
+		}
+		if (useset3) {
+			fprintf(stderr,"[Warning] Option -3 invalid in non-UCS mode, ignored.\n");
+			useset3 = 0;
+		}
+		if (hankana) {
+			fprintf(stderr,"[Warning] Option -H invalid in non-UCS mode, ignored.\n");
+			hankana = 0;
+		}
+	}
+
+	if (jistfm && ucsqtfm) {
+		fprintf(stderr,"Options -J and -U at the same time? I'm confused.\n");
+		exit(100);
+	}
+
+	if (jistfm) {
+		if (FILESTRCASEEQ(&jistfm[strlen(jistfm)-4], ".tfm")) {
+			jistfm[strlen(jistfm)-4] = '\0';
+		}
+		if (FILESTRCASEEQ(&jistfm[0], &atfmname_base[0])) {
+			fprintf(stderr,"Invalid usage: input TFM and output TFM must be different.\n");
+			exit(100);
+		}
+	}
+
+	if (ucsqtfm) {
+		if (FILESTRCASEEQ(&ucsqtfm[strlen(ucsqtfm)-4], ".tfm")) {
+			ucsqtfm[strlen(ucsqtfm)-4] = '\0';
+		}
+		if (FILESTRCASEEQ(&ucsqtfm[0], &atfmname_base[0])) {
+			fprintf(stderr,"Invalid usage: input TFM and output TFM must be different.\n");
+			exit(100);
+		}
+	}
+
 	if (usertable) {
 		get_usertable(usertable);
 	}
@@ -144,6 +196,8 @@
 		exit(101);
 	}
 
+	tfmget(atfmname);
+
 	vfp = vfopen(vfname);
 
 	pstfm_nt=1; /* initialize */
@@ -164,9 +218,6 @@
 	vfclose(vfp);
 
 	if (kanatfm) {
-		if (FILESTRCASEEQ(&kanatfm[strlen(kanatfm)-4], ".tfm")) {
-			kanatfm[strlen(kanatfm)-4] = '\0';
-		}
 		maketfm(kanatfm);
 		pstfm_nt=1; /* already done*/
 	}
@@ -174,19 +225,9 @@
 	maketfm(vtfmname);
 	pstfm_nt=1; /* already done*/
 
-	if (jistfm) {
-		if (FILESTRCASEEQ(&jistfm[strlen(jistfm)-4], ".tfm")) {
-			jistfm[strlen(jistfm)-4] = '\0';
-		}
-		maketfm(jistfm);
-	}
+	if (jistfm) maketfm(jistfm);
 
-	if (ucsqtfm) {
-		if (FILESTRCASEEQ(&ucsqtfm[strlen(ucsqtfm)-4], ".tfm")) {
-			ucsqtfm[strlen(ucsqtfm)-4] = '\0';
-		}
-		maketfm(ucsqtfm);
-	}
+	if (ucsqtfm) maketfm(ucsqtfm);
 
 	exit(0);
 }

Modified: trunk/Build/source/texk/makejvf/tfmread.c
===================================================================
--- trunk/Build/source/texk/makejvf/tfmread.c	2019-02-23 22:18:42 UTC (rev 50105)
+++ trunk/Build/source/texk/makejvf/tfmread.c	2019-02-23 22:34:30 UTC (rev 50106)
@@ -93,20 +93,17 @@
 
 int tfmget(char *name)
 {
-	char nbuff[1024];
+	char *nbuff;
 	FILE *fp;
 
-	if (strlen(name) >= 1020) { /* <buffer size> - ".tfm" */
-		fprintf(stderr,"Too long input file name.\n");
-		exit(1);
-	}
+	nbuff = xmalloc(strlen(name)+4);
 	strcpy(nbuff,name);
+	strcat(nbuff,".tfm");
 	fp = fopen(nbuff,"rb");
 	if (fp == NULL) {
-		strcat(nbuff,".tfm");
-		fp = fopen(nbuff,"rb");
+		fp = fopen(name,"rb"); /* just in case ... */
 		if (fp == NULL) {
-			fprintf(stderr,"%s is not found.\n",name);
+			fprintf(stderr,"Cannot open %s for input.\n",nbuff);
 			exit(1);
 		}
 	}

Modified: trunk/Build/source/texk/makejvf/version.h
===================================================================
--- trunk/Build/source/texk/makejvf/version.h	2019-02-23 22:18:42 UTC (rev 50105)
+++ trunk/Build/source/texk/makejvf/version.h	2019-02-23 22:34:30 UTC (rev 50106)
@@ -1,2 +1,2 @@
-#define VERSION "20190210"
+#define VERSION "20190223"
 #define BUG_ADDRESS "issue at texjp.org"



More information about the tex-live-commits mailing list