Commit Graph
83 Commits
Author SHA1 Message Date
Emanuele Torre 9afc450930 COPYING: adding missing line from decNumber's licence
Fixes #3079

Also clarify what files the Kungliga Tekniska Högskolan copyright notice
applies to.
2024-05-01 16:41:44 +02:00
Emanuele Torre 5bbd02f581 jv_setpath: fix leak when indexing an array with an array
arrays[arrays] is a special case of "INDEX" that actually returns an
array containing the indices in which the array that is being indexed
contains the start of the key array.

So array keys, for array values, are a kind of key that can be "got",
but not "set". jv_setpath() was not freeing the value it "got" from
indexing that key, in case the following "set" on that key failed,
resulting in a leak.

    $ ./jq -n '[] | setpath([[1]]; 1)'
    jq: error (at <unknown>): Cannot update field at array index of array

    =================================================================
    ==953483==ERROR: LeakSanitizer: detected memory leaks

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

    SUMMARY: AddressSanitizer: 272 byte(s) leaked in 1 allocation(s).

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66061
2024-03-28 18:10:38 +01:00
Emanuele Torre ce2638af40 jv_aux.c: replace jv_array_foreach with regular loop in jv_dels()
The code was only conditionally using the value
2024-03-28 12:12:39 +01:00
Emanuele Torre ea78b5a030 jv_array_indexes: remove a bunch of unnecessary copies/gets 2024-03-28 12:12:39 +01:00
Emanuele Torre 22a03e9e06 @base64d: fix unhandled overflow
$ ./jq-before -n '238609295*"|||"|@base64d|"."'
    src/builtin.c:718:29: runtime error: signed integer overflow: 715827885 * 3 cannot be represented in type 'int'
    jq: error: cannot allocate memory
    Aborted (core dumped)

    $ ./jq-after -n '238609295*"|||"|@base64d|"."'
    jq: error (at <unknown>): string ("||||||||||...) is not valid base64 data

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67640
2024-03-27 10:16:15 +01:00
Emanuele Torre b6da71bf68 declare static arrays const where possible
Some static arrays that could be readonly memory were declared mutable.
2024-03-20 00:22:54 +01:00
Emanuele Torre bc96146825 builtin.c: jv2tm: fix UB and accept array inputs with not all the values
Now, time functions accept array inputs even if they don't have all the
elements, 0 will be assumed if a value is not present.

Also, jv2tm now properly clamps large number values to a signed 32-bit
integer and rejects nan.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65885
2024-03-19 02:01:53 +01:00
Emanuele Torre 10ea3c7d9f util.c: update strptime to revision 1.66 2024-03-18 19:10:21 +01:00
Emanuele Torre d777b6570c util.c: fix _WIN32 port of strptime (#3071)
In windows, time_t is a signed 32-bit integer type, so TIME_MAX needs to
be declared as INT32_MAX instead of INT64_MAX.

Also bump NetBSD's strptime to revision 1.65 from 1.63 to fix undefined
behaviour (signed integer overflow) bugs.

Related NetBSD problem report:
https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=58041

Noticed thanks to a compiler warning in the windows build CI.

I declared the d variable as  time_t  instead of as  unsigned  to ensure
that the signedness/size of  TIME_MAX-d  in the  sse > TIME_MAX-d check
is always correct, and to prevent -Wsign-compare warnings from
triggering in the windows build.
2024-03-18 17:22:59 +01:00
Emanuele Torre 1411ce63d5 strftime/1: fix validation of non-string argument with number input
There was a incorrect else, that caused jq to not ensure that the
argument to strftime/1 is a string when the input is a number; this ends
up calling jv_string_value on a non-string value, which does not work,
and causes an assert failure.

Also fix same bug in strflocaltime/1.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67403
2024-03-15 14:30:23 +01:00
Emanuele Torre 6f67bae60b EACH: fix leak when an error is triggered by non-last element of object
Object keys are strings, so they need to be freed.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66070
2024-03-15 14:30:03 +01:00
Emanuele Torre fc9ecd71b3 tests: run tests in C locale
Fixes #3038
2024-02-10 18:23:50 +01:00
Emanuele Torre 13e02ba348 docs: rename example jq utility to total
Apparently sum(1) is a BSD and GNU coreutil used to compute the
"16-bit BSD checksum" of a file.
2024-01-30 12:23:33 -06:00
Emanuele Torre bd3c828f98 libm.h+builtin.c: add and use LIBM_DA and LIBM_DA_NO macros
For functions that from one double return an array with two numbers.
2024-01-26 16:16:25 -06:00
Emanuele Torre 605836b263 builtin.c: fix build with -Woverlength-strings
C99 only allows string literals long at most 4095 characters.
jq_builtins was a lot longer than that.

I rewrote all the optional libm error stubs in C so the value of
jq_builtins is not build dependent.

I replaced the command that generates builtin.inc with a POSIX compliant
od|sed command that encodes builtin.jq as a comma delimited list of
octal numbers (that can be embedded in C using a {} literal).

I also added -Woverlength-strings to AM_CFLAGS to verify that the
problem is fixed.

Fixes #1481
2024-01-26 16:16:25 -06:00
Emanuele Torre 7bdc9a7a63 Makefile.am: fix lines indented with tabs instead of spaces 2024-01-26 16:13:35 -06:00
Emanuele Torre 1f1e619f4e builtins: make ltrimstr and rtrimstr error for non-string inputs
Previously, ltrimstr/rtrimstr would just let the input pass through for
non-string inputs or arguments.

That was happening because, they were leaking the errors returned by
startswith/endswith treating them as if they were jv_false().
The leak was resolved by #2977 for 1.7.1

This patch rewrites ltrimstr and rtrimstr in jq, and makes them not
ignore startswith and endswith errors anymore.
2024-01-16 16:57:37 -06:00
Emanuele Torre 71e7bcdfc1 Revert "lexer: temporarily revert #\ patch; keep CR in comment bug fix"
This reverts commit 5d95791a67.
2024-01-16 16:08:03 -06:00
Emanuele Torre 71c2ab509a Merge pull request from GHSA-686w-5m7m-54vc
decNumberToString calls for a buffer that can hold a string of digits+14
characters, not a buffer of size digits+14.
We need to allocate an extra byte for the NUL byte.

-10E-1000010001, for example, will be stringified as -1.0E-1000010000
and decNumberToString will currently write an extra NUL byte after the
allocated buffer in the heap.

Originally reported by @SEU-SSL on GitHub.

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

Fixes GHSA-686w-5m7m-54vc
2023-12-13 20:20:22 +01:00
Emanuele Torre c9a5156521 Merge pull request from GHSA-7hmr-442f-qc8j
The unit allocated for decNumberCompare was accidentally removed by
commit 680baeffeb (PR #2804)

This caused a stack overflow when comparing a nan with a payload of 1000
or more.

This bug was found by OSS-fuzz.
Ref: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64771
Fixes GHSA-7hmr-442f-qc8j

It also fixes 1e999999999 > 1e-1147483646   triggering UBSAN errors
Fixes #2968
2023-12-13 20:17:17 +01:00
Emanuele Torre c5fd64ba97 jv_parse: let decNumberFromString/strtod parse complex nans as a NaN
Before this patch (when using decNumber), "Nan123" was parsed as a NaN,
only if the first n was uppercase.
2023-12-13 20:14:31 +01:00
Emanuele Torre dcf9a8e580 NEWS.md: fix markdown syntax; mention more bug fixs; list cves (#2987) 2023-12-13 18:39:24 +01:00
Emanuele Torre 5d95791a67 lexer: temporarily revert #\ patch; keep CR in comment bug fix
This commit temporarily reverts the commit that allows #\ "tcl-style"
comments everywhere and documents them, for the 1.7.1 patch release
cca1f7d18f.

\r is removed from the list of characters not allowed in a comment to
preserve that bugfix.
2023-12-13 16:38:18 +01:00
Emanuele Torre 511d50b15b ltrimstr/1+rtrimstr/1: don't leak on invalid input or arguments
ltrimstr/rtrimstr was ignoring and leaking the error returned by
f_startswith()/f_endswith().

This also means that they just let the input pass through for non-string
inputs or arguments.

Only fix the leak for now; in the next release, #2969 will make them
rethrow the error returned by startswith/endswith.

Ref: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64946
2023-12-13 15:13:46 +01:00
Emanuele Torre 7298972551 Makefile.am: don't use -lshlwapi to build jq on WIN32
It does not need it, only libjq needs this.
2023-12-13 13:08:57 +01:00
Emanuele Torre 19453a60cf ci.yml: use sysctl -n hw.logicalcpu instead of nproc on macos
The "macos (arm64)" runner on github does not have nproc.

/Users/runner/work/_temp/f44f0d9f-19eb-4a23-860e-26533d7efdfa.sh: line 10: nproc: command not found
2023-12-11 22:02:42 +01:00
Emanuele Torre 527c5abab1 jv_mem_calloc(): always call with (nmemb, size)
It does not matter much since they most likely just get multiplied
together, but some compilers would complain about this if these were
calls to calloc.
2023-12-11 20:47:32 +01:00
Emanuele Torre c2db51eeb3 shtest+configure: remove uses of non-portable/non-standard commands
Replace deprecated test(1) parentheses and -a logical operator with two
tests command.

Replace deprecated  tail -1  with  tail -n1.

Replace non-standard egrep(1) command with  grep -E  ; this also
prevents obsolescence warnings on GNU systems.
2023-12-11 20:46:54 +01:00
Emanuele Torre 507eb8283c shtest: fix out-of-source tests
The locale test was using ./jq intead of $JQ.

I also removed the use of obsolete egrep instead of grep -E that
triggers warnings on GNU systems, and the use of deprecated head -1
instead of head -n1.

Also removed the unnecessary hiding of strptime/1 errors with
? // false.
2023-12-11 20:45:14 +01:00
Emanuele Torre 7e54d9646e jq.test: fix setpath PR number
It was #2970, not 2967.
2023-12-11 09:58:09 +01:00
Emanuele Torre 6b69ffe769 jv_setpath()+setpath/2: don't leak the input after an invalid get
Ref: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64906
2023-12-10 19:40:29 +01:00
Emanuele Torre 80bc768c5d jq_fuzz_fixed: fix test cases that use string interpolation
"\(" is implementation-defined in C++, and both clang and gcc treat it
as equivalent to "(", not "\\(".
This patch replaces "\(" with "\\(" so that tests with string
interpolation actually use string interpolation.
2023-12-10 15:22:03 +01:00
Emanuele Torre 1617091033 website: use https URLs instead of http URLs in download page
Also add markdown formatting for decNumber URL so it gets rendered as a
link in the html page.
2023-11-29 09:35:36 +01:00
Emanuele Torre 460a5c12b4 jq_fuzz_parse_extended.c: don't jv_free() twice
jv_dump() frees its argument.

I missed this problem before merging #2952, whoops! =)

fixup from eb3b5654bb
2023-11-28 20:51:07 +01:00
Emanuele Torre 6c035133e8 README.md: tosed => to sed (#2944) 2023-11-06 23:59:22 +09:00
Emanuele Torre cca1f7d18f Comment bug fixes, and fully support Tcl-style multiline comments
* bugfix: comments were incorrectly being terminated by CR; for example
    jq -n $'1 #foo\r'
  fails to compile because the CR character terminates the comment, and
  CR is not a valid character in jq syntax.

* improvement: comments fully support Tcl-style line continuation.
  Previously this was only "supported" in `-f' scripts, whose first line
  starts with "#!", and second line starts with # and ends with \, only
  for the comment on the second line, only for one extra line.

* man: document comment syntax, which was previously undocumented.

* tests: add regression tests for the bugfix, and some tests for line
  continuation in comments.
2023-11-03 15:52:02 -05:00
Emanuele Torre f4929f3c19 src/builtin.c: remove unnecessary jv_copy-s in type_error/type_error2
Also fix doubled semicolon   jv ret;;   =>   jv ret;
2023-10-30 22:12:27 -05:00
Emanuele Torre d5590f90da jvp_object_contains: remove unnecessary jv_copy 2023-10-30 22:12:27 -05:00
Emanuele Torre e85e358233 Fix possible uninitialised value dereference if jq_init() fails
If jq_init() fails, goto out would try to free input_state which is
uninitialised. I initialised input_state to NULL to fix the problem.

Ref: https://github.com/jqlang/jq/pull/2934#discussion_r1367795641

Reported-By: Klemens Nanni <kn@openbsd.org>
2023-10-22 10:51:24 -05:00
Emanuele Torre 9de0e26ce6 Generate links in man page
Some [foo](bar) links were added to manual.yml without updating
build_manpage.py to make it generate roff for "a" tags.

Fixes #2930
2023-10-12 15:32:23 -05:00
Emanuele Torre 6b6feaffbb Revert "Revert "od -c => od -tc: od -c is an XSI extension..."
This reverts commit 0e70f7a57e.

There is no reason to revert this change.

In #2922, I only disagreed with the commit message suggesting that
  LC_CTYPE=C od -t c    is   equivalent to   od -c

The only documented differences are that -tc is required to be
influenced by -N and -j, while -c is not, and that -c is required to
only support a subset of the backslash sequences that -tc should
support.
2023-10-05 15:37:44 +02:00
Emanuele Torre 4ebd21e1eb Allow passing the inline jq script before --
jq previously only allowed passing the inline script before -- (as if
they were options) even though one would expect the inline script to be
a positional argument.

Since jq previously also refused to run with a usage error if the script
was passed after -- (It was not assuming  .  as script as it does when
no arguments are passed), and positional arguments are allowed before --
and even before other options, it should not be a breaking change to
change that weird behaviour, and allow the script to appear after --.

It also simplifies the option parsing code a bunch.

Fixes #2918
2023-10-04 00:00:46 -05:00
Emanuele Torre 6b5a18f036 Actually use number correctly casted from double to int as index
The code was using (int)jv_number_value(k) instead of (int)didx.

follow-up from 0e067ef936

Useless assignments to didx detected by clang-tidy.
2023-09-27 22:54:23 -05:00
Emanuele Torre 8206bc8fd2 main.c: Remove unused EXIT_STATUS_EXACT option
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-27 21:52:23 -05:00
Emanuele Torre 623ace27e8 Remove a bunch of unused variables, and useless assignments
Detected by clang-tidy.
2023-09-27 21:50:44 -05:00
Emanuele Torre 2b709727a9 Remove unused nref accumulator in block_bind_library
detected as a warning compiling jq with clang.
2023-09-27 21:50:44 -05:00
Emanuele Torre ab47880b4c Make jq_get_lib_dirs return an empty array if JQ_LIBRARY_PATH is not set
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-27 00:37:54 -05:00
Emanuele Torre 6436f1e0f8 Fix memory leak in find_lib for some invalid inputs 2023-08-26 17:17:29 -05:00
Emanuele Torre 4cf1408e0b Cast function pointers without prototype before calling them (#2842)
clang complained that this is deprecated in all versions of standard C,
and unsupported in C2x.
2023-08-13 22:39:54 +09:00
Emanuele Torre f94a9d463f Let error(null) throw null
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-04 17:38:52 -05:00
Emanuele Torre 3b6e7ddd72 Constant fold all kinds of constants
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-04 11:47:34 -05:00
Emanuele Torre 5fc5453409 Add ERRORK opcode to trigger constant errors 2023-08-04 11:47:34 -05:00
Emanuele Torre dcaf701ef6 Simplify String rule in parser (#2805)
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-04 08:21:25 +09:00
Emanuele Torre 96263f2e4b Don't unnecessarily ignore missing-field-initializers warnings 2023-07-31 23:16:02 -05:00
Emanuele Torre 6716e23ae6 Declare cfunction.fptr as jv (*)() to avoid having to cast everywhere
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-31 15:28:01 -05:00
Emanuele Torre a6eb055c47 Fix typo in manual: "-seq" => "--seq" 2023-07-29 18:27:59 -05:00
Emanuele Torre 17889a1a85 Fix memory leak for { $foo: bar }
{ BINDING: ExpD } wasn't freeing BINDING.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60865
2023-07-27 20:59:35 -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
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
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
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
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
Emanuele Torre 15fd31de78 Define examples in the "examples" field instead of "example"
Only examples defined in the "examples" field are generated, if they are
defined in "example", they are just ignored.

Also fix a bunch of incorrect tests.
2023-07-18 12:12:50 -05:00
Emanuele Torre 01dfd8b86d Populate captures also for zero-width matches
Instead of just using {"captures":[]}.

sub functions are use captures for replacement expressions.
If we don't populate, captures for empty matches, the replacement
expression is run with an empty object as input instead of an object
containing the named captures with "" as value:

* before:

  $ jq -n '"123foo456bar" | gsub("[^a-z]*(?<x>[a-z]*)"; "Z\(.x)")'
  "ZfooZbarZnull"

* after:

  $ jq -n '"123foo456bar" | gsub("[^a-z]*(?<x>[a-z]*)"; "Z\(.x)")'
  "ZfooZbarZ"

---

I also removed a redundant

  result = NULL;
  if (result) {
    ...
  }
2023-07-18 12:12:50 -05:00
Emanuele Torre bb0f898c01 Initialise jq_state->debug_cb{,_data} to NULL
To make debug/0 not call an uninitialised function pointer when using
--run-tests or when using a jq_state on which jq_set_debug_cb() has not
been called.
2023-07-18 12:12:50 -05:00
Emanuele Torre 4b3090a9ab Make stream parser error when a non-empty object or array is used as key
Fixes #2463
2023-07-17 13:15:55 -05:00
Emanuele Torre e79335e3a5 Initialise jq_state->input_cb{,_data} to NULL in jq_init()
To avoid causing segmentation faults when  input/1  is called in a
jq_state on which  jq_set_input_cb()  has not been called; e.g. the one
used by  jq --run-tests.

That segfault could also be fixed in run_jq_tests() by calling:

  jq_set_input_cb(jq, NULL, NULL);

But I think it makes sense to just make jq_init() initialise those
values to NULL.

Ref: https://github.com/jqlang/jq/pull/2717#discussion_r1264338841
2023-07-16 00:03:46 -05:00
Emanuele Torre 1915b689f7 Fix indices/1 and rindex/1 in case of overlapping matches in strings
Fixes #2433
2023-07-14 23:40:37 -05:00
Emanuele Torre bf4390562f Add workflow that runs tests with valgrind on linux
To hopefully detect when we introduce new memory leaks. :-)
2023-07-15 01:29:13 +02:00
Emanuele Torre 4b1ac7c95f Parse nan in JSON as NaN instead of triggering a parse error (#2712)
* Fix memory leak for has(nan)

jv_array_get() used to be responsible of freeing the input array, but
since b5c4c3d67d, it is no longer called
if the key is nan. We need to free it manually to avoid leaking the
array.

* Parse  nan  in JSON as NaN instead of triggering a parse error

Fixes #2021
2023-07-14 07:12:27 +09:00
Emanuele Torre 55249e29be Also run manpage.yml workflow on pull requests that modify the manual 2023-07-13 06:20:11 +02:00
Emanuele Torre ab2779e2e5 Mark src/decNumber/** as vendored files
This excludes those files from the Languages statistics on github.
2023-07-12 11:14:39 -05:00
Emanuele Torre c99981c5b2 Update "tests/man.test" and remove superflous whitespace in manual.yml
tests/man.test was generated incorrectly and had some duplicate tests,
the new CI workflow didn't like that.
2023-07-11 00:24:50 -05:00
Emanuele Torre c049061084 Fix build_manpage.py with newer markdown versions
The markdown python changed its API for markdown extensions.

Bumping the markdown package version in previous commits broke
docs/build_manpage.py since it was using registering an extension with
the old API.
2023-07-11 00:24:50 -05:00
Emanuele Torre 83d4dd16ad Add CI workflow to make sure the man page and man.test can be built
And that man.test is up to date.
2023-07-11 00:24:50 -05:00
Emanuele Torre 2377972dfe Use jinja2 ==3.0.2 for now
We are using some deprecated jinja2 features that have been removed in
newer versions.
2023-07-10 16:19:52 -05:00
Emanuele Torre 7fba85095b Update docs/Pipfile.lock 2023-07-10 15:23:00 -05:00
Emanuele Torre fc1bef0261 Mark generated manual files as linguist-generated=true 2023-07-10 15:23:00 -05:00
Emanuele Torre 6ca7973d49 Allow using { $__loc__ } as shorthand for { __loc__: $__loc__ }
n.b.: { $__loc__: "foo" }  is still not allowed.

$__loc__ cannot be overwritten, and it is always an object.
Using { $x: "foo" } where $x is not a string is an error, so there is
not much of a point in supporting that.
2023-07-10 12:04:54 -05:00
Emanuele Torre 193f432e08 Lex $foo as a single token, instead of using '$' IDENT
Previously, bindings were parsed as the combination of two tokens:
  '$' IDENT

This meant that using a keyword as variable name (e.g. $then, $label)
did not work.
Attempts were made to allow $keyword to work by adding some '$' Keyword
rules in the parser, but this did not allow $keyword in all places:

  jq --arg label foo -n '$label'  # ok

  jq -n '"foo" as $label | .'     # error

Treating $foo as a single token is much simpler, in my opinion.

This patch also changes how LOC is lexed: "$__loc__" instead of as
"__loc__" that gets combined with '$' in the parser.

This patch also disallows having spaces after '$' when recalling a
variable  `$ foo'  since that was probably just an unintentional side
effect of the implementation, and it was not documented.

Fixes #2675
2023-07-09 17:23:19 -05:00
Emanuele Torre c08ecbaf23 Mark src/{parser,lexer}.{c,h} as generated files in .gitattributes
This should hide edit to those files in PR diffs making PRs easier to
review.
2023-07-09 14:38:17 -05:00
Emanuele Torre cd8898d5b9 exit immediately after halt or halt_error is called
Instead of continuing to the next input, and only exiting if there are
no more inputs.

Closes #2533
2023-07-07 11:13:28 -05:00