ncursesw 1.4.14 → 1.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Changes +6 -0
  3. data/menu_wrap.c +25 -4
  4. data/ncurses_wrap.c +20 -38
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 016e54ae104b0ef7cd1ccc31450cf6c187028dcc36924ec862f02d79a599d1ef
4
- data.tar.gz: 2d9672ed5931baa142638ace9eabf3a32727ed023d69043af0b45c3ac5eee22a
3
+ metadata.gz: 8a9aff5809632dcf68381285d9af26cf2654291b79621714e81bc257b3fcd7ae
4
+ data.tar.gz: 96b081e074414294b6dbcff4e46e31c15d6f1c4f6d1382c28028998453e0589e
5
5
  SHA512:
6
- metadata.gz: 8c19f4ccf0c9825e2964f44b12e79f503fcbb95dc7b0b094c43c64b72830d95db5383ee38b6f8c2025ea5c5108b8f5b6d07ae9c4e63829cface34dd06522d68c
7
- data.tar.gz: 56c3f55db7386478779bf59c8489967ca4388839c18bba718c85e9ec1e359a8a060743112ff45bbb658a309b7baeb3cb17440d3793d5654165dc1e6dfe5b3e65
6
+ metadata.gz: 59fe81fba2e564c1fbaaadc5ba67a8662ca8d528e0471b934edce668c93ba720db7e5c93fb9979d213022ffad48f5fa937c049ace6e9da1ceb98b64c18824a84
7
+ data.tar.gz: 764c2878d6c11f2e88643f43b5052229ec902a32d47839df41c2ccbe563070572c9b94fddd0e7aa433c3a4519862b6569e41351798522d0ed95b0080f49a96cf
data/Changes CHANGED
@@ -1,3 +1,9 @@
1
+ ncurses-ruby-1.4.15
2
+ * Fixed leaked rb_fdset object in every iteration of getch()/wgetch().
3
+ * Fixed busy-loop in getch()/wgetch() when input reaches EOF.
4
+ * Fixed potential use-after-free for ITEM name and description.
5
+ * Added missing NULL checks for ITEM name and description.
6
+
1
7
  ncurses-ruby-1.4.14
2
8
  * Fixed segfault when calling tigetstr() for a non-existent capability.
3
9
  * Fixed incorrect binding of wenclose(), mvwgetch(), and add_wch().
data/menu_wrap.c CHANGED
@@ -28,6 +28,7 @@
28
28
 
29
29
  #if defined(HAVE_MENU_H) || defined(HAVE_NCURSESW_MENU_H)
30
30
 
31
+ #include <ruby/util.h>
31
32
  #include "menu_wrap.h"
32
33
  #include "ncurses_wrap.h"
33
34
  #include "compat.h"
@@ -379,16 +380,32 @@ static VALUE rbncurs_m_item_index(VALUE dummy, VALUE rb_item)
379
380
  * Item creation/destruction functions - mitem_new(3X) man page
380
381
  */
381
382
  static VALUE rbncurs_m_new_item(VALUE dummy, VALUE name, VALUE description)
382
- { return wrap_item(new_item(STR2CSTR(name), STR2CSTR(description))); }
383
+ {
384
+ char *c_name = ruby_strdup(STR2CSTR(name));
385
+ char *c_desc = ruby_strdup(STR2CSTR(description));
386
+ ITEM *item = new_item(c_name, c_desc);
387
+ if (item == NULL) { xfree(c_name); xfree(c_desc); return Qnil; }
388
+ if (item_description(item) != c_desc) {
389
+ /* ncurses rejected the description */
390
+ xfree(c_desc);
391
+ }
392
+ return wrap_item(item);
393
+ }
383
394
 
384
395
  static VALUE rbncurs_c_free_item(VALUE rb_item)
385
396
  {
386
397
  VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
387
398
  ITEM *item = get_item(rb_item);
388
399
  VALUE item_address = INT2NUM((long)(item));
400
+ char *c_name = (char *)item_name(item);
401
+ char *c_desc = (char *)item_description(item);
402
+ int result = free_item(item);
403
+ if (result != E_OK) return INT2NUM(result);
404
+ xfree(c_name);
405
+ xfree(c_desc);
389
406
  rb_funcall(items_hash, rb_intern("delete"), 1, item_address);
390
407
  rb_iv_set(rb_item, "@destroyed", Qtrue);
391
- return INT2NUM(free_item(item));
408
+ return INT2NUM(result);
392
409
  }
393
410
  static VALUE rbncurs_m_free_item(VALUE dummy, VALUE rb_item)
394
411
  { return rbncurs_c_free_item(rb_item); }
@@ -764,7 +781,9 @@ static VALUE rbncurs_m_pos_menu_cursor(VALUE dummy, VALUE rb_menu)
764
781
  static VALUE rbncurs_c_item_name(VALUE rb_item)
765
782
  {
766
783
  ITEM *item = get_item(rb_item);
767
- return rb_str_new2(item_name(item));
784
+ char *str = item_name(item);
785
+ if (str == NULL) return Qnil;
786
+ return rb_str_new2(str);
768
787
  }
769
788
  static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
770
789
  { return rbncurs_c_item_name(rb_item); }
@@ -772,7 +791,9 @@ static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
772
791
  static VALUE rbncurs_c_item_description(VALUE rb_item)
773
792
  {
774
793
  ITEM *item = get_item(rb_item);
775
- return rb_str_new2(item_description(item));
794
+ char *str = item_description(item);
795
+ if (str == NULL) return Qnil;
796
+ return rb_str_new2(str);
776
797
  }
777
798
  static VALUE rbncurs_m_item_description(VALUE dummy, VALUE rb_item)
778
799
  { return rbncurs_c_item_description(rb_item); }
data/ncurses_wrap.c CHANGED
@@ -856,28 +856,28 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
856
856
  int result;
857
857
  double starttime, nowtime, finishtime;
858
858
  double resize_delay = NUM2INT(get_RESIZEDELAY(mNcurses)) / 1000.0;
859
+ #ifdef HAVE_RB_THREAD_FD_SELECT
860
+ rb_fdset_t in_fds;
861
+ #else
859
862
  fd_set in_fds;
863
+ #endif
864
+ bool ready = false;
865
+ struct timeval tv;
860
866
  #ifdef HAVE_CLOCK_GETTIME
861
- struct timespec tv;
862
- struct timeval ts;
863
- clock_gettime (CLOCK_MONOTONIC, &tv);
864
- starttime = tv.tv_sec + tv.tv_nsec * 1e-9;
867
+ struct timespec ts;
868
+ clock_gettime (CLOCK_MONOTONIC, &ts);
869
+ starttime = ts.tv_sec + ts.tv_nsec * 1e-9;
865
870
  #else
866
- struct timeval tv;
867
871
  struct timezone tz = {0,0};
868
872
  gettimeofday(&tv, &tz);
869
873
  starttime = tv.tv_sec + tv.tv_usec * 1e-6;
870
874
  #endif
871
875
  finishtime = starttime + delay;
872
876
  wtimeout(c_win, 0);
873
- while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR) {
874
- #ifdef HAVE_RB_THREAD_FD_SELECT
875
- rb_fdset_t fdsets[3];
876
- rb_fdset_t *rfds = NULL;
877
- #endif
877
+ while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR && !ready) {
878
878
  #ifdef HAVE_CLOCK_GETTIME
879
- clock_gettime (CLOCK_MONOTONIC, &tv);
880
- nowtime = tv.tv_sec + tv.tv_nsec * 1e-9;
879
+ clock_gettime (CLOCK_MONOTONIC, &ts);
880
+ nowtime = ts.tv_sec + ts.tv_nsec * 1e-9;
881
881
  #else
882
882
  gettimeofday(&tv, &tz);
883
883
  nowtime = tv.tv_sec + tv.tv_usec * 1e-6;
@@ -888,38 +888,20 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
888
888
  /* Check for terminal size change every resize_delay seconds */
889
889
  if (resize_delay > delay) resize_delay = delay;
890
890
  tv.tv_sec = (time_t)resize_delay;
891
- #ifdef HAVE_CLOCK_GETTIME
892
- tv.tv_nsec = (unsigned)( (resize_delay - tv.tv_sec) * 1e9 );
893
- #else
894
891
  tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 );
895
- #endif
896
-
897
- #if HAVE_CLOCK_GETTIME
898
- ts.tv_sec = tv.tv_sec;
899
- ts.tv_usec = tv.tv_nsec * 1e-3;
900
- #endif
901
892
 
902
893
  /* sleep on infd until input is available or tv reaches timeout */
903
- FD_ZERO(&in_fds);
904
- FD_SET(infd, &in_fds);
905
-
906
894
  #ifdef HAVE_RB_THREAD_FD_SELECT
907
- rfds = &fdsets[0];
908
- rb_fd_init(rfds);
909
- rb_fd_copy(rfds, &in_fds, infd +1);
910
-
911
- #if HAVE_CLOCK_GETTIME
912
- rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &ts);
913
- #else
914
- rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv);
915
- #endif
916
-
917
- #else
918
- #if HAVE_CLOCK_GETTIME
919
- rb_thread_select(infd + 1, &in_fds, NULL, NULL, &ts);
895
+ rb_fd_init(&in_fds);
896
+ rb_fd_set(infd, &in_fds);
897
+ rb_thread_fd_select(infd + 1, &in_fds, NULL, NULL, &tv);
898
+ ready = rb_fd_isset(infd, &in_fds);
899
+ rb_fd_term(&in_fds);
920
900
  #else
901
+ FD_ZERO(&in_fds);
902
+ FD_SET(infd, &in_fds);
921
903
  rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
922
- #endif
904
+ ready = FD_ISSET(infd, &in_fds);
923
905
  #endif
924
906
  }
925
907
  wtimeout(c_win, windelay);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncursesw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.14
4
+ version: 1.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Herzke