Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The patch uses an abort() to prevent heap memory corruption, but per the
discussion here

  lloyd#240

it seems that's the best option available without a significant rewrite
of the library.
  • Loading branch information
jstamp committed Jul 2, 2023
1 parent 65bfd21 commit 33177af
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ yajl (2.1.0-4) UNRELEASED; urgency=medium

* Acknowledge NMU. Thank you, Tobias, for the work.
(Closes: #1039984, #1040034)
* Patch CVE-2017-16516
* Patch CVE-2017-16516 and CVE-2022-24795 (Closes: #1040036)

-- John Stamp <jstamp@users.sourceforge.net> Sun, 02 Jul 2023 10:40:25 -0700

Expand Down
30 changes: 30 additions & 0 deletions debian/patches/CVE-2022-24795.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Description: Fix for CVE-2022-24795
An integer overflow will lead to heap memory corruption with large (~2GB) inputs.
Origin: https://github.com/ppisar/yajl/commit/23cea2d7677e396efed78bbf1bf153961fab6bad
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040036
Bug: https://github.com/lloyd/yajl/issues/239
---
src/yajl_buf.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

--- a/src/yajl_buf.c
+++ b/src/yajl_buf.c
@@ -45,7 +45,17 @@

need = buf->len;

- while (want >= (need - buf->used)) need <<= 1;

This comment has been minimized.

Copy link
@coldtobi

coldtobi Jul 8, 2023

I think this should be
while (need && want >= (need - buf->used)) need <<= 1;

See:
https://github.com/brianmario/yajl-ruby/pull/211/files#r871257171
robohack/yajl@166b384

This comment has been minimized.

Copy link
@jstamp

jstamp Jul 9, 2023

Author Owner

There are a couple of options to fix this.

There's the current patch, which is from lloyd#240 See:

lloyd@23cea2d

The other option is this pair of commits, which I think you're referring to:

robohack/yajl@7d8adb4
robohack/yajl@166b384

You think that's the better option?

+ if (((buf->used > want) ? buf->used : want) > (size_t)(buf->used + want)) {
+ /* We cannot allocate more memory than SIZE_MAX. */
+ abort();
+ }
+ while (want >= (need - buf->used)) {
+ if (need >= (size_t)((size_t)(-1)<<1)>>1) {
+ /* need would overflow. */
+ abort();
+ }
+ need <<= 1;
+ }

if (need != buf->len) {
buf->data = (unsigned char *) YA_REALLOC(buf->alloc, buf->data, need);
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dynamically-link-tools.patch
multiarch.patch
CVE-2017-16516.patch
CVE-2022-24795.patch
CVE-2023-33460.patch

0 comments on commit 33177af

Please sign in to comment.