Skip to content
Memory corruption Disclosed report Intermediate

Buffer overflow in yywarning_s

A warning-formatting function in the mruby compiler concatenated a message and a string into a fixed 256-byte stack buffer without checking length. A crafted input could overflow the buffer and crash the process, with the authors suggesting possible control of execution flow via stack smashing.

dgaletic Follow

Originally disclosed on HackerOne

Bounty$1,000 View original
  • Triaged in 10 hours
  • Fixed in 28 hours
  • Paid in 28 hours
  • Disclosed after 5 months

PoC

The following demonstrates a crash:

300000000000000000000000000000000000000000000000E0030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Debug info

In the same vein as our last two reports, we've found more instances of problematic string concatenation. This crash happens due to a buffer overflow in yywarning_s. strcat is called without making sure buf is large enough. The patch below adds the check.

Diff
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index cb62ec3f..82df8c08 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -3759,10 +3759,15 @@ static void
 yywarning_s(parser_state *p, const char *msg, const char *s)
 {
   char buf[256];
-
-  strcpy(buf, msg);
-  strcat(buf, ": ");
-  strcat(buf, s);
+  const char delim[] = ": ";
+
+  if (strlen(msg) + strlen(s) + strlen(delim) + 1 > sizeof(buf)) {
+      strcpy(buf, msg);
+  } else {
+      strcpy(buf, msg);
+      strcat(buf, delim);
+      strcat(buf, s);
+  }
   yywarning(p, buf);
 }

Test platform

  • Arch Linux

mruby SHA: 9c252410cf6e43eb7e19683844c83581445fc089

Thank you, Dinko Galetic Denis Kasak

Impact

DOS through crashing the mruby process and probable execution flow control through stack smashing.

The original report as published on HackerOne, by dgaletic. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The function copied a message and a string into a fixed 256-byte stack buffer using strcpy and strcat without checking that the combined length fits.

Impact

The process could be crashed (denial of service), and the authors say stack smashing could probably allow control of execution flow.

What the attacker needed

Ability to supply input to the mruby compiler

The fix

The patch adds a length check so the message is copied alone when the combined text would exceed the buffer.

How it was found

  1. Supply the long crafted input to the mruby compiler.
  2. Observe the crash caused by the buffer overflow in yywarning_s.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A program often builds text by copying pieces into a small fixed-size box in memory. If the pieces are longer than the box, they spill over into neighbouring memory, which is called a buffer overflow. Here a very long input made the compiler write past its box and crash, and the authors say it could possibly let an attacker steer the program.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by dgaletic

View all

13 more disclosed reports, best first.

More from shopify-scripts

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.