From 0c38f08fe266a69226d51ba123aad04b9466613d Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Thu, 3 Mar 2016 14:54:09 +0000 Subject: [PATCH 1/2] vmpu: Add a halt error to catch unterminated box namespaces Box namespaces should always be null-terminated, but just in case they aren't, we will halt instead of returning an unterminated string. --- core/system/src/mpu/vmpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/system/src/mpu/vmpu.c b/core/system/src/mpu/vmpu.c index 25142b2b..11f66ee0 100644 --- a/core/system/src/mpu/vmpu.c +++ b/core/system/src/mpu/vmpu.c @@ -444,10 +444,17 @@ static int copy_box_namespace(const char *src, char *dst) if (src[bytes_copied] == '\0') { /* We've reached the end of the box namespace. */ - break; + goto done; } } + /* We did not find a terminating null in the src. The src has been verified + * in vmpu_box_namespace_from_id as being in the box config table. It is a + * programmer error if the namespace in the box config table is not + * null-terminated, so we halt. */ + HALT_ERROR(SANITY_CHECK_FAILED, "vmpu: Box namespace missing terminating-null\r\n"); + +done: return bytes_copied; } From 57de15f322c94ebadf65e2a47337a0621fc946fd Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Thu, 3 Mar 2016 15:06:00 +0000 Subject: [PATCH 2/2] vmpu: Include the terminating-null in the bytes copied count Previously, vmpu_box_namespace_from_id would not include the terminating-null in the bytes copied count it would return. We now include the terminating-null in the bytes copied count. --- core/system/src/mpu/vmpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/core/system/src/mpu/vmpu.c b/core/system/src/mpu/vmpu.c index 11f66ee0..8e3e8634 100644 --- a/core/system/src/mpu/vmpu.c +++ b/core/system/src/mpu/vmpu.c @@ -444,6 +444,7 @@ static int copy_box_namespace(const char *src, char *dst) if (src[bytes_copied] == '\0') { /* We've reached the end of the box namespace. */ + ++bytes_copied; /* Include the terminating-null in bytes_copied. */ goto done; } }