[Tarantool-patches] [PATCH V6 10/10] error: fix iproto error stack overlapped by old error

Leonid Vasiliev lvasiliev at tarantool.org
Mon Apr 20 01:25:12 MSK 2020


Fix possible overlap of IPROTO_ERROR by IPROTO_ERROR_24.
This was possible because messages are transmitted in a map and
an order is not defined. IPROTO_ERROR_24 could be parsed after
the IPROTO_ERROR, and could throw it away.
---
 src/box/xrow.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/box/xrow.c b/src/box/xrow.c
index 1b3f3f9..06473a8 100644
--- a/src/box/xrow.c
+++ b/src/box/xrow.c
@@ -1102,6 +1102,7 @@ xrow_decode_error(struct xrow_header *row)
 	if (mp_typeof(*pos) != MP_MAP)
 		goto error;
 	map_size = mp_decode_map(&pos);
+	bool is_stack_parsed = false;
 	for (uint32_t i = 0; i < map_size; i++) {
 		if (mp_typeof(*pos) != MP_UINT) {
 			mp_next(&pos); /* key */
@@ -1117,12 +1118,15 @@ xrow_decode_error(struct xrow_header *row)
 			 */
 			uint32_t len;
 			const char *str = mp_decode_str(&pos, &len);
-			snprintf(error, sizeof(error), "%.*s", len, str);
-			box_error_set(__FILE__, __LINE__, code, error);
+			if (!is_stack_parsed) {
+				snprintf(error, sizeof(error), "%.*s", len, str);
+				box_error_set(__FILE__, __LINE__, code, error);
+			}
 		} else if (key == IPROTO_ERROR) {
 			struct error *e = error_unpack_unsafe(&pos);
 			if (e == NULL)
 				goto error;
+			is_stack_parsed = true;
 			diag_set_error(diag_get(), e);
 		} else {
 			mp_next(&pos);
-- 
2.7.4



More information about the Tarantool-patches mailing list