return res;
}
+ if (*strLen <= 0) {
+ return DMERR_BAD_DATA;
+ }
+
if (*left < *strLen) {
return DMERR_TRUNCATED_DATA;
}
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;
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;
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]);
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;
/*