Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions src/boringssl_sys/boringssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ macro_rules! opaque {
/// `#define EVP_MAX_MD_SIZE 64` — SHA-512 is the longest digest.
pub const EVP_MAX_MD_SIZE: c_int = 64;

/// `#define RIPEMD160_DIGEST_LENGTH 20`
pub const RIPEMD160_DIGEST_LENGTH: c_int = 20;

/// `#define NID_commonName 13`
pub(crate) const NID_commonName: c_int = 13;
/// `#define NID_subject_alt_name 85`
Expand Down Expand Up @@ -194,29 +191,6 @@ pub struct SHA256_CTX {
pub md_len: c_uint,
}

/// `struct sha512_state_st`.
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SHA512_CTX {
pub h: [u64; 8],
pub num: u16,
pub md_len: u16,
pub bytes_so_far_high: u32,
pub bytes_so_far_low: u64,
pub p: [u8; 128],
}

/// `struct RIPEMD160state_st` (`vendor/boringssl/include/openssl/ripemd.h`).
#[repr(C)]
#[derive(Copy, Clone)]
pub struct RIPEMD160_CTX {
pub h: [u32; 5],
pub Nl: u32,
pub Nh: u32,
pub data: [u8; 64],
pub num: c_uint,
}

// ═══════════════════════════════════════════════════════════════════════════
// X509v3 GENERAL_NAME
// ═══════════════════════════════════════════════════════════════════════════
Expand Down Expand Up @@ -577,7 +551,6 @@ unsafe extern "C" {
// ── EVP digest getters (infallible, return static singletons) ────────
pub safe fn EVP_md4() -> *const EVP_MD;
pub safe fn EVP_md5() -> *const EVP_MD;
pub safe fn EVP_md5_sha1() -> *const EVP_MD;
pub safe fn EVP_ripemd160() -> *const EVP_MD;
pub safe fn EVP_sha1() -> *const EVP_MD;
pub safe fn EVP_sha224() -> *const EVP_MD;
Expand Down Expand Up @@ -653,30 +626,6 @@ unsafe extern "C" {
pub fn SHA256_Final(out: *mut u8, sha: *mut SHA256_CTX) -> c_int;
pub fn SHA256(data: *const u8, len: usize, out: *mut u8) -> *mut u8;

// ── SHA-384 ──────────────────────────────────────────────────────────
pub fn SHA384_Init(sha: *mut SHA512_CTX) -> c_int;
pub fn SHA384_Update(sha: *mut SHA512_CTX, data: *const c_void, len: usize) -> c_int;
pub fn SHA384_Final(out: *mut u8, sha: *mut SHA512_CTX) -> c_int;
pub fn SHA384(data: *const u8, len: usize, out: *mut u8) -> *mut u8;

// ── SHA-512 ──────────────────────────────────────────────────────────
pub fn SHA512_Init(sha: *mut SHA512_CTX) -> c_int;
pub fn SHA512_Update(sha: *mut SHA512_CTX, data: *const c_void, len: usize) -> c_int;
pub fn SHA512_Final(out: *mut u8, sha: *mut SHA512_CTX) -> c_int;
pub fn SHA512(data: *const u8, len: usize, out: *mut u8) -> *mut u8;

// ── SHA-512/256 ──────────────────────────────────────────────────────
pub fn SHA512_256_Init(sha: *mut SHA512_CTX) -> c_int;
pub fn SHA512_256_Update(sha: *mut SHA512_CTX, data: *const c_void, len: usize) -> c_int;
pub fn SHA512_256_Final(out: *mut u8, sha: *mut SHA512_CTX) -> c_int;
pub fn SHA512_256(data: *const u8, len: usize, out: *mut u8) -> *mut u8;

// ── RIPEMD-160 ───────────────────────────────────────────────────────
pub fn RIPEMD160_Init(ctx: *mut RIPEMD160_CTX) -> c_int;
pub fn RIPEMD160_Update(ctx: *mut RIPEMD160_CTX, data: *const c_void, len: usize) -> c_int;
pub fn RIPEMD160_Final(out: *mut u8, ctx: *mut RIPEMD160_CTX) -> c_int;
pub fn RIPEMD160(data: *const u8, len: usize, out: *mut u8) -> *mut u8;

// ── SSL ──────────────────────────────────────────────────────────────
pub safe fn SSL_library_init() -> c_int;
pub safe fn SSL_load_error_strings();
Expand Down Expand Up @@ -878,9 +827,7 @@ unsafe extern "C" {
pub fn SSL_CTX_free(ctx: *mut SSL_CTX);
pub fn SSL_CTX_get_verify_mode(ctx: *const SSL_CTX) -> c_int;
pub fn SSL_CTX_set_ex_data(ctx: *mut SSL_CTX, idx: c_int, data: *mut c_void) -> c_int;
pub fn SSL_CTX_get_ex_data(ctx: *const SSL_CTX, idx: c_int) -> *mut c_void;
pub fn SSL_CTX_set0_buffer_pool(ctx: *mut SSL_CTX, pool: *mut CRYPTO_BUFFER_POOL);
pub fn SSL_CTX_set_cipher_list(ctx: *mut SSL_CTX, str_: *const c_char) -> c_int;
pub fn SSL_CTX_set1_groups_list(ctx: *mut SSL_CTX, groups: *const c_char) -> c_int;
/// `enum ssl_compliance_policy_t` (int-sized via BORINGSSL_ENUM_INT).
pub fn SSL_CTX_set_compliance_policy(ctx: *mut SSL_CTX, policy: c_int) -> c_int;
Expand Down Expand Up @@ -991,7 +938,6 @@ unsafe extern "C" {
// Thread-local error queue — no pointer args, no preconditions.
pub safe fn ERR_clear_error();
pub safe fn ERR_get_error() -> u32;
pub safe fn ERR_peek_error() -> u32;
pub safe fn ERR_peek_last_error() -> u32;
pub fn ERR_error_string(packed_error: u32, buf: *mut c_char) -> *mut c_char;
// `ERR_error_string_n` declared once in the crypto/err block above.
Expand Down Expand Up @@ -1083,10 +1029,6 @@ opaque!(
/// `struct evp_pkey_st` (`typedef ... EVP_PKEY`).
EVP_PKEY
);
opaque!(
/// `struct ssl_cipher_st` (`typedef ... SSL_CIPHER`).
SSL_CIPHER
);
opaque!(
/// `struct ssl_session_st` (`typedef ... SSL_SESSION`).
SSL_SESSION
Expand All @@ -1105,10 +1047,6 @@ unsafe extern "C" {
pub fn SSL_CTX_use_PrivateKey(ctx: *mut SSL_CTX, pkey: *mut EVP_PKEY) -> c_int;

pub fn SSL_get_verify_result(ssl: *const SSL) -> c_long;
pub fn SSL_get_current_cipher(ssl: *const SSL) -> *const SSL_CIPHER;
pub fn SSL_CIPHER_standard_name(cipher: *const SSL_CIPHER) -> *const c_char;
pub fn SSL_CIPHER_get_name(cipher: *const SSL_CIPHER) -> *const c_char;
pub fn SSL_get_version(ssl: *const SSL) -> *const c_char;

pub fn PEM_read_bio_X509(
bp: *mut BIO,
Expand All @@ -1126,7 +1064,6 @@ unsafe extern "C" {

pub fn X509_verify_cert_error_string(err: c_long) -> *const c_char;

pub fn X509_STORE_free(store: *mut X509_STORE);
pub fn X509_STORE_add_cert(store: *mut X509_STORE, x509: *mut X509) -> c_int;
pub fn X509_STORE_add_crl(store: *mut X509_STORE, crl: *mut X509_CRL) -> c_int;
pub fn X509_STORE_set_flags(store: *mut X509_STORE, flags: c_ulong) -> c_int;
Expand All @@ -1144,12 +1081,6 @@ unsafe extern "C" {
/// Returns a BORROWED reference to the local certificate, or null.
pub fn SSL_get_certificate(ssl: *const SSL) -> *mut X509;

pub fn i2d_SSL_SESSION(session: *mut SSL_SESSION, pp: *mut *mut u8) -> c_int;
pub fn d2i_SSL_SESSION(
a: *mut *mut SSL_SESSION,
pp: *mut *const u8,
length: c_long,
) -> *mut SSL_SESSION;
pub fn SSL_set_session(ssl: *mut SSL, session: *mut SSL_SESSION) -> c_int;
pub fn SSL_SESSION_free(session: *mut SSL_SESSION);
}
7 changes: 0 additions & 7 deletions src/http/InternalState.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ impl InternalStateFlags {
}
}

impl Default for InternalStateFlags {
/// `allow_keepalive` defaults to true.
fn default() -> Self {
Self::new()
}
}

impl Default for InternalState<'_> {
fn default() -> Self {
Self {
Expand Down
15 changes: 1 addition & 14 deletions src/http/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,6 @@ pub struct HTTPResponseMetadata {
pub response: bun_picohttp::Response<'static>,
}

impl Default for HTTPResponseMetadata {
fn default() -> Self {
Self {
url: bun_ptr::RawSlice::EMPTY,
owned_buf: Box::default(),
response: bun_picohttp::Response::default(),
}
}
}

impl HTTPResponseMetadata {
/// Accessors tied to `&self`: `response` is typed `'static` but its slices
/// borrow the sibling `owned_buf` / header slice that `Drop` frees, so
Expand All @@ -157,10 +147,7 @@ impl HTTPResponseMetadata {
}

impl Drop for HTTPResponseMetadata {
// `owned_buf` is freed by
// `Box`'s own Drop; `response.headers.list` was `Box::leak`'d in
// `clone_metadata` and must be reclaimed here. `Default` / zero-header
// responses have an empty static slice, guarded by the len check.
// `response.headers.list` is `Box::leak`'d by `clone_metadata`; reclaim it here.
fn drop(&mut self) {
let list = self.response.headers.list;
if !list.is_empty() {
Expand Down
90 changes: 3 additions & 87 deletions src/install/PackageInstaller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use crate::bun_progress::{Node as ProgressNode, Progress};
use crate::lifecycle_script_runner::LifecycleScriptSubprocess;
// `Lockfile` here is the in-crate `crate::lockfile::Lockfile` (the
// struct `PackageManager.lockfile` actually carries). `lockfile_real` is still
// imported for `tree::Id` / `Tree` / `DependencySlice` / `package::*`, all of
// imported for `tree::Id` / `Tree` / `package::*`, all of
// which are the same types re-exported through `crate::lockfile`.
use crate::lockfile::Lockfile;
use crate::lockfile_real::package::{
self as Package, PackageColumns, scripts::Scripts as PackageScripts,
};
use crate::lockfile_real::{self as lockfile, DependencySlice, Tree};
use crate::lockfile_real::{self as lockfile, Tree};
use crate::network_task::ForTarballError;
use crate::package_install::{self, PackageInstall};
use crate::package_manager::{self, Options, PackageManager};
Expand Down Expand Up @@ -84,7 +84,6 @@ pub struct PackageInstaller<'a> {
// so it is also `RawSlice` here.
pub(crate) metas: bun_ptr::RawSlice<Package::Meta>,
pub(crate) names: bun_ptr::RawSlice<String>,
pub(crate) pkg_dependencies: bun_ptr::RawSlice<DependencySlice>,
pub(crate) pkg_name_hashes: bun_ptr::RawSlice<PackageNameHash>,
pub(crate) bins: bun_ptr::RawSlice<Bin>,
pub(crate) resolutions: bun_ptr::RawSlice<Resolution>,
Expand Down Expand Up @@ -361,48 +360,6 @@ fn abs_node_modules_path(
abs
}

enum LazyPackageDestinationDir<'a> {
/// Non-owning view of a directory handle the caller owns.
#[allow(dead_code)]
Dir(Fd),
NodeModulesPath {
#[allow(dead_code)]
node_modules: &'a NodeModulesFolder,
/// Non-owning view; the owning `Dir` lives on `PackageInstaller`.
root_node_modules_dir: Fd,
},
Owned(Dir),
Closed,
}

impl<'a> LazyPackageDestinationDir<'a> {
#[allow(dead_code)]
pub(crate) fn get_dir(&mut self) -> crate::Result<Fd> {
match self {
LazyPackageDestinationDir::Dir(fd) => Ok(*fd),
LazyPackageDestinationDir::Owned(dir) => Ok(dir.fd()),
LazyPackageDestinationDir::NodeModulesPath {
node_modules,
root_node_modules_dir,
} => {
let dir = node_modules.open_dir(Dir::borrow(root_node_modules_dir))?;
let fd = dir.fd();
*self = LazyPackageDestinationDir::Owned(dir);
Ok(fd)
}
LazyPackageDestinationDir::Closed => {
panic!(
"LazyPackageDestinationDir is closed! This should never happen. Why did this happen?! It's not your fault. Its our fault. We're sorry."
)
}
}
}

fn close(&mut self) {
*self = LazyPackageDestinationDir::Closed;
}
}

/// A dependency alias becomes the install destination inside `node_modules`
/// (the existing entry is renamed aside, deleted, and re-created). Reject
/// anything that could escape `node_modules`: empty names, `.`/`..`
Expand Down Expand Up @@ -1082,7 +1039,6 @@ impl<'a> PackageInstaller<'a> {
self.pkg_name_hashes = bun_ptr::RawSlice::new(packages.items_name_hash());
self.bins = bun_ptr::RawSlice::new(packages.items_bin());
self.resolutions = bun_ptr::RawSlice::new(packages.items_resolution());
self.pkg_dependencies = bun_ptr::RawSlice::new(packages.items_dependencies());

// fixes an assertion failure where a transitive dependency is a git dependency newly added to the lockfile after the list of dependencies has been resized
// this assertion failure would also only happen after the lockfile has been written to disk and the summary is being printed.
Expand Down Expand Up @@ -1818,9 +1774,6 @@ impl<'a> PackageInstaller<'a> {
}
};

#[cfg(not(windows))]
let mut lazy_package_dir = LazyPackageDestinationDir::Dir(destination_dir.fd());

let install_result: package_install::InstallResult = match resolution.tag {
resolution::Tag::Symlink | resolution::Tag::Workspace => {
installer.install_from_link(self.skip_delete, &destination_dir)
Expand Down Expand Up @@ -2127,24 +2080,7 @@ impl<'a> PackageInstaller<'a> {
if !NODE_MODULES_IS_OK.load(Ordering::Relaxed) {
#[cfg(not(windows))]
{
let dir = match lazy_package_dir.get_dir() {
Ok(d) => d,
Err(err) => {
Output::err(
"EACCES",
"Permission denied while installing <b>{}<r>",
(bstr::BStr::new(
self.names[package_id as usize].slice(
self.lockfile().buffers.string_bytes.as_slice(),
),
),),
);
if cfg!(debug_assertions) {
Output::err(err, "Failed to stat node_modules", ());
}
Global::exit(1);
}
};
let dir = destination_dir.fd();
let stat = match bun_sys::fstat(dir) {
Ok(s) => s,
Err(err) => {
Expand Down Expand Up @@ -2248,19 +2184,6 @@ impl<'a> PackageInstaller<'a> {
.unwrap_or_oom();
}

// reshaped for borrowck — `LazyPackageDestinationDir` borrows
// `&self.node_modules`, but this else-branch never reads `destination_dir`
// (it only `close()`s it at the end, which is a no-op for `NodeModulesPath`).
// Detach via raw ptr so subsequent `&mut self` calls type-check.
// BACKREF — `self.node_modules` is not moved/dropped in this branch.
let mut destination_dir = LazyPackageDestinationDir::NodeModulesPath {
node_modules: node_modules_ref.get(),
root_node_modules_dir: self.root_node_modules_folder.fd(),
};

// `defer { destination_dir.close(); }` + `defer increment_tree_install_count`.
// No early returns after this point, so manual calls at end are equivalent.

let dep = &self.lockfile().buffers.dependencies.as_slice()[dependency_id as usize];
let dep_behavior = dep.behavior;
let truncated_dep_name_hash: TruncatedPackageNameHash =
Expand Down Expand Up @@ -2370,13 +2293,6 @@ impl<'a> PackageInstaller<'a> {
}
}

// `destination_dir` is `LazyPackageDestinationDir::NodeModulesPath`
// holding `&self.node_modules`. `increment_tree_install_count` takes
// `&mut self` and (via `link_tree_bins`) reads `self.node_modules.path`,
// which would alias the borrow held by `destination_dir`. Close it first
// — `destination_dir` is never read in this else-branch (`get_dir()` is
// only used in the `needs_install` branch's EACCES handler).
destination_dir.close();
self.increment_tree_install_count(
!IS_PENDING_PACKAGE_INSTALL,
self.current_tree_id,
Expand Down
3 changes: 1 addition & 2 deletions src/install/PackageManager/PackageManagerResolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ impl PackageManager {
Err(
crate::Error::Sys(bun_errno::SystemErrno::ENOENT)
| crate::Error::Sys(bun_errno::SystemErrno::ENOTDIR)
| crate::Error::Sys(bun_errno::SystemErrno::EACCES)
| crate::Error::DeviceBusy,
| crate::Error::Sys(bun_errno::SystemErrno::EACCES),
) => {
return Ok(list);
}
Expand Down
Loading
Loading