dprintf: use user_memcpy/user_strlcpy to read the user buffer.
* also check the user buffer address.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
#include <kernel.h>
|
||||||
|
|
||||||
#include <Drivers.h>
|
#include <Drivers.h>
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
@@ -70,11 +71,19 @@ dprintf_read(void *cookie, off_t pos, void *buffer, size_t *length)
|
|||||||
static status_t
|
static status_t
|
||||||
dprintf_write(void *cookie, off_t pos, const void *buffer, size_t *_length)
|
dprintf_write(void *cookie, off_t pos, const void *buffer, size_t *_length)
|
||||||
{
|
{
|
||||||
|
if (!IS_USER_ADDRESS(buffer))
|
||||||
|
return B_BAD_ADDRESS;
|
||||||
const char *str = (const char*)buffer;
|
const char *str = (const char*)buffer;
|
||||||
|
|
||||||
int bytesLeft = *_length;
|
int bytesLeft = *_length;
|
||||||
while (bytesLeft > 0) {
|
while (bytesLeft > 0) {
|
||||||
int chunkSize = strnlen(str, bytesLeft);
|
ssize_t size = user_strlcpy(NULL, str, 0);
|
||||||
|
// there's no user_strnlen()
|
||||||
|
if (size < 0)
|
||||||
|
return 0;
|
||||||
|
int chunkSize = min_c(bytesLeft, (int)size);
|
||||||
|
// int chunkSize = strnlen(str, bytesLeft);
|
||||||
|
|
||||||
if (chunkSize == 0) {
|
if (chunkSize == 0) {
|
||||||
// null bytes -- skip
|
// null bytes -- skip
|
||||||
str++;
|
str++;
|
||||||
@@ -91,7 +100,7 @@ dprintf_write(void *cookie, off_t pos, const void *buffer, size_t *_length)
|
|||||||
char localBuffer[512];
|
char localBuffer[512];
|
||||||
if (bytesLeft > (int)sizeof(localBuffer) - 1)
|
if (bytesLeft > (int)sizeof(localBuffer) - 1)
|
||||||
chunkSize = (int)sizeof(localBuffer) - 1;
|
chunkSize = (int)sizeof(localBuffer) - 1;
|
||||||
memcpy(localBuffer, str, chunkSize);
|
user_memcpy(localBuffer, str, chunkSize);
|
||||||
localBuffer[chunkSize] = '\0';
|
localBuffer[chunkSize] = '\0';
|
||||||
|
|
||||||
debug_puts(localBuffer, chunkSize);
|
debug_puts(localBuffer, chunkSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user