Commit Graph
1532 Commits
Author SHA1 Message Date
pkoppstein 13fbe98dff manual.yml: remove contingent tests
Also clarify non-prescriptive nature of some tests in jq.test
2023-07-25 23:43:57 -05:00
pkoppstein 7b725378b9 builtin.jq: naive abs/0
manual.yml explains that the def is naive, and mentions fabs, etc.
2023-07-25 23:43:57 -05:00
Emanuele Torre 3a1ba0c42d Only care about RS when parsing with --seq
RS should only only have special meaning when parsing json-seq.
Before this fix, RS was sometimes treated as a value terminator, causing
weird results.

Bug discovered by OSS fuzz.
Ref: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60835
2023-07-25 16:42:32 -05:00
Emanuele Torre ae95864b6b Make sure to free default @text format on error
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).
2023-07-25 14:51:58 -05:00
Mattias Wadman a949745059 implode: Better invalid input validation and handling
Error on non-number and nan codepoint, would asserd before
Replace negative codepoint and surrogate range with unicode replacement character, would assert before

Fixes #1160
2023-07-25 13:38:41 -05:00
itchyny a29ac81de1 Remove deprecated --argfile option 2023-07-25 10:21:01 -05:00
Mattias Wadman bb8221efdc Align prompt in help example
Was accidentally unaligned in #2747

Now looks like this:

Example:

	$ echo '{"foo": 0}' | jq .
	{
	  "foo": 0
	}

Before looks like this:

Example:

	 $ echo '{"foo": 0}' | jq .
	{
		"foo": 0
	}
2023-07-25 15:10:50 +02:00
itchyny 4705a22c7d Reorder the command line options in the manual (#2766) 2023-07-25 15:24:54 +09:00
pkoppstein 8f49600a6b builtin.jq: simpler and faster transpose (#2758) 2023-07-25 09:12:23 +09:00
Emanuele Torre 330559643a Run autoconf -i in the Build step of the scanbuild workflow
Fixup from 54fef09ac3
2023-07-24 18:55:48 +02:00
Tomas Halman cca0087ee6 Test that jq works in threads
This patch implements test that searches a key in simple
json in pthread.
2023-07-24 11:55:15 -05:00
Tomas Halman 2dbae5610b Fix segmentation fault when using jq in threads
In previous code nomem_handler in jv_alloc.c is called only once
and therefore the structure is not initialized for second and
following threads.

This leads to segmentation fault in multi-threading environment.

This patch moves initialization of nomem_handler out of the
pthread_once call.
2023-07-24 11:55:15 -05:00
itchyny 5300fbda58 Add decnum workflow to test building without decNumber support 2023-07-24 11:53:51 -05:00
itchyny c4d5ba954d Improve USE_DECNUM check position 2023-07-24 11:53:51 -05:00
Mattias Wadman 54fef09ac3 Make maintainer-mode default to disabled
This makes the standard build instructions a bit easier,
just ./configure, and also requires less tools installed (bison).

Also i think few people probably want to generate the lexer and paser code.
2023-07-24 11:26:17 -05:00
Mattias Wadman 4cc99831e4 Free expected value on invalid actual for test
valgrind (3.19.0) locally on macOS docker container seems to detect this leak but not CI.

$ cat modulemeta.test
modulemeta | .deps |= length
"c"
{"whatever":null,"deps":6}

$ valgrind --error-exitcode=1 --leak-check=full -q ./jq --run-tests < modulemeta.test
Test #1: 'modulemeta | .deps |= length' at line number 1
*** Insufficient results for test at line number 3: modulemeta | .deps |= length
0 of 1 tests passed (0 malformed, 0 skipped)
==14129== 482 (392 direct, 90 indirect) bytes in 1 blocks are definitely lost in loss record 7 of 8
==14129==    at 0x48407B4: malloc (vg_replace_malloc.c:381)
==14129==    by 0x13BC78: jv_mem_alloc (jv_alloc.c:122)
==14129==    by 0x1371C6: jvp_object_new (jv.c:1521)
==14129==    by 0x145840: parse_token (jv_parse.c:167)
==14129==    by 0x145840: scan (jv_parse.c:684)
==14129==    by 0x145840: jv_parser_next (jv_parse.c:793)
==14129==    by 0x1463CB: jv_parse_sized (jv_parse.c:865)
==14129==    by 0x136BD9: run_jq_tests (jq_test.c:183)
==14129==    by 0x1370FA: jq_testsuite (jq_test.c:34)
==14129==    by 0x13135C: main (main.c:582)
==14129==
2023-07-24 11:16:22 -05:00
Mattias Wadman 16ae275d4c Fix leaks on invalid input for strftime, strflocaltime and mktime 2023-07-24 16:45:43 +02:00
David Korczynski 97c6d2848c Add fuzzer targeting load_file
Signed-off-by: David Korczynski <david@adalogics.com>
2023-07-24 15:45:12 +02:00
Emanuele Torre 8a4f246876 Remove all #define _GNU_SOURCE in source files
This is unnecessary since we are using AC_USE_SYSTEM_EXTENSIONS in
configure.ac, which makes the compiler always run with -D_GNU_SOURCE=1
when building for GNU/Linux.

Also, the  #define _GNU_SOURCE  in src/util.c, and in
src/inject_errors.c (--enable-inject-errors), were not guarded by a
#ifndef _GNU_SOURCE  so they were just triggering redefinition warnings.
2023-07-24 15:44:29 +02:00
David Korczynski cf3c11bde8 Add compile fuzzer for OSS-Fuzz
Signed-off-by: David Korczynski <david@adalogics.com>
2023-07-24 13:44:27 +02:00
itchyny ed334b536f Improve manual in various ways (inputs, sort_by, foreach sections, etc.) (#2744)
- Add error/0 and mentions null input behavior (close #2231)
- Explain value iterator suffix syntax .foo[] (close #1047)
- Mention array slicing is also zero-based (close #2094)
- Add examples of input and inputs filters (close #2216, close #2470)
- Improve sort_by about multiple values (close #2103, close #2467, close #2474)
- Improve foreach section and simplify examples (close #1148, close #2169)
- Fix recurse/1 document on how it is identical using recurse/2 (close #2036, close #2412)
- Add non-string examples of index/1, rindex/1 (close #1422)
- Simplify the example of truncate_stream/1 (close #1736)
2023-07-24 20:24:44 +09:00
Nico Williams 1cf6515c06 Fix try/catch catches more than it should #1859
Close #1885, #2140, #2011, #2220, #2485, #2073

Rename the FORK_OPT opcode to TRY_BEGIN, add a TRY_END opcode, and wrap
errors when raising through a TRY_END so that they will not be caught by
the matching TRY_BEGIN.

Now a `try exp catch handler` expression generates code like:

    TRY_BEGIN handler
    <exp>
    TRY_END
    JUMP past_handler
    handler: <handler>
    past_handler:
    ...

On backtrack through TRY_BEGIN it just backtracks.

If anything past the whole thing raises when <exp> produced a value,
then the TRY_END will catch the error, wrap it in another, and
backtrack.  The TRY_BEGIN will see a wrapped error and then it will
unwrap and re-raise the error.

If <exp> raises, then TRY_BEGIN will catch the error and jump to the
handler, but the TRY_BEGIN will not stack_save() in that case, so on
raise/backtrack the TRY_BEGIN will not execute again (nor will the
TRY_END).
2023-07-24 13:20:21 +02:00
itchyny 98f709d0c1 Fix stderr to output string with no decoration (fix #2063) 2023-07-23 17:06:00 -05:00
itchyny dfdce8c6e7 Add checksum signature of old release artifacts (close #1999) 2023-07-23 12:24:59 -05:00
Nicolas Williams f64ef1a7d7 Fix --stream-errors w/o --stream, and doc+test (close #2748) 2023-07-23 03:33:28 -05:00
itchyny 123c780607 Enable significand on macOS 2023-07-23 03:28:07 -05:00
itchyny 99a381b5aa Improve --help to mention all the command options 2023-07-23 03:26:44 -05:00
itchyny 575372222a Add importlib_resources dependency for older Python (fix #2753) (#2754) 2023-07-23 15:01:16 +09:00
itchyny 34629ed223 Fix manual source code to follow the schema definition 2023-07-22 19:00:16 -05:00
itchyny 9044f540bb Validate manual schema 2023-07-22 19:00:16 -05:00
itchyny c9c45d7f03 Add tests for --arg, --argjson, and similar options 2023-07-22 12:29:24 -05:00
itchyny 649d6b5f5e Update AUTHOR for the next release 2023-07-22 11:53:43 -05:00
itchyny e0e1b2293e Enable verbose output of make check 2023-07-21 19:49:48 -05:00
itchyny 3ed928954a Fail quickly if not in git repository in scripts/version 2023-07-21 08:59:17 -05:00
itchyny 4732dd82c0 Remove AppVeyor configuration (#2741) 2023-07-21 22:45:45 +09:00
pkoppstein 3553a9d617 manual.yml: some clarifications plus fixes for markdown bloopers (#2737) 2023-07-21 21:33:03 +09:00
itchyny 7c2bf9bd17 Clarify the Docker image location (close #1864) (#2740) 2023-07-21 20:42:11 +09:00
itchyny 99a77f724b Add a regression test for #2000 2023-07-21 09:01:28 +09:00
William Langford 515260213c Increment nlocals when compiling STORE_GLOBAL ops (#2000)
These are stored in vars, so we need to make sure that nlocals is large
enough to account for that
2023-07-21 09:01:16 +09:00
pkoppstein 3ec66c858c manual.yml: revise section on identity, clarifying what is subject to change
Mostly clarifications w.r.t. numbers.

The anomalous behavior of leading minus signs is documented, with an explicit notice that this will probably change.
2023-07-19 22:32:24 -05:00
Robert Aboukhalil a192e647c5 Move options to main and pass it to process 2023-07-19 13:07:46 -05:00
Robert Aboukhalil 4c25cf3f7c Reset options to 0 so can call main() multiple times in a row 2023-07-19 13:07:46 -05:00
itchyny f1c49473a3 Avoid getpwuid for static linking 2023-07-19 09:56:41 -05:00
itchyny f0306405c1 Add notes on NO_COLOR environment variable to the manual 2023-07-19 09:56:01 -05:00
itchyny 0615d4982c Respect NO_COLOR environment variable to disable color output 2023-07-19 00:05:41 -05:00
itchyny 87e3dfddb8 Enable valgrind in oniguruma workflow 2023-07-19 06:45:09 +02:00
0b558f6ed4 Make object key color configurable (close #1739, #1791, #2638)
Co-authored-by: David Haguenauer <ml@kurokatta.org>
Co-authored-by: Eric Pruitt <eric.pruitt@gmail.com>
2023-07-18 17:53:29 -05:00
Emanuele Torre 62d65a8a9c Fix memory leaks in --with-oniguruma=no implementation of f_match
Found by LeakSanitizer running  ./jq -n '"" | test("")'  in a
--with-oniguruma=no --enable-ubsan --enable-asan  build.
2023-07-18 14:45:20 -05:00
itchyny 0e3c3913d8 Add oniguruma workflow to test regex options 2023-07-18 14:28:16 -05:00
Emanuele Torre 7ffb7943d4 Fix signed integer overflow undefined behaviour in decNumber.c
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60691

  $ ./jq <<< 0E2202012202
  src/decNumber/decNumber.c:598:18: runtime error: signed integer overflow: 440402440 + 1761609760 cannot be represented in type 'int'
  0E+999999999

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

  $ ./jq <<< 5E7657765755
  src/decNumber/decNumber.c:598:18: runtime error: left shift of 765776575 by 3 places cannot be represented in type 'int'
  src/decNumber/decNumber.c:598:18: runtime error: signed integer overflow: 1531553150 + 1831245304 cannot be represented in type 'int'
  1.7976931348623157e+308
2023-07-18 14:03:40 -05:00