From 16b87e4d509428f58a11254c54fc461a851091cc Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 19 Jul 2021 15:10:50 +0200 Subject: [PATCH] fix(core/stellar): fail cleanly when asset code has wrong length --- core/src/apps/stellar/operations/serialize.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/apps/stellar/operations/serialize.py b/core/src/apps/stellar/operations/serialize.py index f8ccdff2fe..e8adef6ac8 100644 --- a/core/src/apps/stellar/operations/serialize.py +++ b/core/src/apps/stellar/operations/serialize.py @@ -12,7 +12,7 @@ from trezor.messages import ( StellarPaymentOp, StellarSetOptionsOp, ) -from trezor.wire import ProcessError +from trezor.wire import DataError, ProcessError from .. import consts, writers @@ -148,9 +148,13 @@ def _write_asset_code(w, asset_type: int, asset_code: str): if asset_type == consts.ASSET_TYPE_NATIVE: return # nothing is needed elif asset_type == consts.ASSET_TYPE_ALPHANUM4: + if len(code) > 4: + raise DataError("Stellar: asset code too long for ALPHANUM4") # pad with zeros to 4 chars writers.write_bytes_fixed(w, code + bytearray([0] * (4 - len(code))), 4) elif asset_type == consts.ASSET_TYPE_ALPHANUM12: + if len(code) > 12: + raise DataError("Stellar: asset code too long for ALPHANUM12") # pad with zeros to 12 chars writers.write_bytes_fixed(w, code + bytearray([0] * (12 - len(code))), 12) else: