Skip to content

Commit

Permalink
Avoid potential null derefs in create_dependency_graph_snapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyONeal committed Oct 16, 2024
1 parent 21f1d2e commit 0da1366
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,27 @@ namespace vcpkg
Optional<Json::Object> create_dependency_graph_snapshot(const VcpkgCmdArguments& args,
const ActionPlan& action_plan)
{
if (args.github_ref.has_value() && args.github_sha.has_value() && args.github_job.has_value() &&
args.github_workflow.has_value() && args.github_run_id.has_value())
const auto github_ref = args.github_ref.get();
const auto github_sha = args.github_sha.get();
const auto github_job = args.github_job.get();
const auto github_workflow = args.github_workflow.get();
const auto github_run_id = args.github_run_id.get();
if (github_ref && github_sha && github_job && github_workflow && github_run_id)
{
Json::Object detector;
detector.insert(JsonIdName, Json::Value::string("vcpkg"));
detector.insert(JsonIdUrl, Json::Value::string("https://github.com/microsoft/vcpkg"));
detector.insert(JsonIdVersion, Json::Value::string("1.0.0"));

Json::Object job;
job.insert(JsonIdId, Json::Value::string(*args.github_run_id.get()));
job.insert(JsonIdCorrelator,
Json::Value::string(*args.github_workflow.get() + "-" + *args.github_job.get()));
job.insert(JsonIdId, Json::Value::string(*github_run_id));
job.insert(JsonIdCorrelator, Json::Value::string(fmt::format("{}-{}", *github_workflow, *github_run_id)));

Json::Object snapshot;
snapshot.insert(JsonIdJob, job);
snapshot.insert(JsonIdVersion, Json::Value::integer(0));
snapshot.insert(JsonIdSha, Json::Value::string(*args.github_sha.get()));
snapshot.insert(JsonIdRef, Json::Value::string(*args.github_ref.get()));
snapshot.insert(JsonIdSha, Json::Value::string(*github_sha));
snapshot.insert(JsonIdRef, Json::Value::string(*github_ref));
snapshot.insert(JsonIdScanned, Json::Value::string(CTime::now_string()));
snapshot.insert(JsonIdDetector, detector);

Expand Down

0 comments on commit 0da1366

Please sign in to comment.