2
1

0001-use-vasprintf-if-available-for-error-messages-and-otherwise-vsnprintf.patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. From fb7db9ae3e8ac271651d1884a3611d30bac04a98 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
  3. Date: Tue, 9 Jul 2024 12:11:37 +0300
  4. Subject: [PATCH] Use vasprintf() if available for error messages and otherwise
  5. vsnprintf()
  6. vasprintf() is a GNU/BSD extension and would allocate as much memory as required
  7. on the heap, similar to g_strdup_printf(). It's ridiculous that such a function
  8. is still not provided as part of standard C.
  9. If it's not available, use vsnprintf() to at least avoid stack/heap buffer
  10. overflows, which can lead to arbitrary code execution.
  11. Thanks to Noriko Totsuka for reporting.
  12. Fixes JVN#02030803 / JPCERT#92912620 / CVE-2024-40897
  13. Fixes #69
  14. Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/191>
  15. Upstream: https://gitlab.freedesktop.org/gstreamer/orc/-/commit/fb7db9ae3e8ac271651d1884a3611d30bac04a98
  16. CVE: CVE-2024-40897
  17. Signed-off-by: Thomas Perale <thomas.perale@mind.be>
  18. ---
  19. meson.build | 1 +
  20. orc/orccompiler.c | 6 +++++-
  21. orc/orcparse.c | 14 +++++++++++---
  22. 3 files changed, 17 insertions(+), 4 deletions(-)
  23. diff --git a/meson.build b/meson.build
  24. index c7ba5d7d..fe8c6016 100644
  25. --- a/meson.build
  26. +++ b/meson.build
  27. @@ -128,6 +128,7 @@ int main() {
  28. '''
  29. cdata.set('HAVE_MONOTONIC_CLOCK', cc.compiles(monotonic_test))
  30. cdata.set('HAVE_GETTIMEOFDAY', cc.has_function('gettimeofday'))
  31. +cdata.set('HAVE_VASPRINTF', cc.has_function('vasprintf'))
  32. cdata.set('HAVE_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix : '#include <stdlib.h>'))
  33. cdata.set('HAVE_MMAP', cc.has_function('mmap'))
  34. cdata.set('HAVE_SYS_TIME_H', cc.has_header('sys/time.h'))
  35. diff --git a/orc/orccompiler.c b/orc/orccompiler.c
  36. index 1e24b8a3..d3394612 100644
  37. --- a/orc/orccompiler.c
  38. +++ b/orc/orccompiler.c
  39. @@ -1332,8 +1332,12 @@ orc_compiler_error_valist (OrcCompiler *compiler, const char *fmt,
  40. if (compiler->error_msg) return;
  41. +#ifdef HAVE_VASPRINTF
  42. + vasprintf (&s, fmt, args);
  43. +#else
  44. s = malloc (ORC_COMPILER_ERROR_BUFFER_SIZE);
  45. - vsprintf (s, fmt, args);
  46. + vsnprintf (s, ORC_COMPILER_ERROR_BUFFER_SIZE, fmt, args);
  47. +#endif
  48. compiler->error_msg = s;
  49. compiler->error = TRUE;
  50. compiler->result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE;
  51. diff --git a/orc/orcparse.c b/orc/orcparse.c
  52. index b0d67095..ae4f1b6b 100644
  53. --- a/orc/orcparse.c
  54. +++ b/orc/orcparse.c
  55. @@ -424,17 +424,25 @@ orc_parse_get_error_where (OrcParser *parser)
  56. static void
  57. orc_parse_add_error_valist (OrcParser *parser, const char *format, va_list args)
  58. {
  59. - char text[ORC_ERROR_LENGTH] = { '\0' };
  60. -
  61. if (parser->error_program != parser->program) {
  62. parser->error_program = parser->program;
  63. }
  64. - vsprintf (text, format, args);
  65. +#ifdef HAVE_VASPRINTF
  66. + char *text;
  67. + vasprintf (&text, format, args);
  68. +#else
  69. + char text[ORC_ERROR_LENGTH] = { '\0' };
  70. + vsnprintf (text, sizeof (text), format, args);
  71. +#endif
  72. orc_vector_append (&parser->errors,
  73. orc_parse_error_new (orc_parse_get_error_where (parser),
  74. parser->line_number, -1, text));
  75. +
  76. +#ifdef HAVE_VASPRINTF
  77. + free (text);
  78. +#endif
  79. }
  80. static void
  81. --
  82. GitLab