0003-sniffer-fix-potential-overflow.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 2eacbd762332795e00692ddab2515c6da23198d3 Mon Sep 17 00:00:00 2001
  2. From: Changqing Li <changqing.li@windriver.com>
  3. Date: Mon, 12 May 2025 14:06:41 +0800
  4. Subject: [PATCH] sniffer: Add better coverage of skip_insignificant_space()
  5. CVE: CVE-2025-2784
  6. Upstream-Status: Backport
  7. [https://gitlab.gnome.org/GNOME/libsoup/-/merge_requests/435/diffs?commit_id=242a10fbb12dbdc12d254bd8fc8669a0ac055304;
  8. https://gitlab.gnome.org/GNOME/libsoup/-/merge_requests/442/diffs?commit_id=c415ad0b6771992e66c70edf373566c6e247089d]
  9. Test code is not added since it uses some functions not defined in
  10. version 2.74. These tests are not used now, so just ignore them.
  11. Upstream: https://git.openembedded.org/meta-openembedded/plain/meta-oe/recipes-support/libsoup/libsoup-2.4/CVE-2025-2784.patch
  12. Signed-off-by: Changqing Li <changqing.li@windriver.com>
  13. Signed-off-by: Titouan Christophe <titouan.christophe@mind.be>
  14. ---
  15. libsoup/soup-content-sniffer.c | 9 +++----
  16. 1 files changed, 3 insertions(+), 4 deletions(-)
  17. diff --git a/libsoup/soup-content-sniffer.c b/libsoup/soup-content-sniffer.c
  18. index 5f2896e..9554636 100644
  19. --- a/libsoup/soup-content-sniffer.c
  20. +++ b/libsoup/soup-content-sniffer.c
  21. @@ -612,8 +612,10 @@ sniff_text_or_binary (SoupContentSniffer *sniffer, SoupBuffer *buffer)
  22. }
  23. static gboolean
  24. -skip_insignificant_space (const char *resource, int *pos, int resource_length)
  25. +skip_insignificant_space (const char *resource, gsize *pos, gsize resource_length)
  26. {
  27. + if (*pos >= resource_length)
  28. + return TRUE;
  29. while ((resource[*pos] == '\x09') ||
  30. (resource[*pos] == '\x20') ||
  31. (resource[*pos] == '\x0A') ||
  32. @@ -632,7 +634,7 @@ sniff_feed_or_html (SoupContentSniffer *sniffer, SoupBuffer *buffer)
  33. {
  34. const char *resource = (const char *)buffer->data;
  35. int resource_length = MIN (512, buffer->length);
  36. - int pos = 0;
  37. + gsize pos = 0;
  38. if (resource_length < 3)
  39. goto text_html;
  40. @@ -642,9 +644,6 @@ sniff_feed_or_html (SoupContentSniffer *sniffer, SoupBuffer *buffer)
  41. pos = 3;
  42. look_for_tag:
  43. - if (pos > resource_length)
  44. - goto text_html;
  45. -
  46. if (skip_insignificant_space (resource, &pos, resource_length))
  47. goto text_html;
  48. --
  49. 2.34.1