Skip to content
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

Incorrect net API attribution to futures-util crate #7

Closed
repi opened this issue Aug 19, 2023 · 3 comments
Closed

Incorrect net API attribution to futures-util crate #7

repi opened this issue Aug 19, 2023 · 3 comments

Comments

@repi
Copy link

repi commented Aug 19, 2023

In one of our bigger projects where we use hyper, rustls, we get this problem highlighted by cackle attributed to the futures-util crate, but as far as I can see it doesn't use any of the std::net functions. But it is a generic type here that are used in other crates with their network types.


ERROR: 'futures-util' uses disallowed APIs:
  net:
    /home/repi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/future/future/map.rs
      <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
        -> call_once<hyper::client::client::{impl#3}::connect_to::{closure#0}::{closure_env#0}<hyper_rustls::connector::HttpsConnector<hyper::client::connect::http::HttpConnector<hyper::client::connect::dns::GaiResolver>>, http_body::full::Full<bytes::bytes::Bytes>>, hyper_rustls::stream::MaybeHttpsStream<tokio::net::tcp::stream::TcpStream>, hyper::error::Error> [57:73]
        -> core::ptr::drop_in_place<core::result::Result<hyper_rustls::stream::MaybeHttpsStream<tokio::net::tcp::stream::TcpStream>,hyper::error::Error>> [60:13]
    /home/repi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/future/select.rs
      futures_util::future::select::select
        -> assert_future<futures_util::future::either::Either<(core::result::Result<tokio::net::tcp::stream::TcpStream, hyper::client::connect::http::ConnectError>, core::pin::Pin<&mut hyper::client::connect::http::{impl#14}::connect::{async_fn_env#0}>), (core::result::Result<tokio::net::tcp::stream::TcpStream, hyper::client::connect::http::ConnectError>, core::pin::Pin<&mut hyper::client::connect::http::{impl#14}::connect::{async_fn_env#0}>)>, futures_util::future::select::Select<core::pin::Pin<&mut hyper::client::connect::http::{impl#14}::connect::{async_fn_env#0}>, core::pin::Pin<&mut hyper::client::connect::http::{impl#14}::connect::{async_fn_env#0}>>> [89:5]
      futures_util::future::select::select
        -> assert_future<futures_util::future::either::Either<(core::result::Result<tokio::net::tcp::stream::TcpStream, hyper::client::connect::http::ConnectError>, core::pin::Pin<&mut tokio::time::sleep::Sleep>), ((), core::pin::Pin<&mut hyper::client::connect::http::{impl#14}::connect::{async_fn_env#0}>)>, futures_util::future::select::Select<core::pin::Pin<&mut hyper::client::connect::http::{impl#14}::connect::{async_fn_env#0}>, core::pin::Pin<&mut tokio::time::sleep::Sleep>>> [89:5]
      <futures_util::future::select::Select<A,B> as core::future::future::Future>::poll
        -> core::ptr::drop_in_place<core::result::Result<tokio::net::tcp::stream::TcpStream,hyper::client::connect::http::ConnectError>> [115:85]
        -> core::ptr::drop_in_place<core::task::poll::Poll<core::result::Result<tokio::net::tcp::stream::TcpStream,hyper::client::connect::http::ConnectError>>> [116:9]
      <futures_util::future::select::Select<A,B> as core::future::future::Future>::poll
        -> core::ptr::drop_in_place<core::task::poll::Poll<core::result::Result<tokio::net::tcp::stream::TcpStream,hyper::client::connect::http::ConnectError>>> [116:9]
        -> core::ptr::drop_in_place<core::task::poll::Poll<core::result::Result<tokio::net::tcp::stream::TcpStream,hyper::client::connect::http::ConnectError>>> [120:9]
        -> core::ptr::drop_in_place<core::result::Result<tokio::net::tcp::stream::TcpStream,hyper::client::connect::http::ConnectError>> [119:86]
        -> core::ptr::drop_in_place<core::result::Result<tokio::net::tcp::stream::TcpStream,hyper::client::connect::http::ConnectError>> [115:85]
    /home/repi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/future/try_future/into_future.rs
      <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
        -> try_poll<futures_util::future::try_future::MapErr<hyper::service::oneshot::Oneshot<hyper_rustls::connector::HttpsConnector<hyper::client::connect::http::HttpConnector<hyper::client::connect::dns::GaiResolver>>, http::uri::Uri>, fn(alloc::boxed::Box<(dyn core::error::Error + core::marker::Send + core::marker::Sync), alloc::alloc::Global>) -> hyper::error::Error>, hyper_rustls::stream::MaybeHttpsStream<tokio::net::tcp::stream::TcpStream>, hyper::error::Error> [34:9]
      <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
        -> try_poll<hyper::service::oneshot::Oneshot<hyper_rustls::connector::HttpsConnector<hyper::client::connect::http::HttpConnector<hyper::client::connect::dns::GaiResolver>>, http::uri::Uri>, hyper_rustls::stream::MaybeHttpsStream<tokio::net::tcp::stream::TcpStream>, alloc::boxed::Box<(dyn core::error::Error + core::marker::Send + core::marker::Sync), alloc::alloc::Global>> [34:9]
    /home/repi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/future/try_future/mod.rs
      futures_util::future::try_future::TryFutureExt::map_err
        -> assert_future<core::result::Result<hyper_rustls::stream::MaybeHttpsStream<tokio::net::tcp::stream::TcpStream>, hyper::error::Error>, futures_util::future::try_future::MapErr<hyper::service::oneshot::Oneshot<hyper_rustls::connector::HttpsConnector<hyper::client::connect::http::HttpConnector<hyper::client::connect::dns::GaiResolver>>, http::uri::Uri>, fn(alloc::boxed::Box<(dyn core::error::Error + core::marker::Send + core::marker::Sync), alloc::alloc::Global>) -> hyper::error::Error>> [313:9]
    /home/repi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/lib.rs
      <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
        -> poll<futures_util::future::try_future::into_future::IntoFuture<hyper::service::oneshot::Oneshot<hyper_rustls::connector::HttpsConnector<hyper::client::connect::http::HttpConnector<hyper::client::connect::dns::GaiResolver>>, http::uri::Uri>>, futures_util::fns::MapErrFn<fn(alloc::boxed::Box<(dyn core::error::Error + core::marker::Send + core::marker::Sync), alloc::alloc::Global>) -> hyper::error::Error>, core::result::Result<hyper_rustls::stream::MaybeHttpsStream<tokio::net::tcp::stream::TcpStream>, hyper::error::Error>> [91:13]

So believe the detection of this using net APIs is correct, but not for this crate, it should have been attributed to the crate using the generic type. So maybe a problem with handling/parsing of generic types and which crates get assigned the "problem"?

@repi
Copy link
Author

repi commented Aug 19, 2023

this one looks similar, for the pin-project-lite:

ERROR: 'pin-project-lite' uses disallowed APIs:
  net:
    /home/repi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.9/src/lib.rs
      hyper::service::oneshot::_::<impl hyper::service::oneshot::State<S,Req>>::project_replace
        -> new<core::pin::Pin<alloc::boxed::Box<(dyn core::future::future::Future<Output=core::result::Result<hyper_rustls::stream::MaybeHttpsStream<tokio::net::tcp::stream::TcpStream>, alloc::boxed::Box<(dyn core::error::Error + core::marker::Send + core::marker::Sync), alloc::alloc::Global>>> + core::marker::Send), alloc::alloc::Global>>> [1065:29]

@davidlattimore
Copy link
Collaborator

davidlattimore commented Aug 20, 2023

Attributing API usages to the right crate is definitely hard. The way it works at the moment is that each function name is split into parts and mapped to APIs. If the from-function matches an API, then we ignore matches for that API in the to-function.

So for example if foo::<std::path::Path> calls bar::<std::path::Path>, both match the "fs" API, then we don't consider foo::<std::path::Path> as using the "fs" API. Whatever calls foo::<std::path::Path> would instead be considered to use the "fs" API.

In the first example, there are from-functions like futures_util::future::select::select that are referencing functions with generics in tokio::net. So it looks like futures_util::future::select::select is generic, but the generic parameters are missing for some reason.

Until recently (some time in the last couple of days), cackle would always look for API usages in both the symbol name and the name from debug info. Now it uses the debug name if present and only falls back to the symbol if the debug name is missing. I'm not sure that change is related to this though. The debug name does tend to contain more useful information than the symbol.

@davidlattimore
Copy link
Collaborator

I looked into this some more. I think the issue is that the hyper crate provides trait implementations with associated types that are in tokio::net. This means that a function generic over one of these traits can access functions in tokio::net without any of the generic arguments themselves being in tokio::net.

I suspect the best fix to your config would be to add "hyper" to net API.

I'm going to try to get Cackle to detect this kind of situation and suggest appropriate edits to API definitions.

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

No branches or pull requests

2 participants