loader: Fix validation error
authorCourtney Goeltzenleuchter <courtneygo@google.com>
Wed, 21 Dec 2016 23:24:34 +0000 (16:24 -0700)
committerCourtney Goeltzenleuchter <courtneygo@google.com>
Wed, 21 Dec 2016 23:35:36 +0000 (16:35 -0700)
The string length validation will not detect strings
that exceed the max length.
For example, when i = max_length-1 and utf8[i] is a valid
character (>= 0x20 and < 0x7f) no error is thrown and
the next iteration will end the loop.
This change extends the loop and the if check to
catch this issue.

layers/vk_layer_utils.cpp
loader/loader.c

index 4ad1989..8d912d7 100644 (file)
@@ -695,9 +695,12 @@ VK_LAYER_EXPORT VkStringErrorFlags vk_string_validate(const int max_length, cons
     int num_char_bytes = 0;
     int i, j;
 
-    for (i = 0; i < max_length; i++) {
+    for (i = 0; i <= max_length; i++) {
         if (utf8[i] == 0) {
             break;
+        } else if (i == max_length) {
+          result = VK_STRING_ERROR_LENGTH;
+          break;
         } else if ((utf8[i] >= 0xa) && (utf8[i] < 0x7f)) {
             num_char_bytes = 0;
         } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) {
index 2ed52c4..4061cd5 100644 (file)
@@ -4752,9 +4752,12 @@ VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) {
     int num_char_bytes = 0;
     int i, j;
 
-    for (i = 0; i < max_length; i++) {
+    for (i = 0; i <= max_length; i++) {
         if (utf8[i] == 0) {
             break;
+        } else if (i == max_length) {
+            result |= VK_STRING_ERROR_LENGTH;
+            break;
         } else if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) {
             num_char_bytes = 0;
         } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) {