Skip to content

Commit ea9944b

Browse files
committed
add validation for token abbr.
1 parent b377c0e commit ea9944b

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎src/main/java/org/tron/core/actuator/AssetIssueActuator.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ public boolean validate() throws ContractValidateException {
120120
if (!TransactionUtil.validAssetName(assetIssueContract.getName().toByteArray())) {
121121
throw new ContractValidateException("Invalidate assetName");
122122
}
123+
124+
if (!TransactionUtil.validTokenAbbrName(assetIssueContract.getAbbr().toByteArray())) {
125+
throw new ContractValidateException("Invalidate abbrName");
126+
}
123127
if (!TransactionUtil.validUrl(assetIssueContract.getUrl().toByteArray())) {
124128
throw new ContractValidateException("Invalidate url");
125129
}
@@ -137,7 +141,7 @@ public boolean validate() throws ContractValidateException {
137141
if (assetIssueContract.getEndTime() <= assetIssueContract.getStartTime()) {
138142
throw new ContractValidateException("end time should be greater than start time");
139143
}
140-
if (assetIssueContract.getStartTime() <= dbManager.getHeadBlockTimeStamp()){
144+
if (assetIssueContract.getStartTime() <= dbManager.getHeadBlockTimeStamp()) {
141145
throw new ContractValidateException("start time should be greater than HeadBlockTime");
142146
}
143147

‎src/main/java/org/tron/core/capsule/utils/TransactionUtil.java‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static boolean validAccountName(byte[] accountName) {
5555
return false;
5656
}
5757

58-
if (accountName.length < 8){
58+
if (accountName.length < 8) {
5959
return false;
6060
}
6161

@@ -93,6 +93,26 @@ public static boolean validAssetName(byte[] assetName) {
9393
return true;
9494
}
9595

96+
public static boolean validTokenAbbrName(byte[] abbrName) {
97+
if (ArrayUtils.isEmpty(abbrName)) {
98+
return false;
99+
}
100+
if (abbrName.length > 5) {
101+
return false;
102+
}
103+
// b must read able.
104+
for (byte b : abbrName) {
105+
if (b < 0x21) {
106+
return false; // 0x21 = '!'
107+
}
108+
if (b > 0x7E) {
109+
return false; // 0x7E = '~'
110+
}
111+
}
112+
return true;
113+
}
114+
115+
96116
public static boolean validAssetDescription(byte[] description) {
97117
if (ArrayUtils.isEmpty(description)) {
98118
return true; //description can empty

0 commit comments

Comments
 (0)