texlive[61850] Build/source/texk/xdvik: check fseek returns

commits+karl at tug.org commits+karl at tug.org
Wed Feb 2 03:05:30 CET 2022


Revision: 61850
          http://tug.org/svn/texlive?view=revision&revision=61850
Author:   karl
Date:     2022-02-02 03:05:30 +0100 (Wed, 02 Feb 2022)
Log Message:
-----------
check fseek returns

Modified Paths:
--------------
    trunk/Build/source/texk/xdvik/ChangeLog
    trunk/Build/source/texk/xdvik/dvi-init.c

Modified: trunk/Build/source/texk/xdvik/ChangeLog
===================================================================
--- trunk/Build/source/texk/xdvik/ChangeLog	2022-02-02 00:49:30 UTC (rev 61849)
+++ trunk/Build/source/texk/xdvik/ChangeLog	2022-02-02 02:05:30 UTC (rev 61850)
@@ -1,3 +1,9 @@
+2022-02-01  John Hawkinson  <jhawk at alum.mit.edu>
+
+	* dvi-init.c (make_backup_fp): check returns from fseeks,
+	disable useTempFp if failure. Posted at
+	https://tug.org/pipermail/tlbuild/2022q1/005129.html
+
 2022-01-31  Karl Berry  <karl at freefriends.org>
 
 	* dvi-init.c (file_exists_p): check for failed fstat.

Modified: trunk/Build/source/texk/xdvik/dvi-init.c
===================================================================
--- trunk/Build/source/texk/xdvik/dvi-init.c	2022-02-02 00:49:30 UTC (rev 61849)
+++ trunk/Build/source/texk/xdvik/dvi-init.c	2022-02-02 02:05:30 UTC (rev 61850)
@@ -1170,17 +1170,13 @@
     if (first_time) { /* doesn't exist yet, create it */
 	if ((tmp_fd = xdvi_temp_fd(&m_tmp_dvi_name)) == -1) {
 	    XDVI_ERROR((stderr, "error creating temporary file - disabling `useTempFp'."));
-	    resource.use_temp_fp = False;
-	    remove_tmp_dvi_file(NULL);
-	    return NULL;
+	    goto fail;
 	}
 	/* 	fprintf(stderr, "temporary file name: |%s|, %d\n", m_tmp_dvi_name, tmp_fd); */
 	TRACE_EVENTS((stderr, "Created temp file: |%s|\n", m_tmp_dvi_name));
 	if ((target_fp = try_fdopen(tmp_fd, "wb+")) == NULL) {
 	    XDVI_ERROR((stderr, "error opening temporary file (%s) - disabling `useTempFp'.", strerror(errno)));
-	    resource.use_temp_fp = False;
-	    remove_tmp_dvi_file(NULL);
-	    return NULL;
+	    goto fail;
 	}
 	first_time = False;
     }
@@ -1189,19 +1185,22 @@
 	ASSERT(target_fp != NULL, "");
 	ASSERT(source_fp != NULL, "");
 
+	if (fseek(target_fp, 0L, SEEK_SET)) {
+	  XDVI_ERROR((stderr, "Couldn't seek to start of file %s: %s - disabling `useTempFp'; target_fp: %p.",
+			m_tmp_dvi_name, strerror(errno), target_fp));
+	  goto fclose_and_fail;
+	}
 #if HAVE_FTRUNCATE
 	if (ftruncate(tmp_fd, 0) < 0) {
-
 	    XDVI_ERROR((stderr, "Couldn't truncate file %s: %s - disabling `useTempFp'; target_fp: %p.",
 			m_tmp_dvi_name, strerror(errno), target_fp));
-	    resource.use_temp_fp = False;
-	    remove_tmp_dvi_file(NULL);
-	    fclose(target_fp);
-	    return NULL;
+	    goto fclose_and_fail;
 	}
 #endif
-	fseek(target_fp, 0L, SEEK_SET);
-	fseek(source_fp, 0L, SEEK_SET);
+	if (fseek(source_fp, 0L, SEEK_SET)) {
+	  perror("fseek of source_fp");
+	  goto fclose_and_fail;
+	}
     }
 
     /* copy the file */
@@ -1210,10 +1209,7 @@
 		    "Error creating temporary file: %s\n"
 		    "- disabling `useTempFp'.",
 		    strerror(errno)));
-	remove_tmp_dvi_file(NULL);
-	resource.use_temp_fp = False;
-	fclose(target_fp);
-	target_fp = NULL;
+	goto fclose_and_fail;
     }
     
     /* rewind both files, else DVI parsing will fail! */
@@ -1220,12 +1216,25 @@
     if (target_fp != NULL) {
 	fflush(target_fp);
     }
-    fseek(source_fp, 0L, SEEK_SET);
+    if (fseek(source_fp, 0L, SEEK_SET)) {
+      perror("fseek of source_fp after rewind");
+    }
     if (target_fp != NULL) {
-	fseek(target_fp, 0L, SEEK_SET);
+      if (fseek(target_fp, 0L, SEEK_SET)) {
+	perror("fseek of target_fp again");
+      }
     }
     
     return target_fp;
+
+ fclose_and_fail:
+    fclose(target_fp);
+    /* FALLTHROUGH */
+ fail:
+    resource.use_temp_fp = False;
+    remove_tmp_dvi_file(NULL);
+    return NULL;
+
 }
 
 static Boolean



More information about the tex-live-commits mailing list.