]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix use-after-free
authordave-p <gh@pickles.me.uk>
Fri, 1 Jul 2022 13:56:09 +0000 (14:56 +0100)
committerFlole998 <Flole998@users.noreply.github.com>
Mon, 4 Jul 2022 00:22:44 +0000 (02:22 +0200)
Building Tvheadend on Raspberry Pi with gcc 12 fails with this error

src/misc/json.c: In function ‘json_parse_string’:
src/misc/json.c:120:31: error: pointer ‘r’ used after ‘free’ [-Werror=use-after-free]
  120 |                   *failp = (a - r) + start;
      |                            ~~~^~~~
src/misc/json.c:118:19: note: call to ‘free’ here
  118 |                   free(r);
      |                   ^~~~~~~

This PR appears correct and fixes the gcc error but has not been tested as it is an error path.

src/misc/json.c

index a1ee74486b1a5eb80bb2e379c55f5114cba671fe..27be484129b98a29f3192d571c27c67a8d9fa11f 100644 (file)
@@ -115,9 +115,9 @@ json_parse_string(const char *s, const char **endp,
                  v |= a[i] - 'F' + 10;
                  break;
                default:
-                 free(r);
                  *failmsg = "Incorrect escape sequence";
                  *failp = (a - r) + start;
+                 free(r);
                  return NULL;
                }
              }