summaryrefslogtreecommitdiff
path: root/Build/source/texk
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-02-02 02:05:30 +0000
committerKarl Berry <karl@freefriends.org>2022-02-02 02:05:30 +0000
commit6ffd1b4f4e34cea21daf384d1c9e0314a612db33 (patch)
treeaf7eaba87e7513d856fa0ab2b3d3ad88b72cb365 /Build/source/texk
parent13edb5d020f8c8da1799062101c51efdd6399be7 (diff)
check fseek returns
git-svn-id: svn://tug.org/texlive/trunk@61850 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk')
-rw-r--r--Build/source/texk/xdvik/ChangeLog6
-rw-r--r--Build/source/texk/xdvik/dvi-init.c47
2 files changed, 34 insertions, 19 deletions
diff --git a/Build/source/texk/xdvik/ChangeLog b/Build/source/texk/xdvik/ChangeLog
index 9068838026c..76c0cf33b17 100644
--- a/Build/source/texk/xdvik/ChangeLog
+++ b/Build/source/texk/xdvik/ChangeLog
@@ -1,3 +1,9 @@
+2022-02-01 John Hawkinson <jhawk@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@freefriends.org>
* dvi-init.c (file_exists_p): check for failed fstat.
diff --git a/Build/source/texk/xdvik/dvi-init.c b/Build/source/texk/xdvik/dvi-init.c
index ed568b1400b..829bd58080b 100644
--- a/Build/source/texk/xdvik/dvi-init.c
+++ b/Build/source/texk/xdvik/dvi-init.c
@@ -1170,17 +1170,13 @@ make_backup_fp(FILE *source_fp, FILE *target_fp)
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 @@ make_backup_fp(FILE *source_fp, FILE *target_fp)
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,22 +1209,32 @@ make_backup_fp(FILE *source_fp, FILE *target_fp)
"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! */
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