Skip to content

Commit

Permalink
guard VERSION against CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Jan 20, 2025
1 parent 6b3218e commit fc74e02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion profiling/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bindgen::callbacks::IntKind;
use std::collections::HashSet;
use std::env;
use std::{env, fs};
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
Expand All @@ -21,6 +21,14 @@ fn main() {
}
}

// Read the version from the VERSION file
let version = fs::read_to_string("../VERSION")
.expect("Failed to read VERSION file")
.trim()
.to_string();
println!("cargo:rustc-env=PROFILER_VERSION={}", version);
println!("cargo:rerun-if-changed=../VERSION");

let php_config_includes = std::str::from_utf8(php_config_includes_output.stdout.as_slice())
.expect("`php-config`'s stdout to be valid utf8");

Expand Down
4 changes: 2 additions & 2 deletions profiling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static PROFILER_NAME_CSTR: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(

/// Version of the profiling module and zend_extension. Must not contain any
/// interior null bytes and must be null terminated.
static PROFILER_VERSION: &[u8] = concat!(include_str!("../../VERSION"), "\0").as_bytes();
static PROFILER_VERSION: &[u8] = concat!(env!("PROFILER_VERSION"), "\0").as_bytes();

/// Version ID of PHP at run-time, not the version it was built against at
/// compile-time. Its value is overwritten during minit.
Expand All @@ -82,7 +82,7 @@ lazy_static! {
static ref LAZY_STATICS_TAGS: Vec<Tag> = {
vec![
tag!("language", "php"),
tag!("profiler_version", include_str!("../../VERSION")),
tag!("profiler_version", env!("PROFILER_VERSION")),
// Safety: calling getpid() is safe.
Tag::new("process_id", unsafe { libc::getpid() }.to_string())
.expect("process_id tag to be valid"),
Expand Down

0 comments on commit fc74e02

Please sign in to comment.