From 99942aa50d5be07372d3ad7f370bb9a396c0e311 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Wed, 12 Aug 2026 17:20:58 -0600 Subject: [PATCH] dnp3-gen: update generated code to match clang-format --- scripts/dnp3-gen/dnp3-gen.py | 17 +++++++---------- src/app-layer-dnp3-objects.c | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/scripts/dnp3-gen/dnp3-gen.py b/scripts/dnp3-gen/dnp3-gen.py index 1ec17fd97b..251e24d49c 100755 --- a/scripts/dnp3-gen/dnp3-gen.py +++ b/scripts/dnp3-gen/dnp3-gen.py @@ -337,9 +337,8 @@ def gen_object_decoders(context): {% for object in objects %} {% if object.packed %} -static int DNP3DecodeObjectG{{object.group}}V{{object.variation}}(const uint8_t **buf, uint16_t *len, - uint8_t prefix_code, uint32_t start, uint32_t count, - DNP3PointList *points) +static int DNP3DecodeObjectG{{object.group}}V{{object.variation}}(const uint8_t **buf, uint16_t *len, uint8_t prefix_code, + uint32_t start, uint32_t count, DNP3PointList *points) { DNP3ObjectG{{object.group}}V{{object.variation}} *object = NULL; uint32_t bytes = (count / 8) + 1; @@ -393,9 +392,8 @@ error: } {% else %} -static int DNP3DecodeObjectG{{object.group}}V{{object.variation}}(const uint8_t **buf, uint16_t *len, - uint8_t prefix_code, uint32_t start, uint32_t count, - DNP3PointList *points) +static int DNP3DecodeObjectG{{object.group}}V{{object.variation}}(const uint8_t **buf, uint16_t *len, uint8_t prefix_code, + uint32_t start, uint32_t count, DNP3PointList *points) { DNP3ObjectG{{object.group}}V{{object.variation}} *object = NULL; uint32_t prefix = 0; @@ -589,7 +587,7 @@ void DNP3FreeObjectPoint(int group, int variation, void *point) {% for object in objects %} {% if f_has_freeable_types(object.fields) %} case DNP3_OBJECT_CODE({{object.group}}, {{object.variation}}): { - DNP3ObjectG{{object.group}}V{{object.variation}} *object = (DNP3ObjectG{{object.group}}V{{object.variation}} *) point; + DNP3ObjectG{{object.group}}V{{object.variation}} *object = (DNP3ObjectG{{object.group}}V{{object.variation}} *)point; {% for field in object.fields %} {% if field.type == "bytearray" %} if (object->{{field.name}} != NULL) { @@ -613,9 +611,8 @@ void DNP3FreeObjectPoint(int group, int variation, void *point) * \\\\retval 0 on success. On failure a positive integer corresponding * to a DNP3 application layer event will be returned. */ -int DNP3DecodeObject(int group, int variation, const uint8_t **buf, - uint16_t *len, uint8_t prefix_code, uint32_t start, - uint32_t count, DNP3PointList *points) +int DNP3DecodeObject(int group, int variation, const uint8_t **buf, uint16_t *len, + uint8_t prefix_code, uint32_t start, uint32_t count, DNP3PointList *points) { int rc = 0; diff --git a/src/app-layer-dnp3-objects.c b/src/app-layer-dnp3-objects.c index 526cbe6ef3..7f38d418a1 100644 --- a/src/app-layer-dnp3-objects.c +++ b/src/app-layer-dnp3-objects.c @@ -7030,7 +7030,7 @@ static int DNP3DecodeObjectG70V4(const uint8_t **buf, uint16_t *len, uint8_t pre if (prefix - (offset - *len) >= 256 || prefix < (offset - *len)) { goto error; } - object->optional_text_len = (uint8_t)(prefix - (offset - *len)); + object->optional_text_len = (uint16_t)(prefix - (offset - *len)); if (object->optional_text_len > 0) { if (*len < object->optional_text_len) { /* Not enough data. */ @@ -7096,7 +7096,7 @@ static int DNP3DecodeObjectG70V5(const uint8_t **buf, uint16_t *len, uint8_t pre if (prefix - (offset - *len) >= 256 || prefix < (offset - *len)) { goto error; } - object->file_data_len = (uint8_t)(prefix - (offset - *len)); + object->file_data_len = (uint16_t)(prefix - (offset - *len)); if (object->file_data_len > 0) { if (*len < object->file_data_len) { /* Not enough data. */ @@ -7165,7 +7165,7 @@ static int DNP3DecodeObjectG70V6(const uint8_t **buf, uint16_t *len, uint8_t pre if (prefix - (offset - *len) >= 256 || prefix < (offset - *len)) { goto error; } - object->optional_text_len = (uint8_t)(prefix - (offset - *len)); + object->optional_text_len = (uint16_t)(prefix - (offset - *len)); if (object->optional_text_len > 0) { if (*len < object->optional_text_len) { /* Not enough data. */ @@ -8846,28 +8846,28 @@ void DNP3FreeObjectPoint(int group, int variation, void *point) { switch(DNP3_OBJECT_CODE(group, variation)) { case DNP3_OBJECT_CODE(83, 1): { - DNP3ObjectG83V1 *object = (DNP3ObjectG83V1 *) point; + DNP3ObjectG83V1 *object = (DNP3ObjectG83V1 *)point; if (object->data_objects != NULL) { SCFree(object->data_objects); } break; } case DNP3_OBJECT_CODE(120, 1): { - DNP3ObjectG120V1 *object = (DNP3ObjectG120V1 *) point; + DNP3ObjectG120V1 *object = (DNP3ObjectG120V1 *)point; if (object->challenge_data != NULL) { SCFree(object->challenge_data); } break; } case DNP3_OBJECT_CODE(120, 2): { - DNP3ObjectG120V2 *object = (DNP3ObjectG120V2 *) point; + DNP3ObjectG120V2 *object = (DNP3ObjectG120V2 *)point; if (object->mac_value != NULL) { SCFree(object->mac_value); } break; } case DNP3_OBJECT_CODE(120, 5): { - DNP3ObjectG120V5 *object = (DNP3ObjectG120V5 *) point; + DNP3ObjectG120V5 *object = (DNP3ObjectG120V5 *)point; if (object->challenge_data != NULL) { SCFree(object->challenge_data); } @@ -8877,28 +8877,28 @@ void DNP3FreeObjectPoint(int group, int variation, void *point) break; } case DNP3_OBJECT_CODE(120, 6): { - DNP3ObjectG120V6 *object = (DNP3ObjectG120V6 *) point; + DNP3ObjectG120V6 *object = (DNP3ObjectG120V6 *)point; if (object->wrapped_key_data != NULL) { SCFree(object->wrapped_key_data); } break; } case DNP3_OBJECT_CODE(120, 8): { - DNP3ObjectG120V8 *object = (DNP3ObjectG120V8 *) point; + DNP3ObjectG120V8 *object = (DNP3ObjectG120V8 *)point; if (object->certificate != NULL) { SCFree(object->certificate); } break; } case DNP3_OBJECT_CODE(120, 9): { - DNP3ObjectG120V9 *object = (DNP3ObjectG120V9 *) point; + DNP3ObjectG120V9 *object = (DNP3ObjectG120V9 *)point; if (object->mac_value != NULL) { SCFree(object->mac_value); } break; } case DNP3_OBJECT_CODE(120, 10): { - DNP3ObjectG120V10 *object = (DNP3ObjectG120V10 *) point; + DNP3ObjectG120V10 *object = (DNP3ObjectG120V10 *)point; if (object->user_public_key != NULL) { SCFree(object->user_public_key); } @@ -8908,35 +8908,35 @@ void DNP3FreeObjectPoint(int group, int variation, void *point) break; } case DNP3_OBJECT_CODE(120, 11): { - DNP3ObjectG120V11 *object = (DNP3ObjectG120V11 *) point; + DNP3ObjectG120V11 *object = (DNP3ObjectG120V11 *)point; if (object->master_challenge_data != NULL) { SCFree(object->master_challenge_data); } break; } case DNP3_OBJECT_CODE(120, 12): { - DNP3ObjectG120V12 *object = (DNP3ObjectG120V12 *) point; + DNP3ObjectG120V12 *object = (DNP3ObjectG120V12 *)point; if (object->challenge_data != NULL) { SCFree(object->challenge_data); } break; } case DNP3_OBJECT_CODE(120, 13): { - DNP3ObjectG120V13 *object = (DNP3ObjectG120V13 *) point; + DNP3ObjectG120V13 *object = (DNP3ObjectG120V13 *)point; if (object->encrypted_update_key_data != NULL) { SCFree(object->encrypted_update_key_data); } break; } case DNP3_OBJECT_CODE(120, 14): { - DNP3ObjectG120V14 *object = (DNP3ObjectG120V14 *) point; + DNP3ObjectG120V14 *object = (DNP3ObjectG120V14 *)point; if (object->digital_signature != NULL) { SCFree(object->digital_signature); } break; } case DNP3_OBJECT_CODE(120, 15): { - DNP3ObjectG120V15 *object = (DNP3ObjectG120V15 *) point; + DNP3ObjectG120V15 *object = (DNP3ObjectG120V15 *)point; if (object->mac != NULL) { SCFree(object->mac); }