From c1ba7c643cfdb43345ba1924e441077377bcfef6 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Fri, 11 Oct 2019 20:31:10 -0400 Subject: [PATCH] Remove unused argument to avoid UB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `OneOfDescriptor_each` is registered as a Ruby method which takes zero parameters, which means it should take one argument. When Ruby invokes `OneOfDescriptor_each`, it calls it with one parameter only, which is one less than what `OneOfDescriptor_each` takes before this commit. Calling a function with the wrong number of argument is technically undefined behavior. See also: ยง6.5.2.2, N1256 --- ruby/ext/google/protobuf_c/defs.c | 2 +- ruby/ext/google/protobuf_c/protobuf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby/ext/google/protobuf_c/defs.c b/ruby/ext/google/protobuf_c/defs.c index dd1c2d8317..d092a5bf09 100644 --- a/ruby/ext/google/protobuf_c/defs.c +++ b/ruby/ext/google/protobuf_c/defs.c @@ -1232,7 +1232,7 @@ VALUE OneofDescriptor_name(VALUE _self) { * * Iterates through fields in this oneof, yielding to the block on each one. */ -VALUE OneofDescriptor_each(VALUE _self, VALUE field) { +VALUE OneofDescriptor_each(VALUE _self) { DEFINE_SELF(OneofDescriptor, self, _self); upb_oneof_iter it; for (upb_oneof_begin(&it, self->oneofdef); diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 6314b78810..7cab5641d7 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -259,7 +259,7 @@ OneofDescriptor* ruby_to_OneofDescriptor(VALUE value); VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie, VALUE descriptor_pool, VALUE ptr); VALUE OneofDescriptor_name(VALUE _self); -VALUE OneofDescriptor_each(VALUE _self, VALUE field); +VALUE OneofDescriptor_each(VALUE _self); void EnumDescriptor_mark(void* _self); void EnumDescriptor_free(void* _self);