Skip to content

Fix linting line end #9518

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

Closed
wants to merge 1 commit into from
Closed

Fix linting line end #9518

wants to merge 1 commit into from

Conversation

mikhailnov
Copy link
Contributor

str is an array, but *str points to its beginning, that does not make sense and will never be true.

Fixes: 989a6f1 ("ruby.c: simplify")

I am not sure that this patch is correct!

I came across this code while debugging the following crash:
create a file with the following line:
#!ruby --enable
and run:
ruby file
It crashes. This patch does not fix this crash, but I came across the changed code while debugging it...

@nobu
Copy link
Member

nobu commented Jan 13, 2024

What do you mean by "It crashes"?

It seems to exit with an error as expected.

$ echo '#!ruby --enable' > test.rb
$ ruby test.rb 
ruby: missing argument for --enable (RuntimeError)
bash: exit 1
$ echo $'#!ruby --enable\r' > test.rb
$ ruby test.rb 
ruby: warning: shebang line ending with \r may cause problems
ruby: missing argument for --enable (RuntimeError)
bash: exit 1

@mikhailnov
Copy link
Contributor Author

I tried with ruby v2.7.8, but a colleague of mine told me that the newest version still crashes. Maybe it was a mistake and it does not crash. Still, I can't understand why it crashes, why is_option_with_arg("enable", Qtrue, Qtrue) returns true. It returns false when running ruby --enable.
What about the patch? Does it make sense?

@mikhailnov
Copy link
Contributor Author

Here is code which makes latest ruby master (from commit 0520e96) crash in the same code paths:
#!ruby -0 --disable

Backtrace from gdb:

(gdb) bt
#0  0x000055555575802b in ruby_each_words (str=0xe791 <error: Cannot access memory at address 0xe791>, func=func@entry=0x5555556e4f60 <disable_option>, arg=arg@entry=0x7fffffffdca0)
    at util.c:599
#1  0x00005555556e7535 in proc_long_options (envopt=0, envopt@entry=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, argv=<optimized out>, 
    argc=<optimized out>, s=<optimized out>, opt=0x7fffffffdc50, opt@entry=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>) at ruby.c:1400
#2  proc_options (argc=<optimized out>, argv=<optimized out>, opt=0x7fffffffdc50, envopt=0) at ruby.c:1694
#3  0x00005555556e7f21 in moreswitches (s=<optimized out>, opt=opt@entry=0x7fffffffdc50, envopt=envopt@entry=0) at ruby.c:933
#4  0x00005555556e89e6 in load_file_internal (argp_v=argp_v@entry=140737488341264) at ruby.c:2571
#5  0x0000555555597ba9 in rb_ensure (b_proc=b_proc@entry=0x5555556e8710 <load_file_internal>, data1=data1@entry=140737488341264, e_proc=e_proc@entry=0x5555556e4df0 <restore_load_file>, 
    data2=data2@entry=140737488341264) at eval.c:1009
#6  0x00005555556ea3ec in load_file (opt=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, 
    script=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, f=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, 
    fname=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, 
    parser=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>) at ruby.c:2760
#7  process_options (argc=0, argv=<optimized out>, opt=0x7fffffffdc50) at ruby.c:2296
#8  0x00005555556eaea8 in ruby_process_options (argc=argc@entry=2, argv=argv@entry=0x7fffffffdf18) at ruby.c:229
#9  0x00005555555968df in ruby_options (argc=2, argv=0x7fffffffdf18) at eval.c:121
#10 0x00005555555916eb in rb_main (argv=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, 
    argc=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>) at ./main.c:39
#11 main (argc=<optimized out>, argv=<optimized out>) at ./main.c:58

@mikhailnov
Copy link
Contributor Author

PR about #!ruby -0 --disable: #9562

str is an array, but *str points to its beginning,
that does not make sense and will never be true.

Fixes: 989a6f1 ("ruby.c: simplify")
@nobu
Copy link
Member

nobu commented Sep 27, 2024

Closed by #9575

@nobu nobu closed this Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants