]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Check for bad length fields for input byte buffers in dataMap code.
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:22:52 +0000 (11:22 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:22:52 +0000 (11:22 -0700)
open-vm-tools/lib/dataMap/dataMap.c
open-vm-tools/lib/include/dataMap.h

index dbc7139eea173c8aa0f242389626661bf345a936..6dbc6ac804ef0441d0d3b2ab3840ef4d60ace6da 100644 (file)
@@ -522,6 +522,10 @@ DecodeString(char **buf,         // IN/OUT
       return res;
    }
 
+   if (*strLen <= 0) {
+      return DMERR_BAD_DATA;
+   }
+
    if (*left < *strLen) {
       return DMERR_TRUNCATED_DATA;
    }
@@ -600,12 +604,19 @@ DecodeInt64List(char **buf,        // IN/OUT
    int32 listLen;
    int64 *numList = NULL;
    ErrorCode res;
+   int32 i;
 
    res = DecodeInt32(buf, left, &listLen);
+   if (res != DMERR_SUCCESS) {
+      return res;
+   }
 
-   if (res == DMERR_SUCCESS) {
-      int32 i;
+   if (listLen < 0 || listLen > *left / sizeof(int64)) {
+      /* listLen can be zero to support an empty list */
+      return DMERR_BAD_DATA;
+   }
 
+   if (listLen) {
       numList = (int64 *)malloc(sizeof(int64) * listLen);
       if (numList == NULL) {
          return DMERR_INSUFFICIENT_MEM;
@@ -617,15 +628,15 @@ DecodeInt64List(char **buf,        // IN/OUT
             break;
          }
       }
+   }
 
-      if (res == DMERR_SUCCESS) {
-         res = AddEntry_Int64List(that, fieldId, numList, listLen);
-      }
+   if (res == DMERR_SUCCESS) {
+      res = AddEntry_Int64List(that, fieldId, numList, listLen);
+   }
 
-      if (res != DMERR_SUCCESS) {
-         /* clean up memory */
-         free(numList);
-      }
+   if (res != DMERR_SUCCESS) {
+      /* clean up memory */
+      free(numList);
    }
 
    return res;
@@ -1434,13 +1445,24 @@ DecodeStringList(char **buf,           // IN
       return res;
    }
 
-   strList = (char **)calloc(listSize + 1, sizeof(char *));
-   strLens = (int32 *)malloc(sizeof(int32) * listSize);
+   if (listSize < 0 || listSize > *left / sizeof(int32)) {
+      /* listSize can be zero to support an empty list */
+      return DMERR_BAD_DATA;
+   }
 
-   if (strList == NULL || strLens == NULL) {
-      FreeStringList(strList, strLens);
+   strList = (char **)calloc(listSize + 1, sizeof(char *));
+   if (strList == NULL) {
       return DMERR_INSUFFICIENT_MEM;
    }
+   if (listSize) {
+      strLens = (int32 *)malloc(sizeof(int32) * listSize);
+      if (strLens == NULL) {
+         FreeStringList(strList, strLens);
+         return DMERR_INSUFFICIENT_MEM;
+      }
+   } else {
+      strLens = NULL;
+   }
 
    for (i = 0; i < listSize; i++) {
       res = DecodeString(buf, left, &strList[i], &strLens[i]);
index a2a1dfe19075f1006ef855026f88e8bfdbd903c8..1add3e023c31e2fb4ed9f96a86f95c2565ef1218 100644 (file)
@@ -55,7 +55,8 @@ typedef enum {
    DMERR_UNKNOWN_TYPE,             /* type unknow in decoding */
    DMERR_TRUNCATED_DATA,           /* more data expected during decoding */
    DMERR_BUFFER_TOO_SMALL,         /* a user buffer is too small */
-   DMERR_INTEGER_OVERFLOW         /* an integer overflow happened */
+   DMERR_INTEGER_OVERFLOW,         /* an integer overflow happened */
+   DMERR_BAD_DATA                  /* bad data during decoding */
 } ErrorCode;
 
 /*