mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 20:38:10 +00:00
fix(core/stellar): fail cleanly when asset code has wrong length
This commit is contained in:
parent
ad6976e01f
commit
16b87e4d50
@ -12,7 +12,7 @@ from trezor.messages import (
|
|||||||
StellarPaymentOp,
|
StellarPaymentOp,
|
||||||
StellarSetOptionsOp,
|
StellarSetOptionsOp,
|
||||||
)
|
)
|
||||||
from trezor.wire import ProcessError
|
from trezor.wire import DataError, ProcessError
|
||||||
|
|
||||||
from .. import consts, writers
|
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:
|
if asset_type == consts.ASSET_TYPE_NATIVE:
|
||||||
return # nothing is needed
|
return # nothing is needed
|
||||||
elif asset_type == consts.ASSET_TYPE_ALPHANUM4:
|
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
|
# pad with zeros to 4 chars
|
||||||
writers.write_bytes_fixed(w, code + bytearray([0] * (4 - len(code))), 4)
|
writers.write_bytes_fixed(w, code + bytearray([0] * (4 - len(code))), 4)
|
||||||
elif asset_type == consts.ASSET_TYPE_ALPHANUM12:
|
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
|
# pad with zeros to 12 chars
|
||||||
writers.write_bytes_fixed(w, code + bytearray([0] * (12 - len(code))), 12)
|
writers.write_bytes_fixed(w, code + bytearray([0] * (12 - len(code))), 12)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user