Skip to content

Commit 7d40924

Browse files
authored
fix: Unbreak the fuzzer more (#2552)
* fix: Link `freebl_static` on static link * More static * Less * More * pk11wrap * More * sqlite3 * sqlite * More * More * Finalize * Debug Windows * Fix * Minimize
1 parent 79527ab commit 7d40924

File tree

4 files changed

+68
-20
lines changed

4 files changed

+68
-20
lines changed

fuzz/fuzz_targets/client_initial.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ use libfuzzer_sys::fuzz_target;
66
#[cfg(all(fuzzing, not(windows)))]
77
fuzz_target!(|data: &[u8]| {
88
use neqo_common::{Datagram, Encoder, Role};
9-
use neqo_transport::{packet::MIN_INITIAL_PACKET_SIZE, Version};
9+
use neqo_transport::{packet::MIN_INITIAL_PACKET_SIZE, ConnectionParameters, Version};
1010
use test_fixture::{
11-
default_client, default_server,
1211
header_protection::{
1312
apply_header_protection, decode_initial_header, initial_aead_and_hp,
1413
remove_header_protection,
1514
},
16-
now,
15+
new_client, new_server, now, DEFAULT_ALPN,
1716
};
1817

19-
let mut client = default_client();
18+
let mut client = new_client(ConnectionParameters::default().mlkem(false));
2019
let ci = client.process_output(now()).dgram().expect("a datagram");
2120
let Some((header, d_cid, s_cid, payload)) = decode_initial_header(&ci, Role::Client) else {
2221
return;
@@ -59,7 +58,7 @@ fuzz_target!(|data: &[u8]| {
5958
);
6059
let fuzzed_ci = Datagram::new(ci.source(), ci.destination(), ci.tos(), ciphertext);
6160

62-
let mut server = default_server();
61+
let mut server = new_server(DEFAULT_ALPN, ConnectionParameters::default().mlkem(false));
6362
let _response = server.process(Some(fuzzed_ci), now());
6463
});
6564

fuzz/fuzz_targets/server_initial.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ use libfuzzer_sys::fuzz_target;
66
#[cfg(all(fuzzing, not(windows)))]
77
fuzz_target!(|data: &[u8]| {
88
use neqo_common::{Datagram, Encoder, Role};
9-
use neqo_transport::{packet::MIN_INITIAL_PACKET_SIZE, Version};
9+
use neqo_transport::{packet::MIN_INITIAL_PACKET_SIZE, ConnectionParameters, Version};
1010
use test_fixture::{
11-
default_client, default_server,
1211
header_protection::{
1312
apply_header_protection, decode_initial_header, initial_aead_and_hp,
1413
remove_header_protection,
1514
},
16-
now,
15+
new_client, new_server, now, DEFAULT_ALPN,
1716
};
1817

19-
let mut client = default_client();
18+
let mut client = new_client(ConnectionParameters::default().mlkem(false));
2019
let ci = client.process_output(now()).dgram().expect("a datagram");
21-
let mut server = default_server();
20+
let mut server = new_server(DEFAULT_ALPN, ConnectionParameters::default().mlkem(false));
2221
let si = server.process(Some(ci), now()).dgram().expect("a datagram");
2322

2423
let Some((header, d_cid, s_cid, payload)) = decode_initial_header(&si, Role::Server) else {

neqo-crypto/build.rs

+42-8
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ fn dynamic_link() {
149149
}
150150

151151
fn static_link() {
152-
let static_libs = [
152+
let mut static_libs = vec![
153153
"certdb",
154154
"certhi",
155155
"cryptohi",
156-
"freebl",
156+
"freebl_static",
157157
if env::consts::OS == "windows" {
158158
"libnspr4"
159159
} else {
@@ -164,9 +164,7 @@ fn static_link() {
164164
"nssdev",
165165
"nsspki",
166166
"nssutil",
167-
"pk11wrap",
168-
"pkcs12",
169-
"pkcs7",
167+
"pk11wrap_static",
170168
if env::consts::OS == "windows" {
171169
"libplc4"
172170
} else {
@@ -177,10 +175,46 @@ fn static_link() {
177175
} else {
178176
"plds4"
179177
},
180-
"smime",
181178
"softokn_static",
182179
"ssl",
183180
];
181+
// macOS always dynamically links against the system sqlite library.
182+
// See https://github.com/nss-dev/nss/blob/a8c22d8fc0458db3e261acc5e19b436ab573a961/coreconf/Darwin.mk#L130-L135
183+
if env::consts::OS == "macos" {
184+
println!("cargo:rustc-link-lib=dylib=sqlite3");
185+
} else {
186+
static_libs.push("sqlite");
187+
}
188+
// Hardware specific libs.
189+
// See https://github.com/mozilla/application-services/blob/0a2dac76f979b8bcfb6bacb5424b50f58520b8fe/components/support/rc_crypto/nss/nss_build_common/src/lib.rs#L127-L157
190+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
191+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
192+
// https://searchfox.org/nss/rev/0d5696b3edce5124353f03159d2aa15549db8306/lib/freebl/freebl.gyp#508-542
193+
if target_arch == "arm" || target_arch == "aarch64" {
194+
static_libs.push("armv8_c_lib");
195+
}
196+
if target_arch == "x86_64" || target_arch == "x86" {
197+
static_libs.push("gcm-aes-x86_c_lib");
198+
static_libs.push("sha-x86_c_lib");
199+
}
200+
if target_arch == "arm" {
201+
static_libs.push("gcm-aes-arm32-neon_c_lib");
202+
}
203+
if target_arch == "aarch64" {
204+
static_libs.push("gcm-aes-aarch64_c_lib");
205+
}
206+
if target_arch == "x86_64" {
207+
static_libs.push("hw-acc-crypto-avx");
208+
static_libs.push("hw-acc-crypto-avx2");
209+
}
210+
// https://searchfox.org/nss/rev/08c4d05078d00089f8d7540651b0717a9d66f87e/lib/freebl/freebl.gyp#315-324
211+
if (target_os == "android" || target_os == "linux") && target_arch == "x86_64" {
212+
static_libs.push("intel-gcm-wrap_c_lib");
213+
// https://searchfox.org/nss/rev/08c4d05078d00089f8d7540651b0717a9d66f87e/lib/freebl/freebl.gyp#43-47
214+
if (target_os == "android" || target_os == "linux") && target_arch == "x86_64" {
215+
static_libs.push("intel-gcm-s_lib");
216+
}
217+
}
184218
for lib in static_libs {
185219
println!("cargo:rustc-link-lib=static={lib}");
186220
}
@@ -331,9 +365,9 @@ fn setup_standalone(nss: &str) -> Vec<String> {
331365
"cargo:rustc-link-search=native={}",
332366
nsslibdir.to_str().unwrap()
333367
);
334-
// FIXME: NSPR doesn't build proper dynamic libraries on Windows.
335368
if env::var("CARGO_CFG_FUZZING").is_ok()
336-
|| env::var("DEBUG").is_ok()
369+
|| env::var("PROFILE").unwrap_or_default() == "debug"
370+
// FIXME: NSPR doesn't build proper dynamic libraries on Windows.
337371
|| env::consts::OS == "windows"
338372
{
339373
static_link();

test-fixture/src/lib.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ pub mod header_protection;
3838
pub mod sim;
3939

4040
/// The path for the database used in tests.
41-
pub const NSS_DB_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/db");
41+
///
42+
/// Initialized via the `NSS_DB_PATH` environment variable. If that is not set,
43+
/// it defaults to the `db` directory in the current crate. If the environment
44+
/// variable is set to `$ARGV0`, it will be initialized to the directory of the
45+
/// current executable.
46+
pub const NSS_DB_PATH: &str = if let Some(dir) = option_env!("NSS_DB_PATH") {
47+
dir
48+
} else {
49+
concat!(env!("CARGO_MANIFEST_DIR"), "/db")
50+
};
4251

4352
/// Initialize the test fixture. Only call this if you aren't also calling a
4453
/// fixture function that depends on setup. Other functions in the fixture
@@ -48,7 +57,14 @@ pub const NSS_DB_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/db");
4857
///
4958
/// When the NSS initialization fails.
5059
pub fn fixture_init() {
51-
init_db(NSS_DB_PATH).unwrap();
60+
if NSS_DB_PATH == "$ARGV0" {
61+
let mut current_exe = std::env::current_exe().unwrap();
62+
current_exe.pop();
63+
let nss_db_path = current_exe.to_str().unwrap();
64+
init_db(nss_db_path).unwrap();
65+
} else {
66+
init_db(NSS_DB_PATH).unwrap();
67+
}
5268
}
5369

5470
// This needs to be > 2ms to avoid it being rounded to zero.

0 commit comments

Comments
 (0)