]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
pythonmod: add check return value after ftell() (#1478)
authorPetr Vaganov <petrvaganoff@gmail.com>
Thu, 23 Jul 2026 08:22:02 +0000 (15:22 +0700)
committerGitHub <noreply@github.com>
Thu, 23 Jul 2026 08:22:02 +0000 (10:22 +0200)
Variable 'flen', which might receive a negative value at pythonmod.c:493
by calling function 'ftell', is used without checking at pythonmod.c:508
by calling function 'fread'.

Found by the static analyzer Svace (ISP RAS).

Signed-off-by: Petr Vaganov <petrvaganoff@gmail.com>
pythonmod/pythonmod.c

index 1b077bb6f3c212f9a4aafd02b53463d463448720..045dd1bbd09ee580d20d210fb387f74f2523145c 100644 (file)
@@ -487,10 +487,17 @@ int pythonmod_init(struct module_env* env, int id)
       /* for python 3.9 and newer */
       char* fstr = NULL;
       size_t flen = 0;
+      long pos = 0;
       log_err("pythonmod: can't parse Python script %s", pe->fname);
       /* print the error to logs too, run it again */
       fseek(script_py, 0, SEEK_END);
-      flen = (size_t)ftell(script_py);
+      pos = ftell(script_py);
+      if (pos == -1L) {
+         log_err("ftell failed to print parse error: %s: %s",
+            pe->fname, strerror(errno));
+         goto fail_close_file;
+      }
+      flen = (size_t)pos;
 #ifdef SIZE_MAX
       if(flen > SIZE_MAX-2) {
                log_err("script file too large");