Skip to content

Fix invalid optional access in GetHostBuild#2241

Open
Databean wants to merge 1 commit intogoogle:mainfrom
Databean:cvd_load_optional
Open

Fix invalid optional access in GetHostBuild#2241
Databean wants to merge 1 commit intogoogle:mainfrom
Databean:cvd_load_optional

Conversation

@Databean
Copy link
Member

@Databean Databean commented Mar 9, 2026

The expression host_package_build.value_or(*fallback_host_build); to select between two optionals after knowing one is set is invalid. In the case where fallback_host_build is missing and host_package_build is present, fallback_host_build is still dereferenced to supply the argument to value_or, even if it is ignored by the implementation.

Issue observed by dsk@ using the following configuration to cvd load:

{
  "common": {
    "host_package": "@ab/aosp-android-latest-release/aosp_cf_x86_64_only_phone-userdebug"
  },
  "instances": [
    {
      "disk": {
        "default_build": "14981173"
      },
      "name": "ins-1",
      "vm": {
        "cpus": 4,
        "memory_mb": 4096
      }
    }
  ],
  "metrics": {
    "enable": true
  }
}

Bug: b/491203837

The expression `host_package_build.value_or(*fallback_host_build);` to
select between two optionals after knowing one is set is invalid. In the
case where `fallback_host_build` is missing and `host_package_build` is
present, `fallback_host_build` is still dereferenced to supply the
argument to `value_or`, even if it is ignored by the implementation.

Issue observed by dsk@ using the following configuration to `cvd load`:
```
{
  "common": {
    "host_package": "@ab/aosp-android-latest-release/aosp_cf_x86_64_only_phone-userdebug"
  },
  "instances": [
    {
      "disk": {
        "default_build": "14981173"
      },
      "name": "ins-1",
      "vm": {
        "cpus": 4,
        "memory_mb": 4096
      }
    }
  ],
  "metrics": {
    "enable": true
  }
}
```

Bug: b/491203837
@Databean Databean requested a review from 3405691582 March 9, 2026 22:36
@Databean Databean enabled auto-merge March 9, 2026 22:37
@Databean Databean added the kokoro:run Run e2e tests. label Mar 9, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Mar 9, 2026
return host_package_build.value();
} else if (fallback_host_build.has_value()) {
return fallback_host_build.value();
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could elide this else if you wanted to, since it's not strictly necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants