mirror of
https://github.com/Martin-P/OpenV2G.git
synced 2024-11-18 12:53:58 +00:00
fix: possible memory corruption bug when parsing X509 serial numbers
git-svn-id: https://svn.code.sf.net/p/openv2g/code/trunk@118 d9f2db14-54d0-4bde-b00c-16405c910529
This commit is contained in:
parent
6a5f291f88
commit
9bb3ff36d1
1 changed files with 384 additions and 246 deletions
|
@ -1,32 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2018 Siemens AG
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
*
|
||||
* @author Daniel.Peintner.EXT@siemens.com
|
||||
* @version 2017-03-02
|
||||
* @contact Richard.Kuntschke@siemens.com
|
||||
*
|
||||
* <p>Code generated by EXIdizer</p>
|
||||
* <p>Schema: V2G_CI_MsgDef.xsd</p>
|
||||
*
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007-2022 Siemens AG
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
*
|
||||
* @author Daniel.Peintner.EXT@siemens.com
|
||||
* @version 2022-03-08
|
||||
* @contact Richard.Kuntschke@siemens.com
|
||||
*
|
||||
* <p>Code generated by EXIdizer</p>
|
||||
* <p>Schema: V2G_CI_MsgDef.xsd</p>
|
||||
*
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
|
||||
|
||||
#include "DecoderChannel.h"
|
||||
|
@ -261,182 +261,320 @@ int decodeUnsignedInteger64(bitstream_t* stream, uint64_t* uint64) {
|
|||
|
||||
return errn;
|
||||
}
|
||||
|
||||
|
||||
void _reverseArray(uint8_t *array, int number) {
|
||||
int x, t;
|
||||
number--;
|
||||
|
||||
for(x = 0; x < number; x ++, number --) {
|
||||
t = array[x];
|
||||
array[x] = array[number];
|
||||
array[number] = t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode an arbitrary precision non negative integer using a sequence of
|
||||
* octets. The most significant bit of the last octet is set to zero to
|
||||
* indicate sequence termination. Only seven bits per octet are used to
|
||||
* store the integer's value.
|
||||
*/
|
||||
int decodeUnsignedIntegerBig(bitstream_t* stream, size_t size, uint8_t* data, size_t* len) {
|
||||
int errn = 0;
|
||||
uint8_t b = 0;
|
||||
unsigned int mShift1 = 0;
|
||||
unsigned int mShift2 = 0;
|
||||
unsigned int mShift3 = 0;
|
||||
unsigned int mShift4 = 0;
|
||||
unsigned int nBytesRead = 0;
|
||||
unsigned int nBitsAvailable = 0;
|
||||
uint64_t uint64_1 = 0;
|
||||
uint64_t uint64_2 = 0;
|
||||
uint64_t uint64_3 = 0;
|
||||
uint64_t uint64_4 = 0;
|
||||
|
||||
*len = 0;
|
||||
|
||||
do {
|
||||
errn = decode(stream, &b);
|
||||
nBytesRead++;
|
||||
nBitsAvailable += 7;
|
||||
|
||||
if(nBytesRead <= 8) {
|
||||
uint64_1 += ((uint64_t) (b & 127)) << mShift1;
|
||||
mShift1 += 7;
|
||||
} else if(nBytesRead <= 16) {
|
||||
uint64_2 += ((uint64_t) (b & 127)) << mShift2;
|
||||
mShift2 += 7;
|
||||
} else if(nBytesRead <= 24) {
|
||||
uint64_3 += ((uint64_t) (b & 127)) << mShift3;
|
||||
mShift3 += 7;
|
||||
} else if(nBytesRead <= 32) {
|
||||
uint64_4 += ((uint64_t) (b & 127)) << mShift4;
|
||||
mShift4 += 7;
|
||||
} else {
|
||||
return -1; // too large
|
||||
}
|
||||
} while (errn == 0 && (b >> 7) == 1);
|
||||
|
||||
// shift actual data into array
|
||||
if(uint64_4 != 0) {
|
||||
// 7 octets for uint64_1
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 1
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 2
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 3
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 4
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 5
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 6
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 7
|
||||
|
||||
// 7 octets for uint64_2
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 1
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 2
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 3
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 4
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 5
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 6
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 7
|
||||
|
||||
// 7 octets for uint64_3
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 1
|
||||
uint64_3 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 2
|
||||
uint64_3 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 3
|
||||
uint64_3 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 4
|
||||
uint64_3 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 5
|
||||
uint64_3 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 6
|
||||
uint64_3 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 7
|
||||
|
||||
// remaining octets of uint64_4
|
||||
while (uint64_4 != 0 && errn == 0) {
|
||||
data[(*len)++] = uint64_4 & 0xFF;
|
||||
uint64_4 >>= 8;
|
||||
}
|
||||
} else if(uint64_3 != 0) {
|
||||
// 7 octets for uint64_1
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 1
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 2
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 3
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 4
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 5
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 6
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 7
|
||||
|
||||
// 7 octets for uint64_2
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 1
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 2
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 3
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 4
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 5
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 6
|
||||
uint64_2 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 7
|
||||
|
||||
// remaining octets of uint64_3
|
||||
while (uint64_3 != 0 && errn == 0) {
|
||||
data[(*len)++] = uint64_3 & 0xFF;
|
||||
uint64_3 >>= 8;
|
||||
}
|
||||
|
||||
} else if(uint64_2 != 0) {
|
||||
// 7 octets for uint64_1
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 1
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 2
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 3
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 4
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 5
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 6
|
||||
uint64_1 >>= 8;
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 7
|
||||
// remaining octets of uint64_2
|
||||
while (uint64_2 != 0 && errn == 0) {
|
||||
data[(*len)++] = uint64_2 & 0xFF;
|
||||
uint64_2 >>= 8;
|
||||
}
|
||||
} else if(uint64_1 != 0) {
|
||||
while (uint64_1 != 0 && errn == 0) {
|
||||
data[(*len)++] = uint64_1 & 0xFF;
|
||||
uint64_1 >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
_reverseArray(data, *len);
|
||||
|
||||
return errn;
|
||||
|
||||
|
||||
void _reverseArray(uint8_t *array, int number) {
|
||||
int x, t;
|
||||
number--;
|
||||
|
||||
for(x = 0; x < number; x ++, number --) {
|
||||
t = array[x];
|
||||
array[x] = array[number];
|
||||
array[number] = t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode an arbitrary precision non negative integer using a sequence of
|
||||
* octets. The most significant bit of the last octet is set to zero to
|
||||
* indicate sequence termination. Only seven bits per octet are used to
|
||||
* store the integer's value.
|
||||
*/
|
||||
int decodeUnsignedIntegerBig(bitstream_t* stream, size_t size, uint8_t* data, size_t* len) {
|
||||
int errn = 0;
|
||||
uint8_t b = 0;
|
||||
unsigned int mShift1 = 0;
|
||||
unsigned int mShift2 = 0;
|
||||
unsigned int mShift3 = 0;
|
||||
unsigned int mShift4 = 0;
|
||||
unsigned int nBytesRead = 0;
|
||||
unsigned int nBitsAvailable = 0;
|
||||
uint64_t uint64_1 = 0;
|
||||
uint64_t uint64_2 = 0;
|
||||
uint64_t uint64_3 = 0;
|
||||
uint64_t uint64_4 = 0;
|
||||
|
||||
*len = 0;
|
||||
|
||||
do {
|
||||
errn = decode(stream, &b);
|
||||
nBytesRead++;
|
||||
nBitsAvailable += 7;
|
||||
|
||||
if(nBytesRead <= 8) {
|
||||
uint64_1 += ((uint64_t) (b & 127)) << mShift1;
|
||||
mShift1 += 7;
|
||||
} else if(nBytesRead <= 16) {
|
||||
uint64_2 += ((uint64_t) (b & 127)) << mShift2;
|
||||
mShift2 += 7;
|
||||
} else if(nBytesRead <= 24) {
|
||||
uint64_3 += ((uint64_t) (b & 127)) << mShift3;
|
||||
mShift3 += 7;
|
||||
} else if(nBytesRead <= 32) {
|
||||
uint64_4 += ((uint64_t) (b & 127)) << mShift4;
|
||||
mShift4 += 7;
|
||||
} else {
|
||||
return -1; /* too large */
|
||||
}
|
||||
} while (errn == 0 && (b >> 7) == 1);
|
||||
|
||||
/* shift actual data into array */
|
||||
if(uint64_4 != 0) {
|
||||
/* 7 octets for uint64_1 */
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 1 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 2 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 3 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 4 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 5 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 6 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 7 */
|
||||
|
||||
/* 7 octets for uint64_2 */
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 1 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 2 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 3 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 4 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 5 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 6 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 7 */
|
||||
|
||||
/* 7 octets for uint64_3 */
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 1 */
|
||||
uint64_3 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 2 */
|
||||
uint64_3 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 3 */
|
||||
uint64_3 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 4 */
|
||||
uint64_3 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 5 */
|
||||
uint64_3 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 6 */
|
||||
uint64_3 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 7 */
|
||||
|
||||
/* remaining octets of uint64_4 */
|
||||
while (uint64_4 != 0 && errn == 0) {
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = uint64_4 & 0xFF;
|
||||
uint64_4 >>= 8;
|
||||
}
|
||||
} else if(uint64_3 != 0) {
|
||||
/* 7 octets for uint64_1 */
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 1 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 2 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 3 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 4 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 5 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 6 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 7 */
|
||||
|
||||
/* 7 octets for uint64_2 */
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 1 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 2 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 3 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 4 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 5 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 6 */
|
||||
uint64_2 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 7 */
|
||||
|
||||
/* remaining octets of uint64_3 */
|
||||
while (uint64_3 != 0 && errn == 0) {
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = uint64_3 & 0xFF;
|
||||
uint64_3 >>= 8;
|
||||
}
|
||||
|
||||
} else if(uint64_2 != 0) {
|
||||
/* 7 octets for uint64_1 */
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 1 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 2 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 3 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 4 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 5 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 6 */
|
||||
uint64_1 >>= 8;
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 7 */
|
||||
/* remaining octets of uint64_2 */
|
||||
while (uint64_2 != 0 && errn == 0) {
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = uint64_2 & 0xFF;
|
||||
uint64_2 >>= 8;
|
||||
}
|
||||
} else if(uint64_1 != 0) {
|
||||
while (uint64_1 != 0 && errn == 0) {
|
||||
if(*len >= size) {
|
||||
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||
}
|
||||
data[(*len)++] = uint64_1 & 0xFF;
|
||||
uint64_1 >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
_reverseArray(data, *len);
|
||||
|
||||
return errn;
|
||||
}
|
||||
|
||||
int decodeInteger(bitstream_t* stream, exi_integer_t* iv) {
|
||||
|
@ -529,28 +667,28 @@ int decodeInteger64(bitstream_t* stream, int64_t* int64) {
|
|||
}
|
||||
|
||||
return errn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode an arbitrary precision integer using a sign bit followed by a
|
||||
* sequence of octets. The most significant bit of the last octet is set to
|
||||
* zero to indicate sequence termination. Only seven bits per octet are used
|
||||
* to store the integer's value.
|
||||
*/
|
||||
int decodeIntegerBig(bitstream_t* stream, int* negative, size_t size, uint8_t* data, size_t* len) {
|
||||
int errn = decodeBoolean(stream, negative);
|
||||
|
||||
if (errn == 0) {
|
||||
if (*negative) {
|
||||
/* For negative values, the Unsigned Integer holds the
|
||||
* magnitude of the value minus 1 */
|
||||
} else {
|
||||
/* positive */
|
||||
}
|
||||
errn = decodeUnsignedIntegerBig(stream, size, data, len);
|
||||
}
|
||||
|
||||
return errn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode an arbitrary precision integer using a sign bit followed by a
|
||||
* sequence of octets. The most significant bit of the last octet is set to
|
||||
* zero to indicate sequence termination. Only seven bits per octet are used
|
||||
* to store the integer's value.
|
||||
*/
|
||||
int decodeIntegerBig(bitstream_t* stream, int* negative, size_t size, uint8_t* data, size_t* len) {
|
||||
int errn = decodeBoolean(stream, negative);
|
||||
|
||||
if (errn == 0) {
|
||||
if (*negative) {
|
||||
/* For negative values, the Unsigned Integer holds the
|
||||
* magnitude of the value minus 1 */
|
||||
} else {
|
||||
/* positive */
|
||||
}
|
||||
errn = decodeUnsignedIntegerBig(stream, size, data, len);
|
||||
}
|
||||
|
||||
return errn;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -637,16 +775,16 @@ int decodeString(bitstream_t* stream, exi_string_t* s) {
|
|||
*/
|
||||
int decodeCharacters(bitstream_t* stream, size_t len, exi_string_character_t* chars, size_t charsSize) {
|
||||
unsigned int i;
|
||||
int errn = 0;
|
||||
|
||||
unsigned int extraChar = 0;
|
||||
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
||||
extraChar = 1; /* null terminator */
|
||||
#endif /* STRING_REPRESENTATION_ASCII */
|
||||
|
||||
if ( (len + extraChar) > charsSize) {
|
||||
errn = EXI_ERROR_OUT_OF_STRING_BUFFER;
|
||||
return errn;
|
||||
int errn = 0;
|
||||
|
||||
unsigned int extraChar = 0;
|
||||
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
||||
extraChar = 1; /* null terminator */
|
||||
#endif /* STRING_REPRESENTATION_ASCII */
|
||||
|
||||
if ( (len + extraChar) > charsSize) {
|
||||
errn = EXI_ERROR_OUT_OF_STRING_BUFFER;
|
||||
return errn;
|
||||
}
|
||||
|
||||
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
||||
|
@ -679,15 +817,15 @@ int decodeRCSCharacters(bitstream_t* stream, size_t len, exi_string_character_t*
|
|||
unsigned int i;
|
||||
int errn = 0;
|
||||
uint32_t uint32;
|
||||
unsigned int extraChar = 0;
|
||||
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
||||
uint8_t b;
|
||||
extraChar = 1; /* null terminator */
|
||||
#endif /* STRING_REPRESENTATION_ASCII */
|
||||
|
||||
if ( (len + extraChar) > charsSize) {
|
||||
errn = EXI_ERROR_OUT_OF_STRING_BUFFER;
|
||||
return errn;
|
||||
unsigned int extraChar = 0;
|
||||
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
||||
uint8_t b;
|
||||
extraChar = 1; /* null terminator */
|
||||
#endif /* STRING_REPRESENTATION_ASCII */
|
||||
|
||||
if ( (len + extraChar) > charsSize) {
|
||||
errn = EXI_ERROR_OUT_OF_STRING_BUFFER;
|
||||
return errn;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue