network stack: Copy right amount of data from request buffer.

The full size of the entry, including the size of the following
addresses, was used when copying the request instead of just the request
buffer size. Also clear the request buffer to 0 as not all of it is
otherwise initialized.
This commit is contained in:
Michael Lotz
2015-04-12 18:50:01 +02:00
parent 3b7b927dd0
commit d66114bece
+5 -2
View File
@@ -323,6 +323,7 @@ list_routes(net_domain_private* domain, void* buffer, size_t size)
RecursiveLocker _(domain->lock); RecursiveLocker _(domain->lock);
RouteList::Iterator iterator = domain->routes.GetIterator(); RouteList::Iterator iterator = domain->routes.GetIterator();
const size_t baseSize = IF_NAMESIZE + sizeof(route_entry);
size_t spaceLeft = size; size_t spaceLeft = size;
sockaddr zeros; sockaddr zeros;
@@ -333,7 +334,7 @@ list_routes(net_domain_private* domain, void* buffer, size_t size)
while (iterator.HasNext()) { while (iterator.HasNext()) {
net_route* route = iterator.Next(); net_route* route = iterator.Next();
size = IF_NAMESIZE + sizeof(route_entry); size = baseSize;
sockaddr* destination = NULL; sockaddr* destination = NULL;
sockaddr* mask = NULL; sockaddr* mask = NULL;
@@ -360,6 +361,8 @@ list_routes(net_domain_private* domain, void* buffer, size_t size)
return ENOBUFS; return ENOBUFS;
ifreq request; ifreq request;
memset(&request, 0, sizeof(request));
strlcpy(request.ifr_name, route->interface_address->interface->name, strlcpy(request.ifr_name, route->interface_address->interface->name,
IF_NAMESIZE); IF_NAMESIZE);
request.ifr_route.destination = destination; request.ifr_route.destination = destination;
@@ -369,7 +372,7 @@ list_routes(net_domain_private* domain, void* buffer, size_t size)
request.ifr_route.flags = route->flags; request.ifr_route.flags = route->flags;
// copy data into userland buffer // copy data into userland buffer
if (user_memcpy(buffer, &request, size) < B_OK if (user_memcpy(buffer, &request, baseSize) < B_OK
|| (route->destination != NULL || (route->destination != NULL
&& user_memcpy(request.ifr_route.destination, && user_memcpy(request.ifr_route.destination,
route->destination, route->destination->sa_len) < B_OK) route->destination, route->destination->sa_len) < B_OK)