Skip to content

Fixes format-security error when compiling ruby_193_compatible.h #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2016

Conversation

RJPercival
Copy link
Contributor

Fixes #516. When compiling the extension for Ruby 1.9 on a system that treats format-security warnings as errors (i.e. the Makefile generated for the extension contains "-Werror=format-security"), compilation would fail with the following error:

compiling atomic_boolean.c
In file included from atomic_boolean.c:5:0:
ruby_193_compatible.h: In function 'rb_error_arity':
ruby_193_compatible.h:20:3: warning: passing argument 2 of 'rb_raise' makes pointer from integer without a cast [enabled by
 default]
   rb_raise(rb_eTypeError, err_mess);
   ^
In file included from /usr/include/ruby-1.9.1/ruby.h:32:0,
                 from atomic_boolean.c:1:
/usr/include/ruby-1.9.1/ruby/ruby.h:1172:27: note: expected 'const char *' but argument is of type 'VALUE'
 PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
#ifndef rb_check_arity
                           ^
/usr/include/ruby-1.9.1/ruby/ruby.h:42:3: note: in definition of macro 'PRINTF_ARGS'
   decl __attribute__((format(printf, string_index, first_to_check)))
   ^
/usr/include/ruby-1.9.1/ruby/ruby.h:1172:13: note: in expansion of macro 'NORETURN'
 PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
             ^
In file included from atomic_boolean.c:5:0:
ruby_193_compatible.h:20:3: error: format not a string literal and no format arguments [-Werror=format-security]
   rb_raise(rb_eTypeError, err_mess);
   ^
cc1: some warnings being treated as errors
make: *** [atomic_boolean.o] Error 1

This updates the functions in ruby_193_compatible.h to work more like the original copies (found in the Ruby 2.0+ source code), which avoids this compilation error.

@@ -17,12 +17,12 @@ static inline void rb_error_arity(int argc, int min, int max)
else {
err_mess = rb_sprintf("wrong number of arguments (%d for %d..%d)", argc, min, max);
}
rb_raise(rb_eTypeError, err_mess);
return rb_ext_new3(rb_eTypeError, err_mess);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you find the documentation on rb_ext_new3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that's supposed to be rb_exc_new3 - fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised the Travis build succeeded. It looks like the extension is being compiled with very lenient settings, to the extent that calling non-existent functions isn't even considered an error!

When compiling the extension for Ruby 1.9 on a system that treats format-security warnings as errors (i.e. the Makefile generated for the extension contains "-Werror=format-security"), compilation would fail with the following error:

```
compiling atomic_boolean.c
In file included from atomic_boolean.c:5:0:
ruby_193_compatible.h: In function 'rb_error_arity':
ruby_193_compatible.h:20:3: warning: passing argument 2 of 'rb_raise' makes pointer from integer without a cast [enabled by
 default]
   rb_raise(rb_eTypeError, err_mess);
   ^
In file included from /usr/include/ruby-1.9.1/ruby.h:32:0,
                 from atomic_boolean.c:1:
/usr/include/ruby-1.9.1/ruby/ruby.h:1172:27: note: expected 'const char *' but argument is of type 'VALUE'
 PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
                           ^
/usr/include/ruby-1.9.1/ruby/ruby.h:42:3: note: in definition of macro 'PRINTF_ARGS'
   decl __attribute__((format(printf, string_index, first_to_check)))
   ^
/usr/include/ruby-1.9.1/ruby/ruby.h:1172:13: note: in expansion of macro 'NORETURN'
 PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
             ^
In file included from atomic_boolean.c:5:0:
ruby_193_compatible.h:20:3: error: format not a string literal and no format arguments [-Werror=format-security]
   rb_raise(rb_eTypeError, err_mess);
   ^
cc1: some warnings being treated as errors
make: *** [atomic_boolean.o] Error 1
```

This updates these functions to work more like the original copies (found in the Ruby 2.0+ source code), which avoids this compilation error.
@RJPercival RJPercival force-pushed the format-security-error branch from 316e043 to b3fa771 Compare June 8, 2016 14:47
@pitr-ch pitr-ch added the bug A bug in the library or documentation. label Jun 11, 2016
@pitr-ch pitr-ch added this to the 1.0.3 milestone Jun 11, 2016
@pitr-ch
Copy link
Member

pitr-ch commented Jun 11, 2016

@RJPercival Thanks very much for the fix. I'll defer to @jdantonio for review though.

@jdantonio
Copy link
Member

Thank you!

@jdantonio jdantonio merged commit 13c6202 into ruby-concurrency:master Jun 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in the library or documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants