Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [ncursesw-ruby.git] 01/06: fix use-after-free with ITEM name and description
Date: Sat, 07 Nov 2026 19:53:28 +1100	[thread overview]
Message-ID: <20261107085327.51F352CA78B@bl2.djc.id.au> (raw)
In-Reply-To: <179404160709.118121.923149093806097164@bl2.djc.id.au>

New commit on branch master:
https://supmua.dev/git/ncursesw-ruby/commit/b240bb5ad794a86776d1803d66b49a03328ade67.html

commit b240bb5ad794a86776d1803d66b49a03328ade67
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 7 19:13:18 2026 +1100

    fix use-after-free with ITEM name and description
---
 menu_wrap.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/menu_wrap.c b/menu_wrap.c
index 7c6a8ea..1f934db 100644
--- a/menu_wrap.c
+++ b/menu_wrap.c
@@ -28,6 +28,7 @@
 
 #if defined(HAVE_MENU_H) || defined(HAVE_NCURSESW_MENU_H)
 
+#include <ruby/util.h>
 #include "menu_wrap.h"
 #include "ncurses_wrap.h"
 #include "compat.h"
@@ -379,16 +380,32 @@ static VALUE rbncurs_m_item_index(VALUE dummy, VALUE rb_item)
  * Item creation/destruction functions - mitem_new(3X) man page
  */
 static VALUE rbncurs_m_new_item(VALUE dummy, VALUE name, VALUE description)
-{ return wrap_item(new_item(STR2CSTR(name), STR2CSTR(description))); }
+{
+  char *c_name = ruby_strdup(STR2CSTR(name));
+  char *c_desc = ruby_strdup(STR2CSTR(description));
+  ITEM *item = new_item(c_name, c_desc);
+  if (item == NULL) { xfree(c_name); xfree(c_desc); return Qnil; }
+  if (item_description(item) != c_desc) {
+    /* ncurses rejected the description */
+    xfree(c_desc);
+  }
+  return wrap_item(item);
+}
 
 static VALUE rbncurs_c_free_item(VALUE rb_item)
 {
   VALUE items_hash   = rb_iv_get(mMenu, "@items_hash");
   ITEM *item       = get_item(rb_item);
   VALUE item_address  = INT2NUM((long)(item));
+  char *c_name = (char *)item_name(item);
+  char *c_desc = (char *)item_description(item);
+  int result = free_item(item);
+  if (result != E_OK) return INT2NUM(result);
+  xfree(c_name);
+  xfree(c_desc);
   rb_funcall(items_hash, rb_intern("delete"), 1, item_address);
   rb_iv_set(rb_item, "@destroyed", Qtrue);
-  return INT2NUM(free_item(item));
+  return INT2NUM(result);
 }
 static VALUE rbncurs_m_free_item(VALUE dummy, VALUE rb_item)
 { return rbncurs_c_free_item(rb_item); }

  reply	other threads:[~2026-11-07  8:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
2026-11-07  8:53 ` Dan Callaghan [this message]
2026-11-07  8:53 ` [ncursesw-ruby.git] 02/06: handle NULL for ITEM name and description Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 03/06: fix leaked rb_fdset in every iteration of getch() Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 04/06: clean up type confusion around clock_gettime() Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 05/06: simplify usage of rb_fdset_t Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 06/06: return ERR from wgetch() immediately on EOF Dan Callaghan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261107085327.51F352CA78B@bl2.djc.id.au \
    --to=dan@bl2.djc.id.au \
    --cc=djc@djc.id.au \
    --cc=sup-commits@supmua.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox