Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
* [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee)
@ 2026-11-07  8:53 Dan Callaghan
  2026-11-07  8:53 ` [ncursesw-ruby.git] 01/06: fix use-after-free with ITEM name and description Dan Callaghan
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Dan Callaghan @ 2026-11-07  8:53 UTC (permalink / raw)
  To: sup-commits

Pushed branch master:
    from b5d4f45  release 1.4.14
     new b240bb5  fix use-after-free with ITEM name and description
     new 8c9003c  handle NULL for ITEM name and description
     new ca35e95  fix leaked rb_fdset in every iteration of getch()
     new d4b9570  clean up type confusion around clock_gettime()
     new f341b43  simplify usage of rb_fdset_t
     new f189aee  return ERR from wgetch() immediately on EOF


Summary of changes:
 menu_wrap.c    | 29 +++++++++++++++++++++++++----
 ncurses_wrap.c | 58 ++++++++++++++++++++--------------------------------------
 2 files changed, 45 insertions(+), 42 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ncursesw-ruby.git] 01/06: fix use-after-free with ITEM name and description
  2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
@ 2026-11-07  8:53 ` Dan Callaghan
  2026-11-07  8:53 ` [ncursesw-ruby.git] 02/06: handle NULL for " Dan Callaghan
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dan Callaghan @ 2026-11-07  8:53 UTC (permalink / raw)
  To: sup-commits

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); }

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [ncursesw-ruby.git] 02/06: handle NULL for ITEM name and description
  2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
  2026-11-07  8:53 ` [ncursesw-ruby.git] 01/06: fix use-after-free with ITEM name and description Dan Callaghan
@ 2026-11-07  8:53 ` Dan Callaghan
  2026-11-07  8:53 ` [ncursesw-ruby.git] 03/06: fix leaked rb_fdset in every iteration of getch() Dan Callaghan
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dan Callaghan @ 2026-11-07  8:53 UTC (permalink / raw)
  To: sup-commits

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

commit 8c9003c9fcb0161c43df034439dba610a1495ac0
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 7 14:45:27 2026 +1100

    handle NULL for ITEM name and description
---
 menu_wrap.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/menu_wrap.c b/menu_wrap.c
index 1f934db..03b1540 100644
--- a/menu_wrap.c
+++ b/menu_wrap.c
@@ -781,7 +781,9 @@ static VALUE rbncurs_m_pos_menu_cursor(VALUE dummy, VALUE rb_menu)
 static VALUE rbncurs_c_item_name(VALUE rb_item)
 {
   ITEM *item = get_item(rb_item);
-  return rb_str_new2(item_name(item));
+  char *str = item_name(item);
+  if (str == NULL) return Qnil;
+  return rb_str_new2(str);
 }
 static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
 { return rbncurs_c_item_name(rb_item); }
@@ -789,7 +791,9 @@ static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
 static VALUE rbncurs_c_item_description(VALUE rb_item)
 {
   ITEM *item = get_item(rb_item);
-  return rb_str_new2(item_description(item));
+  char *str = item_description(item);
+  if (str == NULL) return Qnil;
+  return rb_str_new2(str);
 }
 static VALUE rbncurs_m_item_description(VALUE dummy, VALUE rb_item)
 { return rbncurs_c_item_description(rb_item); }

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [ncursesw-ruby.git] 03/06: fix leaked rb_fdset in every iteration of getch()
  2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
  2026-11-07  8:53 ` [ncursesw-ruby.git] 01/06: fix use-after-free with ITEM name and description Dan Callaghan
  2026-11-07  8:53 ` [ncursesw-ruby.git] 02/06: handle NULL for " Dan Callaghan
@ 2026-11-07  8:53 ` Dan Callaghan
  2026-11-07  8:53 ` [ncursesw-ruby.git] 04/06: clean up type confusion around clock_gettime() Dan Callaghan
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dan Callaghan @ 2026-11-07  8:53 UTC (permalink / raw)
  To: sup-commits

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

commit ca35e9507af4b86ce90a789bc67d1c94090af704
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 7 18:16:02 2026 +1100

    fix leaked rb_fdset in every iteration of getch()
---
 ncurses_wrap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ncurses_wrap.c b/ncurses_wrap.c
index 0773bc0..88bc709 100644
--- a/ncurses_wrap.c
+++ b/ncurses_wrap.c
@@ -913,6 +913,7 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
 #else
       rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv);
 #endif
+      rb_fd_term(rfds);
 
 #else
 #if HAVE_CLOCK_GETTIME

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [ncursesw-ruby.git] 04/06: clean up type confusion around clock_gettime()
  2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
                   ` (2 preceding siblings ...)
  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 ` 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
  5 siblings, 0 replies; 7+ messages in thread
From: Dan Callaghan @ 2026-11-07  8:53 UTC (permalink / raw)
  To: sup-commits

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

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

    clean up type confusion around clock_gettime()
    
    Although clock_gettime() uses struct timespec, select() still always
    uses struct timeval, and the code converts through double. So don't mix
    up the two structs.
---
 ncurses_wrap.c | 32 ++++++--------------------------
 1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/ncurses_wrap.c b/ncurses_wrap.c
index 88bc709..00d4111 100644
--- a/ncurses_wrap.c
+++ b/ncurses_wrap.c
@@ -857,13 +857,12 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
     double starttime, nowtime, finishtime;
     double resize_delay = NUM2INT(get_RESIZEDELAY(mNcurses)) / 1000.0;
     fd_set in_fds;
+    struct timeval tv;
 #ifdef HAVE_CLOCK_GETTIME
-    struct timespec tv;
-    struct timeval  ts;
-    clock_gettime (CLOCK_MONOTONIC, &tv);
-    starttime = tv.tv_sec + tv.tv_nsec * 1e-9;
+    struct timespec ts;
+    clock_gettime (CLOCK_MONOTONIC, &ts);
+    starttime = ts.tv_sec + ts.tv_nsec * 1e-9;
 #else
-    struct timeval tv;
     struct timezone tz = {0,0};
     gettimeofday(&tv, &tz);
     starttime = tv.tv_sec + tv.tv_usec * 1e-6;
@@ -876,8 +875,8 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
       rb_fdset_t *rfds = NULL;
 #endif
 #ifdef HAVE_CLOCK_GETTIME
-      clock_gettime (CLOCK_MONOTONIC, &tv);
-      nowtime = tv.tv_sec + tv.tv_nsec * 1e-9;
+      clock_gettime (CLOCK_MONOTONIC, &ts);
+      nowtime = ts.tv_sec + ts.tv_nsec * 1e-9;
 #else
       gettimeofday(&tv, &tz);
       nowtime = tv.tv_sec + tv.tv_usec * 1e-6;
@@ -888,16 +887,7 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
       /* Check for terminal size change every resize_delay seconds */
       if (resize_delay > delay) resize_delay = delay;
       tv.tv_sec = (time_t)resize_delay;
-#ifdef HAVE_CLOCK_GETTIME
-      tv.tv_nsec = (unsigned)( (resize_delay - tv.tv_sec) * 1e9 );
-#else
       tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 );
-#endif
-
-#if HAVE_CLOCK_GETTIME
-      ts.tv_sec = tv.tv_sec;
-      ts.tv_usec = tv.tv_nsec * 1e-3;
-#endif
 
       /* sleep on infd until input is available or tv reaches timeout */
       FD_ZERO(&in_fds);
@@ -907,20 +897,10 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
       rfds = &fdsets[0];
       rb_fd_init(rfds);
       rb_fd_copy(rfds, &in_fds, infd +1);
-
-#if HAVE_CLOCK_GETTIME
-      rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &ts);
-#else
       rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv);
-#endif
       rb_fd_term(rfds);
-
-#else
-#if HAVE_CLOCK_GETTIME
-      rb_thread_select(infd + 1, &in_fds, NULL, NULL, &ts);
 #else
       rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
-#endif
 #endif
     }
     wtimeout(c_win, windelay);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [ncursesw-ruby.git] 05/06: simplify usage of rb_fdset_t
  2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
                   ` (3 preceding siblings ...)
  2026-11-07  8:53 ` [ncursesw-ruby.git] 04/06: clean up type confusion around clock_gettime() Dan Callaghan
@ 2026-11-07  8:53 ` Dan Callaghan
  2026-11-07  8:53 ` [ncursesw-ruby.git] 06/06: return ERR from wgetch() immediately on EOF Dan Callaghan
  5 siblings, 0 replies; 7+ messages in thread
From: Dan Callaghan @ 2026-11-07  8:53 UTC (permalink / raw)
  To: sup-commits

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

commit f341b43e7324884400c69329e11f6cd234cbc388
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 7 19:31:23 2026 +1100

    simplify usage of rb_fdset_t
    
    No need to allocate three of them and then go through a pointer. Copying
    from an old-fashioned fd_set also defeats the purpose of the Ruby
    wrapper, which is to handle fds larger than 1024.
---
 ncurses_wrap.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/ncurses_wrap.c b/ncurses_wrap.c
index 00d4111..967f2d2 100644
--- a/ncurses_wrap.c
+++ b/ncurses_wrap.c
@@ -856,7 +856,11 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
     int result;
     double starttime, nowtime, finishtime;
     double resize_delay = NUM2INT(get_RESIZEDELAY(mNcurses)) / 1000.0;
+#ifdef HAVE_RB_THREAD_FD_SELECT
+    rb_fdset_t in_fds;
+#else
     fd_set in_fds;
+#endif
     struct timeval tv;
 #ifdef HAVE_CLOCK_GETTIME
     struct timespec ts;
@@ -870,10 +874,6 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
     finishtime = starttime + delay;
     wtimeout(c_win, 0);
     while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR) {
-#ifdef HAVE_RB_THREAD_FD_SELECT
-      rb_fdset_t fdsets[3];
-      rb_fdset_t *rfds = NULL;
-#endif
 #ifdef HAVE_CLOCK_GETTIME
       clock_gettime (CLOCK_MONOTONIC, &ts);
       nowtime = ts.tv_sec + ts.tv_nsec * 1e-9;
@@ -890,16 +890,14 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
       tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 );
 
       /* sleep on infd until input is available or tv reaches timeout */
-      FD_ZERO(&in_fds);
-      FD_SET(infd, &in_fds);
-
 #ifdef HAVE_RB_THREAD_FD_SELECT
-      rfds = &fdsets[0];
-      rb_fd_init(rfds);
-      rb_fd_copy(rfds, &in_fds, infd +1);
-      rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv);
-      rb_fd_term(rfds);
+      rb_fd_init(&in_fds);
+      rb_fd_set(infd, &in_fds);
+      rb_thread_fd_select(infd + 1, &in_fds, NULL, NULL, &tv);
+      rb_fd_term(&in_fds);
 #else
+      FD_ZERO(&in_fds);
+      FD_SET(infd, &in_fds);
       rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
 #endif
     }

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [ncursesw-ruby.git] 06/06: return ERR from wgetch() immediately on EOF
  2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
                   ` (4 preceding siblings ...)
  2026-11-07  8:53 ` [ncursesw-ruby.git] 05/06: simplify usage of rb_fdset_t Dan Callaghan
@ 2026-11-07  8:53 ` Dan Callaghan
  5 siblings, 0 replies; 7+ messages in thread
From: Dan Callaghan @ 2026-11-07  8:53 UTC (permalink / raw)
  To: sup-commits

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

commit f189aee4473e2253a03cb55364d13cfc4a72e5c6
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 7 19:36:29 2026 +1100

    return ERR from wgetch() immediately on EOF
    
    If the input reaches EOF, the file descriptor will be indicated as ready
    by select() but ncurses wgetch() will return ERR. Don't busy-loop in
    this case, just return the ERR straight away.
---
 ncurses_wrap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ncurses_wrap.c b/ncurses_wrap.c
index 967f2d2..04efd1e 100644
--- a/ncurses_wrap.c
+++ b/ncurses_wrap.c
@@ -861,6 +861,7 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
 #else
     fd_set in_fds;
 #endif
+    bool ready = false;
     struct timeval tv;
 #ifdef HAVE_CLOCK_GETTIME
     struct timespec ts;
@@ -873,7 +874,7 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
 #endif
     finishtime = starttime + delay;
     wtimeout(c_win, 0);
-    while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR) {
+    while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR && !ready) {
 #ifdef HAVE_CLOCK_GETTIME
       clock_gettime (CLOCK_MONOTONIC, &ts);
       nowtime = ts.tv_sec + ts.tv_nsec * 1e-9;
@@ -894,11 +895,13 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
       rb_fd_init(&in_fds);
       rb_fd_set(infd, &in_fds);
       rb_thread_fd_select(infd + 1, &in_fds, NULL, NULL, &tv);
+      ready = rb_fd_isset(infd, &in_fds);
       rb_fd_term(&in_fds);
 #else
       FD_ZERO(&in_fds);
       FD_SET(infd, &in_fds);
       rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
+      ready = FD_ISSET(infd, &in_fds);
 #endif
     }
     wtimeout(c_win, windelay);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-07  8:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-07  8:53 [ncursesw-ruby.git] branch master updated (b5d4f45 -> f189aee) Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 01/06: fix use-after-free with ITEM name and description Dan Callaghan
2026-11-07  8:53 ` [ncursesw-ruby.git] 02/06: handle NULL for " 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox