diff --git a/src/ripple/app/hook/impl/applyHook.cpp b/src/ripple/app/hook/impl/applyHook.cpp index 8912143bc1..6e0819d46f 100644 --- a/src/ripple/app/hook/impl/applyHook.cpp +++ b/src/ripple/app/hook/impl/applyHook.cpp @@ -3440,16 +3440,18 @@ DEFINE_HOOK_FUNCTION( for (int j = -5; j < 5; ++j) DBG_PRINTF(( j == 0 ? " [%02X] " : " %02X "), *(upto + j)); DBG_PRINTF("\n"); + if (type == 0xF) // we return arrays fully formed return (((int64_t)(upto - start)) << 32) /* start of the object */ + (uint32_t)(length); + // return pointers to all other objects as payloads return (((int64_t)(upto - start + payload_start)) << 32U) /* start of the object */ + (uint32_t)(payload_length); } upto += length; } - + if (upto != end) return PARSE_ERROR; @@ -3474,8 +3476,16 @@ DEFINE_HOOK_FUNCTION( unsigned char* upto = start; unsigned char* end = start + read_len; - if ((*upto & 0xF0) == 0xF0) + // unwrap the array if it is wrapped, + // by removing a byte from the start and end + if ((*upto & 0xF0U) == 0xF0U) + { upto++; + end--; + } + + if (upto >= end) + return PARSE_ERROR; /* DBG_PRINTF("sto_subarray called, looking for index %u\n", index_id); @@ -3489,6 +3499,7 @@ DEFINE_HOOK_FUNCTION( int32_t length = get_stobject_length(upto, end, type, field, payload_start, payload_length, 0); if (length < 0) return PARSE_ERROR; + if (i == index_id) { DBG_PRINTF("sto_subarray returned for index %u\n", index_id); @@ -3496,8 +3507,9 @@ DEFINE_HOOK_FUNCTION( DBG_PRINTF(( j == 0 ? " [%02X] " : " %02X "), *(upto + j + length)); DBG_PRINTF("\n"); - return (((int64_t)(upto - start)) << 32U) /* start of the object */ - + (uint32_t)(length); + return + (((int64_t)(upto - start)) << 32U) /* start of the object */ + + (int64_t)(length); } upto += length; } diff --git a/src/test/app/SetHook_test.cpp b/src/test/app/SetHook_test.cpp index 030ce26888..acb815cefb 100644 --- a/src/test/app/SetHook_test.cpp +++ b/src/test/app/SetHook_test.cpp @@ -4577,19 +4577,15 @@ public: // Test index 0, should be position 1 length 27 ASSERT(sto_subarray(sto, sizeof(sto), 0) == - (1U << 32U) + 27U); + (1ULL << 32ULL) + 27ULL); // Test index 1, should be position 28 length 27 ASSERT(sto_subarray(sto, sizeof(sto), 1) == - (27U << 32U) + 27U); + (28ULL << 32ULL) + 27ULL); // Test index2, doesn't exist ASSERT(sto_subarray(sto, sizeof(sto), 2) == DOESNT_EXIST); - // Test parse error - sto[0] = 0x11U; - ASSERT(sto_subarray(sto, sizeof(sto), 0) == PARSE_ERROR); - accept(0,0,0); } )[test.hook]"]; @@ -4658,30 +4654,26 @@ public: // Test size check ASSERT(sto_subfield(0,1, 1) == TOO_SMALL); - // Test subfield 0x11, should be position 0 length 3 + // Test subfield 0x11, should be position 0 length 3, payload pos 1, len 2 ASSERT(sto_subfield(sto, sizeof(sto), - 0x10001U) == 3); + 0x10001U) == (1ULL << 32ULL) + 2ULL); - // Test subfield 0x22, should be position 3 length 5 + // Test subfield 0x22, should be position 3 length 5, payload pos 4, len 4 ASSERT(sto_subfield(sto, sizeof(sto), - 0x20002U) == (3U << 32U) + 5U); + 0x20002U) == (4ULL << 32ULL) + 4ULL); - // Test subfield 0x34, should be at position 25, length = 9 + // Test subfield 0x34, should be at position 25, length = 9, payload pos 26, len 8 ASSERT(sto_subfield(sto, sizeof(sto), - 0x30004U) == (25U << 32U) + 9U); + 0x30004U) == (26ULL << 32ULL) + 8ULL); - // Test final subfield, position 34, length 33 + // Test final subfield, position 34, length 33, payload pos 35, len 32 ASSERT(sto_subfield(sto, sizeof(sto), - 0x50005U) == (34U << 32U) + 33U); + 0x50005U) == (35ULL << 32ULL) + 32ULL); // Test not found ASSERT(sto_subfield(sto, sizeof(sto), 0x90009U) == DOESNT_EXIST); - // Test parse error - sto[0] = 0x11U; - ASSERT(sto_subfield(sto, sizeof(sto), 0) == PARSE_ERROR); - accept(0,0,0); } )[test.hook]"];