Skip to content

Commit

Permalink
Make sure to free default @text format on error
Browse files Browse the repository at this point in the history
It seems that bison doesn't call destructors for mid-rule action
components on error, since it does not know their type.

A mid-rule action was used to allocate the "text" string used as format
by string literals without a format, which would leak on error.
This patch replaces it with a new NoFormat component of type <literal>.
Now bison will call jv_free() on that string after a syntax error.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60836

  $ ./jq '"'
  jq: error: syntax error, unexpected end of file, expecting QQSTRING_TEXT or QQSTRING_INTERP_START or QQSTRING_END (Unix shell quoting issues?) at <top-level>, line 1:
  "
  jq: 1 compile error

  =================================================================
  ==1495450==ERROR: LeakSanitizer: detected memory leaks

  Direct leak of 21 byte(s) in 1 object(s) allocated from:
      #0 0x7fc21aee1359 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
      #1 0x557ccb6ff608 in jv_mem_alloc src/jv_alloc.c:141

  SUMMARY: AddressSanitizer: 21 byte(s) leaked in 1 allocation(s).
  • Loading branch information
emanuele6 committed Jul 25, 2023
1 parent a949745 commit e951581
Show file tree
Hide file tree
Showing 2 changed files with 413 additions and 399 deletions.
Loading

0 comments on commit e951581

Please sign in to comment.