summaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)Author
2023-09-27Actually use number correctly casted from double to int as indexEmanuele Torre
The code was using (int)jv_number_value(k) instead of (int)didx. follow-up from 0e067ef93605493060392f0999be27694146fca4 Useless assignments to didx detected by clang-tidy.
2023-09-27main.c: Remove unused EXIT_STATUS_EXACT optionEmanuele Torre
In process there is a suspicious options |= EXIT_STATUS_EXACT that is run when the jq script is terminated by halt, or halt_error. That line of code acutally does nothing because options is a local argument variable, and is not passed as a pointer. It was probably meant to be a *options |= EXIT_STATUS_EXACT with the options argument passed as a int*. In any case, we do not want to run the code in main() that was supposed to run if EXIT_STATUS_EXACT is set (but didn't since it is never added to options); as far as I can tell, we only want to run that code when the --exit-status/-e option is passed. So I removed EXIT_STATUS_EXACT completely, and the useless assignment, instead of fixing it since it was not used for anything else. Useless assignment detected by clang-tidy.
2023-09-27Remove a bunch of unused variables, and useless assignmentsEmanuele Torre
Detected by clang-tidy.
2023-09-27Remove unused nref accumulator in block_bind_libraryEmanuele Torre
detected as a warning compiling jq with clang.
2023-09-26Reject U+001F in string literals (fix #2909)itchyny
2023-09-22Fix the default colors to use 39, the default foreground color (#2904)taoky
2023-09-06Add setlocale() call (fix #1740)jq-1.7Nicolas Williams
2023-08-29Fix leak on too-large programs, OSS Fuzz issue 61349Nico Williams
A very large program can cause these leaks: ==758838== 7,820 (16 direct, 7,804 indirect) bytes in 2 blocks are definitely lost in loss record 17 of 28 ==758838== at 0x4848A23: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==758838== by 0x125D30: jv_mem_calloc (jv_alloc.c:153) ==758838== by 0x162ADE: compile (compile.c:1286) ==758838== by 0x162D4B: compile (compile.c:1304) ==758838== by 0x163697: block_compile (compile.c:1381) ==758838== by 0x11B5CA: jq_compile_args (execute.c:1245) ==758838== by 0x115E20: main (main.c:691) ==758838== ==758838== 1,674,694 (103,576 direct, 1,571,118 indirect) bytes in 1,177 blocks are definitely lost in loss record 28 of 28 ==758838== at 0x4843839: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==758838== by 0x125CD0: jv_mem_alloc (jv_alloc.c:141) ==758838== by 0x162B19: compile (compile.c:1289) ==758838== by 0x163697: block_compile (compile.c:1381) ==758838== by 0x11B5CA: jq_compile_args (execute.c:1245) ==758838== by 0x115E20: main (main.c:691) This commit fixes that. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61349
2023-08-27Improve handling of non-integer numeric indices (fix #2815)jq-1.7rc2Nicolas Williams
2023-08-27Make jq_get_lib_dirs return an empty array if JQ_LIBRARY_PATH is not setEmanuele Torre
For the jq_state used by the jq utility, the JQ_LIBRARY_PATH attribute will always be set, but, in general, it is possible that it might not be. If it is not set, jq_get_lib_dirs() will return jv_invalid(). That is not good, because some code in linker.c expects it to always returns an array. This patch makes jq_get_lib_dirs() return an empty array if JQ_LIBRARY_PATH is not set to prevent problems. This issue made OSS fuzz trigger failed assertions every time it tried to compile a script that uses "include". Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61796
2023-08-26Fix memory leak in find_lib for some invalid inputsEmanuele Torre
2023-08-25Check nomem_handler->handler before calling itNicolas Williams
2023-08-19Add --config option printing ./configure options usedNicolas Williams
2023-08-17Fix overflow on numeric comparison (#2849)itchyny
Although #2839 fixed the overflow of exponent subtraction, there still is possibility of overflow in the `D2U` macro. This patch fixes the overflow in the `D2U` macro, and also truncates the maximum digits to `DEC_MAX_DIGITS`.
2023-08-16Revert "Allow .[-1] in path expressions"itchyny
This reverts commit 086a156ec389de167edc72e8bd1752984b117349. This commit leads to negative indexing wraps twice.
2023-08-13Cast function pointers without prototype before calling them (#2842)Emanuele Torre
clang complained that this is deprecated in all versions of standard C, and unsupported in C2x.
2023-08-13Fix crash on numeric comparison again (ref #2825)itchyny
The decNumber library subtracts the exponents of two numbers, we make sure to limit the number of digits not to make it overflows. Since the maximum adjusted exponent is `emax` and the minimum is `emin - digits + 1`, we follow `emax - (emin - digits + 1) <= INT32_MAX`.
2023-08-13Rename jv_type_private.h to jv_private.h, move jvp_number_is_nan thereitchyny
2023-08-12Expose the names of a module's defined function via `modulemeta`Alex Wilson
This reuses the existing `block_list_funcs` capability and adds an extra field on the `modulemeta` output, called `defs`, containing that list of functions.
2023-08-12Build windows 64bit binary using UCRT64 (#2832)Mattias Wadman
* Build windows 64bit binary using UCRT64 Is the default and recommended msystem setting. Will produce binaries that are compatible with windows 10 and later. Also run tests for 32bit build. Related to #2831 * Use jq -b in tests/shtest * Add Windows strptime * Make Windows-optional tests not run on Windows again --------- Co-authored-by: Nicolas Williams <nico@cryptonector.com>
2023-08-10Make sure to init key and dbl_key also on win32Mattias Wadman
Hopefully fixes page fault for mingw build Related to #2831
2023-08-10Make sure to init dtoa_ctx_key also on win32 (#2834)Mattias Wadman
Fixes page fault for mingw build Related to #2831
2023-08-05Change the default color of null to Bright Blackitchyny
2023-08-04Let error(null) throw nullEmanuele Torre
This patch removes the weird behaviour of jv_invalid_with_msg(jv_null()) that returns jv_invalid() (i.e. empty), instead of a boxed jv_null(). The previous behaviour of null|error was obviously unintentional, and allowing is jv_invalid_with_msg() to return values on which you can't call jv_invalid_get_msg() is only error prone.
2023-08-04Constant fold all kinds of constantsEmanuele Torre
This patch exports all the binary operator builtins functions from builtin.c and uses them for constant folding in the parser, allowing constant folding to work will all kinds and combinations of constants. Now string*number, $ARGS+$ARGS, string/string, etc will also be constant folded and the implementation of constant folded operators and runtime operators will be the same. And thanks to the new ERRORK bytecode operation, errors are constant folded too! (e.g. 1 / 0 [] * {} etc)
2023-08-04Add ERRORK opcode to trigger constant errorsEmanuele Torre
2023-08-04Simplify String rule in parser (#2805)Emanuele Torre
Use a StringStart component that is either FORMAT QQSTRING_START or QQSTRING_START instead of having two similar rules for String. This is simpler and avoids having to use an untyped mid-rule action component to copy FORMAT at the top of the stack before QQString, and having to use jv_free($<literal>3) instead of jv_free($1) just to make bison not complain about the "unused" mid-rule component.
2023-08-03Fix crash on numeric comparison (ref #2804) (#2818)itchyny
2023-08-02Fix rounding small (but not too small) numbers to zero on calculationitchyny
Co-authored-by: Leonid S. Usov <leonid.s.usov@gmail.com>
2023-08-01Require a main program (fix #2785)Nicolas Williams
2023-07-31Re-generate src/parser.[ch]Nicolas Williams
2023-08-01Simple and efficient implementation of walk/1 (#2795)pkoppstein
2023-07-31Fix constant folding of division and reminder with zero divisoritchyny
Previously constant folding of zero division (e.x. 1/0) produces a compile error. This was incorrectly implemented by checking if the division result is infinite, so produces wrong results compared to the query where no constant folding is processed (e.x. 1e308/0.1). This patch delays the operation when the divisor is zero. This makes the results more consistent, but changes the exit code on zero division from 3 to 5. Also 0/0 now produces the zero division error, not NaN. This patch also fixes the modulo operation. Previously constant folding logic does not take care of the % operator, but now it folds if the both dividend and divisor are safe numbers to cast to the integer type, and the divisor is not zero. This patch also fixes some code that relies on undefined cast behaviors in C. The modulo operation produces NaN if either the dividend or divisor is NaN.
2023-07-31Declare cfunction.fptr as jv (*)() to avoid having to cast everywhereEmanuele Torre
You only need to specify the return type in a function pointer declaration in C. If you use () in the declaration, the function pointer can be called with any arguments, and the type of the arguments is decided for each function call based on the types of the arguments used for the call. (To declare a function pointer for a function with no arguments, you use `(void)'.) Since all the cfunction structs have a fptr that points to a functions that return jv, not void, we can we can just declare cfunction.fptr as jv (*)() and avoid having those annoying and technically not C-standard compliant casts everywhere.
2023-07-31Massage --help text to use max 72 characters widthMattias Wadman
2023-07-30Add JQ_FALLTHROUGH and use it to quiet warningsNicolas Williams
2023-07-28Allow .[-1] in path expressionsNicolas Williams
2023-07-27Fix memory leak for { $foo: bar }Emanuele Torre
{ BINDING: ExpD } wasn't freeing BINDING. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60865
2023-07-26Enable gamma, drem on macOSitchyny
2023-07-26Rename --nul-output to --raw-output0, abort on string containing NULitchyny
The option naming --nul-output was confusing, especially when we have a similar option for input stream in the future (--nul-input vs --null-input). Based on the observation of other command line tools, we rename the option to --raw-output0. We also drop the short option -0 to avoid confusion on introducing the NUL-delimited input option. Unlike the other command line tools outputting file names with NUL delimiter, jq deals with JSON, and its strings may contain NUL character. To protect users from the risk of injection attacks, we abort the program and print an error message before outputting strings including NUL character. Closes #2683.
2023-07-25builtin.jq: naive abs/0pkoppstein
manual.yml explains that the def is naive, and mentions fabs, etc.
2023-07-25Only care about RS when parsing with --seqEmanuele Torre
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-25Make sure to free default `@text` format on errorEmanuele Torre
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-25implode: Better invalid input validation and handlingMattias Wadman
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-25Remove deprecated --argfile optionitchyny
2023-07-25Align prompt in help exampleMattias Wadman
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-25Reorder the command line options in the manual (#2766)itchyny
2023-07-25builtin.jq: simpler and faster transpose (#2758)pkoppstein
2023-07-24Test that jq works in threadsTomas Halman
This patch implements test that searches a key in simple json in pthread.
2023-07-24Fix segmentation fault when using jq in threadsTomas Halman
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.