geiger-rs / cargo-geiger

Detects usage of unsafe Rust in a Rust crate and its dependencies.
https://crates.io/crates/cargo-geiger
1.41k stars 66 forks source link

Unrecognized literal c"" #517

Open mleonhard opened 7 months ago

mleonhard commented 7 months ago

Cargo-geiger 11.7 crashes when it encounters Rust code that uses C-style string literals which were introduced in Rust v1.77.

user@Users-MBP build-data % cat Cargo.toml               
[package]
name = "build-data"
repository = "https://gitlab.com/leonhard-llc/ops"
...
user@Users-MBP build-data % git show |head -n 1
commit 6f99a63717effa72a9bfc2d950c8614cafab9b5d
user@Users-MBP build-data % ~/.cargo/bin/cargo-geiger
cargo-geiger 0.11.7
user@Users-MBP build-data % ~/.cargo/bin/cargo-geiger
...
{"$message_type":"artifact","artifact":"/Users/user/ops/target/debug/deps/libtest_set_git_commit-b34cd715ff6be484.rmeta","emit":"metadata"}
    Finished dev [unoptimized + debuginfo] target(s) in 5.88s
thread '<unnamed>' panicked at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-1.0.109/src/lit.rs:1020:13:                                    
Unrecognized literal: `c""`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
user@Users-MBP build-data % RUST_BACKTRACE=1 ~/.cargo/bin/cargo-geiger
{"$message_type":"artifact","artifact":"/Users/user/ops/target/debug/deps/libtest_set_source_date-9f40d682582364bb.rmeta","emit":"metadata"}
    Finished dev [unoptimized + debuginfo] target(s) in 8.17s
thread '<unnamed>' panicked at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-1.0.109/src/lit.rs:1020:13:                                    
Unrecognized literal: `c""`
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: syn::lit::value::<impl syn::lit::Lit>::new
   3: syn::parse::ParseBuffer::step
   4: <syn::lit::Lit as syn::token::Token>::peek::peek
   5: syn::token::peek_impl
   6: syn::expr::parsing::trailer_expr
   7: syn::expr::parsing::unary_expr
   8: syn::expr::parsing::<impl syn::parse::Parse for syn::expr::Expr>::parse
   9: syn::punctuated::Punctuated<T,P>::parse_terminated_with
  10: syn::expr::parsing::trailer_helper
  11: syn::expr::parsing::trailer_expr
  12: syn::expr::parsing::unary_expr
  13: syn::expr::parsing::expr_early
  14: syn::stmt::parsing::stmt_expr
  15: syn::stmt::parsing::parse_stmt
  16: syn::stmt::parsing::<impl syn::stmt::Block>::parse_within
  17: syn::item::parsing::parse_rest_of_fn
 18: syn::item::parsing::<impl syn::parse::Parse for syn::item::Item>::parse                                                                                        
  19: syn::file::parsing::<impl syn::parse::Parse for syn::file::File>::parse
  20: syn::parse::Parser::parse_str
  21: syn::parse_file
  22: geiger::find::find_unsafe_in_string
  23: geiger::find::find_unsafe_in_file
...
pinkforest commented 7 months ago

Great find - would you like to send a PR ?

thanks very much for raising the issue

noncombatant commented 4 months ago

I'm having the same problem, but on a file that does not contain c"" or cr"" (!). Here's the end of my stack trace:

    Finished dev [unoptimized + debuginfo] target(s) in 8.34s
thread '<unnamed>' panicked at /home/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-1.0.109/src/lit.rs:1020:13:
Unrecognized literal: `c""`
stack backtrace:
   0:     0x606eb68aa325 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1e1a1972118942ad
   1:     0x606eb68da22b - core::fmt::write::hc090a2ffd6b28c4a
   2:     0x606eb68a544f - std::io::Write::write_fmt::h8898bac6ff039a23
   3:     0x606eb68aa0fe - std::sys_common::backtrace::print::ha96650907276675e
   4:     0x606eb68abd89 - std::panicking::default_hook::{{closure}}::h215c2a0a8346e0e0
   5:     0x606eb68abacd - std::panicking::default_hook::h207342be97478370
   6:     0x606eb68ac223 - std::panicking::rust_panic_with_hook::hac8bdceee1e4fe2c
   7:     0x606eb68ac104 - std::panicking::begin_panic_handler::{{closure}}::h00d785e82757ce3c
   8:     0x606eb68aa7e9 - std::sys_common::backtrace::__rust_end_short_backtrace::h1628d957bcd06996
   9:     0x606eb68abe37 - rust_begin_unwind
  10:     0x606eb5a70483 - core::panicking::panic_fmt::hdc63834ffaaefae5
  11:     0x606eb5b31502 - syn::lit::value::<impl syn::lit::Lit>::new::hfb4d5c148d655db8
  12:     0x606eb5c081ac - syn::parse::ParseBuffer::step::h4aa41d710875974a
  13:     0x606eb5b32178 - <syn::lit::Lit as syn::token::Token>::peek::peek::h0b1276c450fe66e8
  14:     0x606eb5b2fdef - syn::token::peek_impl::h82befc9cfc9ff952
  15:     0x606eb5b7c890 - syn::expr::parsing::trailer_expr::h5ca4c62cc46c0dd3
  16:     0x606eb5b7bd96 - syn::expr::parsing::unary_expr::h3572ce70ee9ee04b
  17:     0x606eb5b7f0c1 - syn::expr::parsing::trailer_helper::hcb2d736a7a3a19f2
  18:     0x606eb5b7d892 - syn::expr::parsing::trailer_expr::h5ca4c62cc46c0dd3
  19:     0x606eb5b7bd96 - syn::expr::parsing::unary_expr::h3572ce70ee9ee04b
  20:     0x606eb5b83a17 - syn::expr::parsing::expr_early::h178a4e468e01c3fc
  21:     0x606eb5bf2c59 - syn::stmt::parsing::stmt_expr::h9e96ba448ed8e3d3
  22:     0x606eb5bf24a2 - syn::stmt::parsing::parse_stmt::h9ac1b48323763767
  23:     0x606eb5c053ad - syn::stmt::parsing::<impl syn::stmt::Block>::parse_within::h531e85b3afe0efd2
  24:     0x606eb5b6a9fa - syn::item::parsing::parse_rest_of_fn::h0612f66db3283eec
  25:     0x606eb5b9d799 - syn::item::parsing::<impl syn::parse::Parse for syn::item::Item>::parse::h54e6f4d0823f0914
  26:     0x606eb5b70ed6 - syn::file::parsing::<impl syn::parse::Parse for syn::file::File>::parse::h165955b965494051
  27:     0x606eb5c0a219 - syn::parse::Parser::parse_str::h93b223921061f410
  28:     0x606eb5b5cd24 - syn::parse_file::hc64baafb9d54e086
  29:     0x606eb5af4a9f - geiger::find::find_unsafe_in_string::h35ff9be001b7249d
  30:     0x606eb5af48cc - geiger::find::find_unsafe_in_file::h81675ae16e1d145a
  31:     0x606eb5a9237c - core::ops::function::impls::<impl core::ops::function::Fn<A> for &F>::call::h14079d42c75e4c03
  32:     0x606eb5ab9294 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::hdf6a485831e4b75e
  33:     0x606eb5ab7cd4 - rayon::iter::plumbing::bridge_producer_consumer::helper::hffa773b200d4747f
  34:     0x606eb5ab4618 - rayon_core::join::join_context::{{closure}}::h931e9ec32bcf3729
  35:     0x606eb5ab7f6e - rayon::iter::plumbing::bridge_producer_consumer::helper::hffa773b200d4747f
  36:     0x606eb5ab4769 - rayon_core::join::join_context::{{closure}}::h931e9ec32bcf3729
  37:     0x606eb5ab7f6e - rayon::iter::plumbing::bridge_producer_consumer::helper::hffa773b200d4747f
  38:     0x606eb5ab4618 - rayon_core::join::join_context::{{closure}}::h931e9ec32bcf3729
  39:     0x606eb5ab7f6e - rayon::iter::plumbing::bridge_producer_consumer::helper::hffa773b200d4747f
  40:     0x606eb5ab4769 - rayon_core::join::join_context::{{closure}}::h931e9ec32bcf3729
  41:     0x606eb5ab7f6e - rayon::iter::plumbing::bridge_producer_consumer::helper::hffa773b200d4747f
  42:     0x606eb5ab4618 - rayon_core::join::join_context::{{closure}}::h931e9ec32bcf3729
  43:     0x606eb5ab7f6e - rayon::iter::plumbing::bridge_producer_consumer::helper::hffa773b200d4747f
  44:     0x606eb5ab8556 - <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::h8d2f3b233555a49a
  45:     0x606eb5a07046 - rayon_core::registry::WorkerThread::wait_until_cold::h097633a4d221cea9
  46:     0x606eb5aed192 - rayon_core::registry::ThreadBuilder::run::h892fe44123d3e235
  47:     0x606eb5af1b4a - std::sys_common::backtrace::__rust_begin_short_backtrace::h132762fe01fe5ede
  48:     0x606eb5af2d92 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hcc50bb7143426d50
  49:     0x606eb68b356b - std::sys::pal::unix::thread::Thread::new::thread_start::h522bc89a54da820a
Failed to parse file: /home/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/locale-0.2.2/src/linux/langinfo.rs, Syn(Error("expected one of: `::`, `<`, `_`, literal, `const`, `ref`, `mut`, `&`, parentheses, square brackets, `..`, `const`"), "/home/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/locale-0.2.2/src/linux/langinfo.rs") 
  50:     0x71b57989ca94 - start_thread
                               at ./nptl/pthread_create.c:447:8
  51:     0x71b579929c3c - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
  52:                0x0 - <unknown>

and I've attached langinfo.rs. langinfo.rs.txt

~ % grep '""' langinfo.rs 
        return Cow::Borrowed("");
renegadevi commented 4 months ago

I'm getting the same problem with Syn.

Apple M1 Pro Sonoma 14.2.1 (23C71) rust 1.79.0

Finished dev [unoptimized + debuginfo] target(s) in 8.04s
thread '<unnamed>' panicked at /Users/renegadevi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-1.0.109/src/lit.rs:1020:13:
Unrecognized literal: `c""`
stack backtrace:
   0:        0x1051d1f20 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1f3776e0b5c7517d
   1:        0x1051f5b90 - core::fmt::write::heedef092c8c0962e
   2:        0x1051cd0a4 - std::io::Write::write_fmt::h7178e8e2ea928914
   3:        0x1051d1d78 - std::sys_common::backtrace::print::h417292deb95532ed
   4:        0x1051d34ac - std::panicking::default_hook::{{closure}}::h0cb68f1228c4613a
   5:        0x1051d31a0 - std::panicking::default_hook::h24535936bc1f51de
   6:        0x1051d3d64 - std::panicking::rust_panic_with_hook::h5db4d2345b297bed
   7:        0x1051d3794 - std::panicking::begin_panic_handler::{{closure}}::h3fd558f09a0d5492
   8:        0x1051d23a8 - std::sys_common::backtrace::__rust_end_short_backtrace::hfc76eebe1ce501b2
   9:        0x1051d3504 - _rust_begin_unwind
  10:        0x1052656bc - core::panicking::panic_fmt::hc2b459a5bd3dce66
  11:        0x1047aef0c - syn::lit::value::<impl syn::lit::Lit>::new::h1f7576cd3b91be9b
  12:        0x10479c68c - syn::parse::ParseBuffer::step::h9eceaa444b8fe160
  13:        0x1047af124 - <syn::lit::Lit as syn::token::Token>::peek::peek::h3a66aefe555683f2
  14:        0x1047ad668 - syn::token::peek_impl::ha93cb6cca2bc89b9
  15:        0x1047c84d0 - syn::expr::parsing::trailer_expr::hf69794986f346c44
  16:        0x1047c7a74 - syn::expr::parsing::unary_expr::h6c044be2ef6ab460
  17:        0x1047ca7a4 - syn::expr::parsing::trailer_helper::ha62cbf4929ba75b6
  18:        0x1047c92e0 - syn::expr::parsing::trailer_expr::hf69794986f346c44
  19:        0x1047c7a74 - syn::expr::parsing::unary_expr::h6c044be2ef6ab460
  20:        0x1047ce66c - syn::expr::parsing::expr_early::h44d9f35f22a9b5f9
  21:        0x1047e6220 - syn::stmt::parsing::stmt_expr::hcbda970467f06193
  22:        0x1047e59a8 - syn::stmt::parsing::parse_stmt::h5699172044404959
  23:        0x104798cc4 - syn::stmt::parsing::<impl syn::stmt::Block>::parse_within::hf0785c26897c2aa0
  24:        0x10477a814 - syn::item::parsing::parse_rest_of_fn::he9ea6083a179a722
  25:        0x1047357dc - syn::item::parsing::<impl syn::parse::Parse for syn::item::Item>::parse::hd3416435ca046d02
  26:        0x10477f528 - syn::file::parsing::<impl syn::parse::Parse for syn::file::File>::parse::h2b41c082cfc28dfe
  27:        0x10479d098 - syn::parse::Parser::parse_str::h75c942e1d1d312de
  28:        0x10478d708 - syn::parse_file::h3c4332eb452bf7a6
  29:        0x104723044 - geiger::find::find_unsafe_in_string::h47ef3038b34d70b4
  30:        0x104722eac - geiger::find::find_unsafe_in_file::h04fecf477c6b10ab
  31:        0x1046ea884 - core::ops::function::impls::<impl core::ops::function::Fn<A> for &F>::call::he0813a6bc6c09c5f
  32:        0x1046d0904 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::ha26ee5a58eb593b2
  33:        0x1046e8f20 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  34:        0x1046b03f4 - rayon_core::job::StackJob<L,F,R>::run_inline::h301377cad9257802
  35:        0x1046b0704 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  36:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  37:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  38:        0x1046b03f4 - rayon_core::job::StackJob<L,F,R>::run_inline::h301377cad9257802
  39:        0x1046b0704 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  40:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  41:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  42:        0x1046b03f4 - rayon_core::job::StackJob<L,F,R>::run_inline::h301377cad9257802
  43:        0x1046b0704 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  44:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  45:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  46:        0x1046b03f4 - rayon_core::job::StackJob<L,F,R>::run_inline::h301377cad9257802
  47:        0x1046b0704 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  48:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  49:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  50:        0x1046b05e0 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  51:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  52:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  53:        0x1046b5878 - <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::h6c742953a7a6c4f8
  54:        0x105207040 - rayon_core::registry::WorkerThread::wait_until_cold::h4db08d37f2408eb1
  55:        0x1046b0670 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  56:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  57:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  58:        0x1046b05e0 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  59:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  60:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  61:        0x1046b05e0 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  62:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  63:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  64:        0x1046b05e0 - rayon_core::join::join_context::{{closure}}::h4cfdedf5cb8b898e
  65:        0x1046b085c - rayon_core::registry::in_worker::h6b8f5641cb482008
  66:        0x1046e9018 - rayon::iter::plumbing::bridge_producer_consumer::helper::h3a652692c376b925
  67:        0x1046b5a98 - <rayon::vec::IntoIter<T> as rayon::iter::IndexedParallelIterator>::with_producer::hf1bf83710b87e4e2
  68:        0x1046efb98 - cargo_geiger::scan::find::find_unsafe_in_packages::h4523bb17ba77c3d5
  69:        0x1046e638c - rayon_core::scope::ScopeBase::execute_job_closure::hc8c1faa0a3fcc44b
  70:        0x1046b5240 - <rayon_core::job::HeapJob<BODY> as rayon_core::job::Job>::execute::hc35d77e4e13e6241
  71:        0x105207040 - rayon_core::registry::WorkerThread::wait_until_cold::h4db08d37f2408eb1
  72:        0x1046fa5dc - rayon_core::registry::ThreadBuilder::run::ha1f9d47de3c2bc22
  73:        0x104700518 - std::sys_common::backtrace::__rust_begin_short_backtrace::h366f50b1746c8fd6
  74:        0x1046ffd68 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h20a0ba0a42e2357e
  75:        0x1051da130 - std::sys::pal::unix::thread::Thread::new::thread_start::h50a0ef5291b272f3
  76:        0x18307e034 - __pthread_joiner_wake