1.1 --- a/opener_context_resource.cc Sun Feb 28 22:48:57 2021 +0100
1.2 +++ b/opener_context_resource.cc Sun Feb 28 23:28:45 2021 +0100
1.3 @@ -3,6 +3,10 @@
1.4 #include "opener_resource.h"
1.5 #include "resource_server.h"
1.6
1.7 +#include <string.h>
1.8 +
1.9 +
1.10 +
1.11 /* Support for providing access to files. */
1.12
1.13 OpenerContextResource::OpenerContextResource(OpenerResource *opener, Memory *memory)
1.14 @@ -26,7 +30,15 @@
1.15
1.16 char *OpenerContextResource::get_path()
1.17 {
1.18 - return _region->read();
1.19 + char *buffer = _region->read();
1.20 + offset_t size = _region->size();
1.21 +
1.22 + /* Confine the path to the limit of the buffer. */
1.23 +
1.24 + if ((buffer != NULL) && (strnlen(buffer, size) < size))
1.25 + return buffer;
1.26 + else
1.27 + return NULL;
1.28 }
1.29
1.30
1.31 @@ -37,7 +49,12 @@
1.32 {
1.33 /* NOTE: Support flags in the file pager method and obtain the file size. */
1.34
1.35 - FilePager *pager = _opener->open(get_path());
1.36 + char *path = get_path();
1.37 +
1.38 + if (path == NULL)
1.39 + return -L4_EINVAL;
1.40 +
1.41 + FilePager *pager = _opener->open(path);
1.42
1.43 /* Complete the initialisation and start a server in a new thread. */
1.44
2.1 --- a/region.cc Sun Feb 28 22:48:57 2021 +0100
2.2 +++ b/region.cc Sun Feb 28 23:28:45 2021 +0100
2.3 @@ -66,7 +66,10 @@
2.4
2.5 char *Region::read(offset_t offset)
2.6 {
2.7 - return (char *) start + offset;
2.8 + if (offset < size())
2.9 + return (char *) start + offset;
2.10 + else
2.11 + return NULL;
2.12 }
2.13
2.14 void Region::write(const char *data, offset_t offset)