-/* Copyright (C) 2015 Open Information Security Foundation
+/* Copyright (C) 2015-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
static int ENIPExtractUint16(uint16_t *res, const uint8_t *input, uint16_t *offset, uint32_t input_len)
{
- if (input_len < sizeof(uint16_t) || *offset > (input_len - sizeof(uint16_t)))
- {
+ if (input_len < sizeof(uint16_t) || *offset > (input_len - sizeof(uint16_t))) {
SCLogDebug("ENIPExtractUint16: Parsing beyond payload length");
return 0;
}
- ByteExtractUint16(res, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
- (const uint8_t *) (input + *offset));
+ if (ByteExtractUint16(res, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
+ (const uint8_t *)(input + *offset)) == -1) {
+ return 0;
+ }
+
*offset += sizeof(uint16_t);
return 1;
}
return 0;
}
- ByteExtractUint32(res, BYTE_LITTLE_ENDIAN, sizeof(uint32_t),
- (const uint8_t *) (input + *offset));
+ if (ByteExtractUint32(res, BYTE_LITTLE_ENDIAN, sizeof(uint32_t),
+ (const uint8_t *)(input + *offset)) == -1) {
+ return 0;
+ }
+
*offset += sizeof(uint32_t);
return 1;
}
return 0;
}
- ByteExtractUint64(res, BYTE_LITTLE_ENDIAN, sizeof(uint64_t),
- (const uint8_t *) (input + *offset));
+ if (ByteExtractUint64(res, BYTE_LITTLE_ENDIAN, sizeof(uint64_t),
+ (const uint8_t *)(input + *offset)) == -1) {
+ return 0;
+ }
+
*offset += sizeof(uint64_t);
return 1;
}
enip_data->encap_data_item.sequence_count = data_sequence_count;
}
- switch (enip_data->encap_data_item.type)
- {
+ switch (enip_data->encap_data_item.type) {
case CONNECTED_DATA_ITEM:
SCLogDebug(
"DecodeCommonPacketFormat - CONNECTED DATA ITEM - parse CIP");
//use temp_offset just to grab the service offset, don't want to use and push offset
uint16_t temp_offset = offset;
uint16_t num_services;
- ByteExtractUint16(&num_services, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
- (const uint8_t *) (input + temp_offset));
+ if (ByteExtractUint16(&num_services, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
+ (const uint8_t *)(input + temp_offset)) == -1) {
+ return 0;
+ }
+
temp_offset += sizeof(uint16_t);
//SCLogDebug("DecodeCIPRequestMSP number of services %d",num_services);
}
uint16_t svc_offset; //read set of service offsets
- ByteExtractUint16(&svc_offset, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
- (const uint8_t *) (input + temp_offset));
+ if (ByteExtractUint16(&svc_offset, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
+ (const uint8_t *)(input + temp_offset)) == -1) {
+ return 0;
+ }
temp_offset += sizeof(uint16_t);
//SCLogDebug("parseCIPRequestMSP service %d offset %d",svc, svc_offset);
//use temp_offset just to grab the service offset, don't want to use and push offset
uint16_t temp_offset = offset;
uint16_t num_services;
- ByteExtractUint16(&num_services, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
- (const uint8_t *) (input + temp_offset));
+ if (ByteExtractUint16(&num_services, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
+ (const uint8_t *)(input + temp_offset)) == -1) {
+ return 0;
+ }
temp_offset += sizeof(uint16_t);
//SCLogDebug("DecodeCIPResponseMSP number of services %d", num_services);
- for (int svc = 0; svc < num_services; svc++)
- {
+ for (int svc = 0; svc < num_services; svc++) {
if (temp_offset >= (input_len - sizeof(uint16_t)))
{
SCLogDebug("DecodeCIPResponseMSP: Parsing beyond payload length");
}
uint16_t svc_offset; //read set of service offsets
- ByteExtractUint16(&svc_offset, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
- (const uint8_t *) (input + temp_offset));
+ if (ByteExtractUint16(&svc_offset, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
+ (const uint8_t *)(input + temp_offset)) == -1) {
+ return 0;
+ }
temp_offset += sizeof(uint16_t);
//SCLogDebug("parseCIPResponseMSP service %d offset %d", svc, svc_offset);
-/* Copyright (C) 2007-2010 Open Information Security Foundation
+/* Copyright (C) 2007-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractUint64(uint64_t *res, int e, uint16_t len, const uint8_t *bytes);
+int WARN_UNUSED ByteExtractUint64(uint64_t *res, int e, uint16_t len, const uint8_t *bytes);
/**
* Extract bytes from a byte string and convert to a uint32_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractUint32(uint32_t *res, int e, uint16_t len, const uint8_t *bytes);
+int WARN_UNUSED ByteExtractUint32(uint32_t *res, int e, uint16_t len, const uint8_t *bytes);
/**
* Extract bytes from a byte string and convert to a unint16_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractUint16(uint16_t *res, int e, uint16_t len, const uint8_t *bytes);
+int WARN_UNUSED ByteExtractUint16(uint16_t *res, int e, uint16_t len, const uint8_t *bytes);
/**
* Extract unsigned integer value from a string.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractString(uint64_t *res, int base, size_t len, const char *str, bool strict);
+int WARN_UNUSED ByteExtractString(
+ uint64_t *res, int base, size_t len, const char *str, bool strict);
/**
* Extract unsigned integer value from a string as uint64_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringUint64(uint64_t *res, int base, size_t len, const char *str);
+int WARN_UNUSED ByteExtractStringUint64(uint64_t *res, int base, size_t len, const char *str);
/**
* Extract unsigned integer value from a string as uint32_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringUint32(uint32_t *res, int base, size_t len, const char *str);
+int WARN_UNUSED ByteExtractStringUint32(uint32_t *res, int base, size_t len, const char *str);
/**
* Extract unsigned integer value from a string as uint16_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringUint16(uint16_t *res, int base, size_t len, const char *str);
+int WARN_UNUSED ByteExtractStringUint16(uint16_t *res, int base, size_t len, const char *str);
/**
* Extract unsigned integer value from a string as uint8_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringUint8(uint8_t *res, int base, size_t len, const char *str);
+int WARN_UNUSED ByteExtractStringUint8(uint8_t *res, int base, size_t len, const char *str);
/**
* Extract signed integer value from a string.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringSigned(int64_t *res, int base, size_t len, const char *str, bool strict);
+int WARN_UNUSED ByteExtractStringSigned(
+ int64_t *res, int base, size_t len, const char *str, bool strict);
/**
* Extract signed integer value from a string as uint64_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringInt64(int64_t *res, int base, size_t len, const char *str);
+int WARN_UNUSED ByteExtractStringInt64(int64_t *res, int base, size_t len, const char *str);
/**
* Extract signed integer value from a string as uint32_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringInt32(int32_t *res, int base, size_t len, const char *str);
+int WARN_UNUSED ByteExtractStringInt32(int32_t *res, int base, size_t len, const char *str);
/**
* Extract signed integer value from a string as uint16_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringInt16(int16_t *res, int base, size_t len, const char *str);
+int WARN_UNUSED ByteExtractStringInt16(int16_t *res, int base, size_t len, const char *str);
/**
* Extract signed integer value from a string as uint8_t.
* \return n Number of bytes extracted on success
* \return -1 On error
*/
-int ByteExtractStringInt8(int8_t *res, int base, size_t len, const char *str);
+int WARN_UNUSED ByteExtractStringInt8(int8_t *res, int base, size_t len, const char *str);
/**
* Extract unsigned integer value from a string as uint64_t strictly.
#endif /* UNITTESTS */
/** ------ Inline functions ----- */
-static inline int ByteExtract(uint64_t *res, int e, uint16_t len, const uint8_t *bytes)
+static inline int WARN_UNUSED ByteExtract(uint64_t *res, int e, uint16_t len, const uint8_t *bytes)
{
if ((e != BYTE_BIG_ENDIAN) && (e != BYTE_LITTLE_ENDIAN)) {
/** \todo Need standard return values */