فهرست منبع

update: gmssl添加更多防御

Wendal Chen 2 سال پیش
والد
کامیت
fc4baf105d
1فایلهای تغییر یافته به همراه12 افزوده شده و 0 حذف شده
  1. 12 0
      components/gmssl/bind/luat_lib_gmssl.c

+ 12 - 0
components/gmssl/bind/luat_lib_gmssl.c

@@ -590,6 +590,10 @@ static int l_sm2_sign(lua_State *L)
         LLOGW("private key len must be 64 byte HEX string");
         LLOGW("private key len must be 64 byte HEX string");
         return 0;
         return 0;
     }
     }
+    if (pBufLen < 1) {
+        LLOGW("待签名数据不能为空字符串");
+        return 0;
+    }
 
 
     luat_str_fromhex(pk, 64, (char*)pkey);
     luat_str_fromhex(pk, 64, (char*)pkey);
     sm2_key_set_private_key(&key, (const uint8_t*)pkey);
     sm2_key_set_private_key(&key, (const uint8_t*)pkey);
@@ -648,6 +652,14 @@ static int l_sm2_verify(lua_State *L)
         LLOGW("public key x/y len must be 64 byte HEX string");
         LLOGW("public key x/y len must be 64 byte HEX string");
         return 0;
         return 0;
     }
     }
+    if (pBufLen < 1) {
+        LLOGW("待签名数据不能为空字符串");
+        return 0;
+    }
+    if (siglen < SM2_signature_compact_size || siglen > SM2_signature_max_size) {
+        LLOGW("sig数据长度应该在70到72之间,当前传入值的长度不合法");
+        return 0;
+    }
 
 
     SM2_SIGN_CTX ctx = {0};
     SM2_SIGN_CTX ctx = {0};
     SM2_KEY key = {0};
     SM2_KEY key = {0};