Project

General

Profile

Bug #14425

rb_funcall too strict on extra args

Added by normalperson (Eric Wong) 9 months ago. Updated 8 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:85266]

Description

Ruby 2.5 instroduces extra checking for rb_funcall checking,
but apparently it is too strict for some compilers and extra
args should not cause fatal problems (only warnings).

Jeremy first reported this to me in:
https://bogomips.org/kgio-public/20171215053434.GT7579@jeremyevans.local/
but there's apparently hundreds of instances on RubyGems.org alone.

Attached are over 500 gem-codesearch results of latest gems.

/me goes to setup a sid chroot again...

funcall-extra-zeros.txt (47.4 KB) funcall-extra-zeros.txt normalperson (Eric Wong), 01/30/2018 09:36 PM
0001-ruby.h-relax-rb_funcall-check-on-extra-args-for-clan.patch (3.25 KB) 0001-ruby.h-relax-rb_funcall-check-on-extra-args-for-clan.patch normalperson (Eric Wong), 01/30/2018 11:03 PM

Associated revisions

Revision 3ce9a140
Added by normal 9 months ago

ruby.h: relax rb_funcall check on extra args for clang

clang 5.+ (tested clang 7.0.0) seems to be attempting division-by-zero
and giving a very large number for static args to rb_funcall.

  • include/ruby/ruby.h (rb_varargs_bad_length): relax check for clang
  • ext/-test-/funcall/funcall.c: renamed from passing_block.c define extra_args_name function
  • test/-ext-/funcall/test_funcall.rb: new test [Bug #14425]

From: Eric Wong e@80x24.org

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62116
Added by normalperson (Eric Wong) 9 months ago

ruby.h: relax rb_funcall check on extra args for clang

clang 5.+ (tested clang 7.0.0) seems to be attempting division-by-zero
and giving a very large number for static args to rb_funcall.

  • include/ruby/ruby.h (rb_varargs_bad_length): relax check for clang
  • ext/-test-/funcall/funcall.c: renamed from passing_block.c define extra_args_name function
  • test/-ext-/funcall/test_funcall.rb: new test [Bug #14425]

From: Eric Wong e@80x24.org

Revision 6eeb0f7e
Added by nobu (Nobuyoshi Nakada) 9 months ago

ruby.h: relax rb_funcall(obj, id, 0, 0) case only

  • include/ruby/ruby.h (rb_varargs_argc_valid_p): relax rb_funcall check on extra args only if argc == 0, for the compatibility with wrong code which is probably confused with rb_funcallv. [Bug #14425]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62151
Added by nobu (Nobuyoshi Nakada) 9 months ago

ruby.h: relax rb_funcall(obj, id, 0, 0) case only

  • include/ruby/ruby.h (rb_varargs_argc_valid_p): relax rb_funcall check on extra args only if argc == 0, for the compatibility with wrong code which is probably confused with rb_funcallv. [Bug #14425]

Revision 18b6b672
Added by naruse (Yui NARUSE) 8 months ago

merge revision(s) 62116,62151: [Backport #14425]

ruby.h: relax rb_funcall check on extra args for clang

clang 5.+ (tested clang 7.0.0) seems to be attempting division-by-zero
and giving a very large number for static args to rb_funcall.

* include/ruby/ruby.h (rb_varargs_bad_length): relax check for clang
* ext/-test-/funcall/funcall.c: renamed from passing_block.c
  define extra_args_name function
* test/-ext-/funcall/test_funcall.rb: new test
   [Bug #14425]

From: Eric Wong <e@80x24.org>

ruby.h: relax rb_funcall(obj, id, 0, 0) case only

* include/ruby/ruby.h (rb_varargs_argc_valid_p): relax rb_funcall
  check on extra args only if argc == 0, for the compatibility
  with wrong code which is probably confused with rb_funcallv.
  [Bug #14425]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@62501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62501
Added by naruse (Yui NARUSE) 8 months ago

merge revision(s) 62116,62151: [Backport #14425]

ruby.h: relax rb_funcall check on extra args for clang

clang 5.+ (tested clang 7.0.0) seems to be attempting division-by-zero
and giving a very large number for static args to rb_funcall.

* include/ruby/ruby.h (rb_varargs_bad_length): relax check for clang
* ext/-test-/funcall/funcall.c: renamed from passing_block.c
  define extra_args_name function
* test/-ext-/funcall/test_funcall.rb: new test
   [Bug #14425]

From: Eric Wong <e@80x24.org>

ruby.h: relax rb_funcall(obj, id, 0, 0) case only

* include/ruby/ruby.h (rb_varargs_argc_valid_p): relax rb_funcall
  check on extra args only if argc == 0, for the compatibility
  with wrong code which is probably confused with rb_funcallv.
  [Bug #14425]

History

#1 Updated by normalperson (Eric Wong) 9 months ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED

#3 Updated by Anonymous 9 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r62116.


ruby.h: relax rb_funcall check on extra args for clang

clang 5.+ (tested clang 7.0.0) seems to be attempting division-by-zero
and giving a very large number for static args to rb_funcall.

  • include/ruby/ruby.h (rb_varargs_bad_length): relax check for clang
  • ext/-test-/funcall/funcall.c: renamed from passing_block.c define extra_args_name function
  • test/-ext-/funcall/test_funcall.rb: new test [Bug #14425]

From: Eric Wong e@80x24.org

#4 [ruby-core:85267] Updated by mame (Yusuke Endoh) 9 months ago

normalperson (Eric Wong) wrote:

Attached are over 500 gem-codesearch results of latest gems.

nitpick: Your query includes rb_funcall2, rb_funcall3, and rb_funcallv which are safe to pass "0, 0".

#5 [ruby-core:85269] Updated by normalperson (Eric Wong) 9 months ago

mame@ruby-lang.org wrote:

normalperson (Eric Wong) wrote:

Attached are over 500 gem-codesearch results of latest gems.

nitpick: Your query includes rb_funcall2, rb_funcall3, and rb_funcallv which are safe to pass "0, 0".

Oops :x

Btw, I guess this is undefined behavior?
In a standalone case, gcc prints "0", clang prints a randomly high
number. I expected compilation to fail with both compilers.

 /* $CC -O2 -Wextra -Wall -o divzero /path/to/this/file.c */
 #include <stdio.h>
 int main(void)
 {
    int a = 0;
    int b = 1;
    int c = a / (a == b);

    printf("%d\n", c);
    return 0;
 }

#6 [ruby-core:85701] Updated by naruse (Yui NARUSE) 8 months ago

  • Backport changed from 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: DONE

ruby_2_5 r62501 merged revision(s) 62116,62151.

Also available in: Atom PDF