2
1

0004-fix-potential-buffer-overflows-of-interactive-shell.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From: Michael Mann <mmann78@netscape.net>
  2. Date: Fri, 20 Jun 2025 23:05:00 -0400
  3. Subject: Fix potential buffer overflows of interactive shell
  4. Upstream: https://gitlab.gnome.org/GNOME/libxml2/-/commit/5e9ec5c107d3f5b5179c3dbc19df43df041cd55b
  5. Upstream: https://sources.debian.org/src/libxml2/2.12.7+dfsg+really2.9.14-2.1/debian/patches/CVE-2025-6170.patch/
  6. CVE: CVE-2025-6170
  7. [thomas: Originally backported for v2.9.14 re-applied on v2.13.8]
  8. Signed-off-by: Thomas Perale <thomas.perale@mind.be>
  9. ---
  10. debugXML.c | 15 ++++++++++-----
  11. result/scripts/long_command | 8 ++++++++
  12. test/scripts/long_command.script | 6 ++++++
  13. test/scripts/long_command.xml | 1 +
  14. 4 files changed, 25 insertions(+), 5 deletions(-)
  15. create mode 100644 result/scripts/long_command
  16. create mode 100644 test/scripts/long_command.script
  17. create mode 100644 test/scripts/long_command.xml
  18. diff --git a/debugXML.c b/debugXML.c
  19. index ed56b0f8..452b9573 100644
  20. --- a/debugXML.c
  21. +++ b/debugXML.c
  22. @@ -1033,6 +1033,10 @@ xmlCtxtDumpOneNode(xmlDebugCtxtPtr ctxt, xmlNodePtr node)
  23. xmlCtxtGenericNodeCheck(ctxt, node);
  24. }
  25. +#define MAX_PROMPT_SIZE 500
  26. +#define MAX_ARG_SIZE 400
  27. +#define MAX_COMMAND_SIZE 100
  28. +
  29. /**
  30. * xmlCtxtDumpNode:
  31. * @output: the FILE * for the output
  32. @@ -2795,10 +2799,10 @@ void
  33. xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input,
  34. FILE * output)
  35. {
  36. - char prompt[500] = "/ > ";
  37. + char prompt[MAX_PROMPT_SIZE] = "/ > ";
  38. char *cmdline = NULL, *cur;
  39. - char command[100];
  40. - char arg[400];
  41. + char command[MAX_COMMAND_SIZE];
  42. + char arg[MAX_ARG_SIZE];
  43. int i;
  44. xmlShellCtxtPtr ctxt;
  45. xmlXPathObjectPtr list;
  46. @@ -2856,7 +2860,8 @@ xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input,
  47. cur++;
  48. i = 0;
  49. while ((*cur != ' ') && (*cur != '\t') &&
  50. - (*cur != '\n') && (*cur != '\r')) {
  51. + (*cur != '\n') && (*cur != '\r') &&
  52. + (i < (MAX_COMMAND_SIZE - 1))) {
  53. if (*cur == 0)
  54. break;
  55. command[i++] = *cur++;
  56. @@ -2871,7 +2876,7 @@ xmlShell(xmlDocPtr doc, const char *filename, xmlShellReadlineFunc input,
  57. while ((*cur == ' ') || (*cur == '\t'))
  58. cur++;
  59. i = 0;
  60. - while ((*cur != '\n') && (*cur != '\r') && (*cur != 0)) {
  61. + while ((*cur != '\n') && (*cur != '\r') && (*cur != 0) && (i < (MAX_ARG_SIZE-1))) {
  62. if (*cur == 0)
  63. break;
  64. arg[i++] = *cur++;
  65. diff --git a/result/scripts/long_command b/result/scripts/long_command
  66. new file mode 100644
  67. index 00000000..e6f00708
  68. --- /dev/null
  69. +++ b/result/scripts/long_command
  70. @@ -0,0 +1,8 @@
  71. +/ > b > b > Object is a Node Set :
  72. +Set contains 1 nodes:
  73. +1 ELEMENT a:c
  74. +b > Unknown command This_is_a_really_long_command_string_designed_to_test_the_limits_of_the_memory_that_stores_the_comm
  75. +b > b > Unknown command ess_currents_of_time_and_existence
  76. +b > <?xml version="1.0"?>
  77. +<a xmlns:a="bar"><b xmlns:a="foo">Navigating_the_labyrinthine_corridors_of_human_cognition_one_often_encounters_the_perplexing_paradox_that_the_more_we_delve_into_the_intricate_dance_of_neural_pathways_and_synaptic_firings_the_further_we_seem_to_stray_from_a_truly_holistic_understanding_of_consciousness_a_phenomenon_that_remains_as_elusive_as_a_moonbeam_caught_in_a_spiderweb_yet_undeniably_shapes_every_fleeting_thought_every_prof</b></a>
  78. +b >
  79. \ No newline at end of file
  80. diff --git a/test/scripts/long_command.script b/test/scripts/long_command.script
  81. new file mode 100644
  82. index 00000000..00f6df09
  83. --- /dev/null
  84. +++ b/test/scripts/long_command.script
  85. @@ -0,0 +1,6 @@
  86. +cd a/b
  87. +set <a:c/>
  88. +xpath //*[namespace-uri()="foo"]
  89. +This_is_a_really_long_command_string_designed_to_test_the_limits_of_the_memory_that_stores_the_command_please_dont_crash foo
  90. +set Navigating_the_labyrinthine_corridors_of_human_cognition_one_often_encounters_the_perplexing_paradox_that_the_more_we_delve_into_the_intricate_dance_of_neural_pathways_and_synaptic_firings_the_further_we_seem_to_stray_from_a_truly_holistic_understanding_of_consciousness_a_phenomenon_that_remains_as_elusive_as_a_moonbeam_caught_in_a_spiderweb_yet_undeniably_shapes_every_fleeting_thought_every_profound_emotion_and_every_grand_aspiration_that_propels_our_species_ever_onward_through_the_relentless_currents_of_time_and_existence
  91. +save -
  92. diff --git a/test/scripts/long_command.xml b/test/scripts/long_command.xml
  93. new file mode 100644
  94. index 00000000..1ba44016
  95. --- /dev/null
  96. +++ b/test/scripts/long_command.xml
  97. @@ -0,0 +1 @@
  98. +<a xmlns:a="bar"><b xmlns:a="foo"/></a>
  99. --
  100. 2.50.1