Skip to content

Commit df9dddd

Browse files
surajrmalCQ Bot
authored andcommitted
[driver_manager] Fix incorrect usage of std::string_view
std::string_view is not guaranteed to be null terminated, but these usages assume it is. Bug: 102933 Change-Id: I5998c5e246f89d4c8155e4665d028a09d42773bb Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/708602 Fuchsia-Auto-Submit: Suraj Malhotra <surajmalhotra@google.com> Reviewed-by: Sarah Chan <spqchan@google.com> Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
1 parent b8f2121 commit df9dddd

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/devices/bin/driver_manager/driver.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,50 +244,52 @@ void find_loadable_drivers(fidl::WireSyncClient<fuchsia_boot::Arguments>* boot_a
244244
}
245245

246246
zx_status_t load_driver_vmo(fidl::WireSyncClient<fuchsia_boot::Arguments>* boot_args,
247-
std::string_view libname, zx::vmo vmo, DriverLoadCallback func) {
247+
std::string_view libname_view, zx::vmo vmo, DriverLoadCallback func) {
248+
std::string libname(libname_view);
248249
zx_handle_t vmo_handle = vmo.get();
249-
AddContext context = {boot_args, libname.data(), std::move(func), std::move(vmo)};
250+
AddContext context = {boot_args, libname.c_str(), std::move(func), std::move(vmo)};
250251

251252
auto di_vmo_read = [](void* vmo, void* data, size_t len, size_t off) {
252253
return zx_vmo_read(*((zx_handle_t*)vmo), data, off, len);
253254
};
254255
zx_status_t status = di_read_driver_info_etc(&vmo_handle, di_vmo_read, &context, found_driver);
255256

256257
if (status == ZX_ERR_NOT_FOUND) {
257-
LOGF(INFO, "Missing info from driver '%s'", libname.data());
258+
LOGF(INFO, "Missing info from driver '%s'", libname.c_str());
258259
} else if (status != ZX_OK) {
259-
LOGF(ERROR, "Failed to read info from driver '%s': %s", libname.data(),
260+
LOGF(ERROR, "Failed to read info from driver '%s': %s", libname.c_str(),
260261
zx_status_get_string(status));
261262
}
262263
return status;
263264
}
264265

265-
zx_status_t load_vmo(std::string_view libname, zx::vmo* out_vmo) {
266+
zx_status_t load_vmo(std::string_view libname_view, zx::vmo* out_vmo) {
267+
std::string libname(libname_view);
266268
int fd = -1;
267-
zx_status_t r = fdio_open_fd(libname.data(),
269+
zx_status_t r = fdio_open_fd(libname.c_str(),
268270
static_cast<uint32_t>(fio::wire::OpenFlags::kRightReadable |
269271
fio::wire::OpenFlags::kRightExecutable),
270272
&fd);
271273
if (r != ZX_OK) {
272-
LOGF(ERROR, "Cannot open driver '%s': %d", libname.data(), r);
274+
LOGF(ERROR, "Cannot open driver '%s': %d", libname.c_str(), r);
273275
return ZX_ERR_IO;
274276
}
275277
zx::vmo vmo;
276278
r = fdio_get_vmo_exec(fd, vmo.reset_and_get_address());
277279
close(fd);
278280
if (r != ZX_OK) {
279-
LOGF(ERROR, "Cannot get driver VMO '%s'", libname.data());
281+
LOGF(ERROR, "Cannot get driver VMO '%s'", libname.c_str());
280282
return r;
281283
}
282-
const char* vmo_name = strrchr(libname.data(), '/');
284+
const char* vmo_name = strrchr(libname.c_str(), '/');
283285
if (vmo_name != nullptr) {
284286
++vmo_name;
285287
} else {
286-
vmo_name = libname.data();
288+
vmo_name = libname.c_str();
287289
}
288290
r = vmo.set_property(ZX_PROP_NAME, vmo_name, strlen(vmo_name));
289291
if (r != ZX_OK) {
290-
LOGF(ERROR, "Cannot set name on driver VMO to '%s'", libname.data());
292+
LOGF(ERROR, "Cannot set name on driver VMO to '%s'", libname.c_str());
291293
return r;
292294
}
293295
*out_vmo = std::move(vmo);

0 commit comments

Comments
 (0)