1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

1716 Commits

Author SHA1 Message Date
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
d875ff5c7a doc(readme): Add docker usage doc (#3103)
* doc(readme): Add docker usage doc

* fix heading size

Co-authored-by: itchyny <itchyny@cybozu.co.jp>
2024-05-01 06:07:10 +02:00
6ce6e7c713 chore: fix some typos in comments (#3096)
Signed-off-by: goodactive <goodactive@qq.com>
2024-04-29 21:03:46 +02:00
e4d0b12d7d A couple of teeny tweaks (#3091)
* Don't get HOMEDRIVE unless needed

* Use put_char instead of put_str
2024-04-23 16:10:42 +09:00
6eff31a204 Add strptime fallback not only for Windows 2024-04-18 01:38:29 +02:00
6408338e93 Update jq_fuzz_load_file.c: Add missing include unistd.h (#3085) 2024-03-29 10:13:25 +01:00
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
afe0afaf06 ci: Remove unnecessary apt-get upgrade (#3082)
Causes update to irrelevant packages and added flakeyness

Fixes #3066
2024-03-28 14:01:03 +01:00
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
ea78b5a030 jv_array_indexes: remove a bunch of unnecessary copies/gets 2024-03-28 12:12:39 +01:00
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
be437ec049 Add trim/0, ltrim/0 and rtrim/0 that trims leading and trailing whitespace (#3056) 2024-03-20 11:04:17 +01:00
81f4f883ac Remove non-standard pow10 filter in favor of exp10 (#3059)
The pow10 function was a glibc extension removed in 2.27. Use exp10 filter instead.
2024-03-20 18:23:08 +09:00
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
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
d69733154a Fix valgrind warning on aarch64/glibc 2.31
tests/mantest were failing on Raspberry Pi OS 11:

==10205== Conditional jump or move depends on uninitialised value(s)
==10205==    at 0x48806F8: checkfail (jq_test.c:58)
==10205==    by 0x48806F8: run_jq_tests (jq_test.c:99)
==10205==    by 0x4880FCB: jq_testsuite (jq_test.c:39)
==10205==    by 0x10B37F: main (main.c:576)
==10205==
==10205== Conditional jump or move depends on uninitialised value(s)
==10205==    at 0x4880714: checkfail (jq_test.c:58)
==10205==    by 0x4880714: run_jq_tests (jq_test.c:99)
==10205==    by 0x4880FCB: jq_testsuite (jq_test.c:39)
==10205==    by 0x10B37F: main (main.c:576)
2024-03-18 19:42:22 +01:00
10ea3c7d9f util.c: update strptime to revision 1.66 2024-03-18 19:10:21 +01:00
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
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
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
c95b34ff82 remove repetitive words
Signed-off-by: wellweek <xiezitai@outlook.com>
2024-03-08 10:43:29 +01:00
ce0e788ce2 improve tonumber/0 performance by parsing input as number literal
Previously, the tonumber/0 filter parses the input as JSON values, but
this is less-performant on large non-number strings. Parsing the input
string as number literal fixes the performance issue. Also, this fix
changes the filter to reject numbers with white spaces.
2024-03-01 16:33:17 +01:00
913b26469f docs: Update chocolatey install command in default.yml (#3042) 2024-02-13 16:50:58 +01:00
fc9ecd71b3 tests: run tests in C locale
Fixes #3038
2024-02-10 18:23:50 +01:00
623d7a8bd6 src/jv_dtoa.c: Fix compiler error 2024-02-08 19:27:48 +01:00
6980cc9713 src/builtin.c: Add missing semicolon 2024-02-08 19:27:48 +01:00
92d35378ff Fix typo in documentation for map_values (#3035)
* Fix typo in documentation for map_values

"map_value(f)" -> "map_values(f)"

* map_value => map_values also in the devolpment manual

---------

Co-authored-by: Emanuele Torre <torreemanuele6@gmail.com>
2024-02-08 13:52:50 +00:00
54cc15c127 Add missing string color case
Colors have a color separate from object keys, so were not tested.
2024-02-08 00:11:54 -06:00
48df9bce0c Clear formatting immediately after colon 2024-02-08 00:11:54 -06:00
76853f6046 Fix tests and test indented printing 2024-02-08 00:11:54 -06:00
3c37522aaa Consistently reset color formatting in jv_dump_term
Before, arrays would not reset colors after `[` and `,`, but objects
would; it would reset colors twice before `]` and `}`; and some cases of
indentation would have colors applied. Now, colors are reset immediately
after any token that is colored, before any indentation. This makes the
formatting consistent, for the benefit of custom `JQ_COLORS`.
2024-02-08 00:11:54 -06:00
8a9a74dc12 License: Improve license statement.
The README mentions only the MIT license but in fact part of `jq`
is under ICU license and the documentation is under CC.

Also jq.spec claimed that it is licensed under BSD.
2024-02-06 14:51:46 +01:00
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
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
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
7bdc9a7a63 Makefile.am: fix lines indented with tabs instead of spaces 2024-01-26 16:13:35 -06:00
1daabc67ed typo contruct->construct (#3017) 2024-01-25 22:21:41 +01:00
c95f6ce700 Fix "in the a search" typo (#3015)
Fixes #3014
2024-01-24 23:34:41 +01:00
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
71e7bcdfc1 Revert "lexer: temporarily revert #\ patch; keep CR in comment bug fix"
This reverts commit 5d95791a6795bfc44380c2e6e343ee66dd891e8b.
2024-01-16 16:08:03 -06:00
f954e82b14 Provide strptime implementation on all systems 2024-01-16 16:01:27 -06:00
f51e841fbc Bump jinja2 from 3.1.2 to 3.1.3 in /docs (#3009)
Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.2 to 3.1.3.
- [Release notes](https://github.com/pallets/jinja/releases)
- [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst)
- [Commits](https://github.com/pallets/jinja/compare/3.1.2...3.1.3)

---
updated-dependencies:
- dependency-name: jinja2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-13 11:24:16 +09:00
2381d15d3e Bump the official-actions group with 2 updates (#2998)
* Bump the official-actions group with 2 updates

Bumps the official-actions group with 2 updates: [actions/upload-artifact](https://github.com/actions/upload-artifact) and [actions/download-artifact](https://github.com/actions/download-artifact).


Updates `actions/upload-artifact` from 3 to 4
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

Updates `actions/download-artifact` from 3 to 4
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: official-actions
- dependency-name: actions/download-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: official-actions
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix CI workflow for updating artifact actions to v4

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: itchyny <itchyny@cybozu.co.jp>
2024-01-09 09:33:26 +09:00
701c880805 Add jq 1.7.1 news item (#3004) 2023-12-26 15:22:39 +09:00
0b922725b1 Fix typo (#3002) 2023-12-24 11:22:20 +01:00
e011f003b6 Add jq 1.7.1 to webpage (#3003)
Make it the default download
2023-12-24 11:17:21 +01:00
56828b6d04 Always build Docker image on CI, group Dependabot PRs for official actions (#2997)
* Always build docker image on CI

* Revert "Bump actions/download-artifact from 3 to 4"

This reverts commit 9e2695e117aef8403fa0c5b32ee0f26cb442862a.

* Group Dependabot PRs for official actions
2023-12-19 17:54:53 +09:00
9e2695e117 Bump actions/download-artifact from 3 to 4
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-18 15:18:47 +01:00
95c50a2d0d Update signatures of 1.7.1
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 20:52:03 +01:00
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
jq-1.7.1
2023-12-13 20:20:22 +01:00