usb: add range check to UTF-16 string copy

This commit is contained in:
Sebastian Sumpf 2016-10-10 15:25:33 +02:00 committed by Christian Helmuth
parent 4b148d896a
commit c2e7727f46

View File

@ -73,6 +73,10 @@ struct Usb::String
void copy(unsigned len, void *from, Genode::Allocator *md_alloc) void copy(unsigned len, void *from, Genode::Allocator *md_alloc)
{ {
length = len; length = len;
if (len == 0)
return;
string = (utf16_t *)md_alloc->alloc(length * sizeof(utf16_t)); string = (utf16_t *)md_alloc->alloc(length * sizeof(utf16_t));
Genode::memcpy(string, from, sizeof(utf16_t) * length); Genode::memcpy(string, from, sizeof(utf16_t) * length);
} }