chiark / gitweb /
Fix 3x not checking fread return value
authorMatthew Vernon <matthew@debian.org>
Fri, 7 Nov 2025 13:32:46 +0000 (13:32 +0000)
committerMatthew Vernon <matthew@debian.org>
Fri, 7 Nov 2025 14:35:30 +0000 (14:35 +0000)
Again, found by using newer build tooling.

tsl.c

diff --git a/tsl.c b/tsl.c
index d5946a2129c0268406f71089645dbf1bf2f20fd6..c0090c601813e16e8027c5e2bc905233fc09a574 100644 (file)
--- a/tsl.c
+++ b/tsl.c
 |
 \*----------------------------------------------------------------------*/
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -286,7 +287,8 @@ int tsl_scan_concordance(const char *target, ref_t *sbuf, ref_t range_start,
     /* Read all the refs for this word */
     /* Where do they end? */
     fseek( cfp, (int)(inx_start + univ2int(cfh.data_ptr)), SEEK_SET );
-    fread( tbuf, 1, rsize, cfp );
+    if (fread( tbuf, 1, rsize, cfp ) < (size_t)rsize)
+      tsl_error(TRUE, "Reading %d refs: %s", rsize, strerror(errno));
 
     /* Process the ref list.
        Expand compressed references.
@@ -682,12 +684,14 @@ void tsl_init(char *dfname,char *path, const int memlimit)
            /* Allocate & initialize buffer for strings (all words) */
            i=univ2int(cfh.index_ptr) - univ2int(cfh.word_ptr);
            cf_words = malloc( i );
-           fread( cf_words, 1, i, cfp );
+           if (fread( cf_words, 1, i, cfp ) < (size_t)i)
+             tsl_error( TRUE, "reading initialised buffer for strings");
 
            /* Allocate & initialize buffer for index */
            i=univ2int(cfh.data_ptr) - univ2int(cfh.index_ptr);
            cf_index = (short int *) malloc( i );
-           fread( cf_index, 1, i, cfp );
+           if (fread( cf_index, 1, i, cfp ) < (size_t)i)
+             tsl_error( TRUE, "reading initialised buffer for index");
            /* Convert from Short_Univ_Int to short int */
            sup = (Short_Univ_Int *) cf_index;
            for (i=0; i<=univ2int(cfh.word_cnt); i++) {