#!/bin/bash
set -euo pipefail

# Verification script for CVE-2025-60021 fix.
# Builds the vulnerable (now patched) bRPC tree to ensure the code compiles
# after applying the sanitisation changes to jemalloc_profiler.cpp.

REPO_ROOT="/home/user/pruva/work/brpc-1.14.1"
BUILD_DIR="$REPO_ROOT/build"

if [ ! -d "$REPO_ROOT" ]; then
  echo "bRPC source tree not found at $REPO_ROOT" >&2
  exit 1
fi

if [ ! -d "$BUILD_DIR" ]; then
  cmake -S "$REPO_ROOT" -B "$BUILD_DIR"
fi

cmake --build "$BUILD_DIR" --target brpc -j"$(nproc)"
