Skip to content

Commit cb7ef3a

Browse files
authored
Fwd port fix for build ids containing a zero byte (#5502)
This change is based on #5480, which makes this fix on the 25.lts.1+ branch. This current change goes a step further by changing the type of build_id in the EvergreenInfo struct; a uint8_t array should better represent the data and provide some type safety. b/408471930
1 parent 75b9360 commit cb7ef3a

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎starboard/elf_loader/evergreen_info.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ typedef struct EvergreenInfo {
5757
size_t phdr_table_num;
5858

5959
// Contents of the build id.
60-
char build_id[EVERGREEN_BUILD_ID_MAX_SIZE];
60+
// TODO: b/413105301 - Consider changing to std::array or std::vector.
61+
uint8_t build_id[EVERGREEN_BUILD_ID_MAX_SIZE];
6162

6263
// Length of the build id.
6364
size_t build_id_length;

‎starboard/elf_loader/program_table.cc‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ bool ProgramTable::LoadProgramHeader(const Ehdr* elf_header, File* elf_file) {
113113
}
114114
}
115115

116+
// TODO: b/413107644 - Add more compile-time checks to elf_loader casts and
117+
// pointer conversions.
116118
phdr_table_ = reinterpret_cast<Phdr*>(reinterpret_cast<char*>(phdr_mmap_) +
117119
page_offset);
118120
SB_DLOG(INFO) << "phdr_table_=" << phdr_table_;
@@ -388,10 +390,13 @@ void ProgramTable::PublishEvergreenInfo(const char* file_path) {
388390
evergreen_info.phdr_table = (uint64_t)phdr_table_;
389391
evergreen_info.phdr_table_num = phdr_num_;
390392

391-
std::vector<char> tmp(build_id_.begin(), build_id_.end());
392-
tmp.push_back('\0');
393-
starboard::strlcpy(evergreen_info.build_id, tmp.data(),
394-
EVERGREEN_BUILD_ID_MAX_SIZE);
393+
if (build_id_.size() > EVERGREEN_BUILD_ID_MAX_SIZE) {
394+
SB_LOG(ERROR) << "Build id size cannot be greater than "
395+
<< EVERGREEN_BUILD_ID_MAX_SIZE << " bytes but is "
396+
<< build_id_.size();
397+
return;
398+
}
399+
memcpy(evergreen_info.build_id, build_id_.data(), build_id_.size());
395400
evergreen_info.build_id_length = build_id_.size();
396401

397402
SetEvergreenInfo(&evergreen_info);

0 commit comments

Comments
 (0)