Project

General

Profile

Bug #14425

rb_funcall too strict on extra args

Added by normalperson (Eric Wong) 21 days ago. Updated 20 days 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 62116
Added by normal 21 days 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 62151
Added by nobu (Nobuyoshi Nakada) 19 days 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]

History

#1 Updated by normalperson (Eric Wong) 21 days 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 21 days 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) 21 days 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) 20 days 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;
 }

Also available in: Atom PDF