Fix potential missing '\0' when wrapping to legacy
The HAL API for port name is a C++ string of arbitrary
length.
Nevertheless the legacy API name had a maximum length.
Thus when wrapping from the new to legacy, the string
was truncated but no '\0' was added.
Bug: 38184704
Test: compile
Change-Id: I482363809718281e022041c2d5042e5800c5a617
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/audio/common/all-versions/default/include/common/all-versions/default/HidlUtils.impl.h b/audio/common/all-versions/default/include/common/all-versions/default/HidlUtils.impl.h
index d6f8d3e..8ab7350 100644
--- a/audio/common/all-versions/default/include/common/all-versions/default/HidlUtils.impl.h
+++ b/audio/common/all-versions/default/include/common/all-versions/default/HidlUtils.impl.h
@@ -296,8 +296,8 @@
halPort->id = port.id;
halPort->role = static_cast<audio_port_role_t>(port.role);
halPort->type = static_cast<audio_port_type_t>(port.type);
- memcpy(halPort->name, port.name.c_str(),
- std::min(port.name.size(), static_cast<size_t>(AUDIO_PORT_MAX_NAME_LEN)));
+ strncpy(halPort->name, port.name.c_str(), AUDIO_PORT_MAX_NAME_LEN);
+ halPort->name[AUDIO_PORT_MAX_NAME_LEN - 1] = '\0';
halPort->num_sample_rates =
std::min(port.sampleRates.size(), static_cast<size_t>(AUDIO_PORT_MAX_SAMPLING_RATES));
for (size_t i = 0; i < halPort->num_sample_rates; ++i) {