diff --git a/src/mapleall/bin/dex2mpl b/src/mapleall/bin/dex2mpl index 2ccee50cd7271fcb59458fc4fdea5d8e4e91caa5..25280cb56986796ea6417d47dad72f53dadc76f6 100755 Binary files a/src/mapleall/bin/dex2mpl and b/src/mapleall/bin/dex2mpl differ diff --git a/src/mapleall/bin/dex2mpl_android b/src/mapleall/bin/dex2mpl_android index dc775fcf5790dffe2e322b8275073ac38e6ef84a..2a241b87c7ba67a5742847ce772ef4d9cd748335 100755 Binary files a/src/mapleall/bin/dex2mpl_android and b/src/mapleall/bin/dex2mpl_android differ diff --git a/src/mapleall/bin/jbc2mpl b/src/mapleall/bin/jbc2mpl index fe6a8bba33b048d922602022d223908df69b7913..c456172d1843e3563e1219f37b1ae61acad73e74 100755 Binary files a/src/mapleall/bin/jbc2mpl and b/src/mapleall/bin/jbc2mpl differ diff --git a/src/mapleall/deplibs/libmempool.a b/src/mapleall/deplibs/libmempool.a index 6eab6f7a55a686ae6e89d0d867e9236c7f19f5ff..f44f9add3dd5703e0356ed153c73bb265751dda7 100644 Binary files a/src/mapleall/deplibs/libmempool.a and b/src/mapleall/deplibs/libmempool.a differ diff --git a/src/mapleall/maple_be/BUILD.gn b/src/mapleall/maple_be/BUILD.gn index 97055908af3bddbf7fd8c4d7b2a367b4a15d516a..e02af538d8f8e5f2143ca590188b068c1b6f1c91 100644 --- a/src/mapleall/maple_be/BUILD.gn +++ b/src/mapleall/maple_be/BUILD.gn @@ -27,7 +27,7 @@ include_directories = [ "${MAPLEALL_ROOT}/mempool/include", "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_phase/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] src_libmplad = [ "src/ad/mad.cpp" ] @@ -162,7 +162,7 @@ executable("maplegen") { "${MAPLEALL_ROOT}/maple_be/mdgen/src/mdrecord.cpp", ] deps = [ - "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", + "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", ] libs = [ "${OPENSOURCE_DEPS}/libmempool.a", @@ -175,6 +175,6 @@ executable("maplegen") { "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] } diff --git a/src/mapleall/maple_driver/BUILD.gn b/src/mapleall/maple_driver/BUILD.gn index 7c358a1fe3947a6b2ee4c0a251e90f404b2ab45d..b303e72173bf030301502e241f3a94ce938f6946 100644 --- a/src/mapleall/maple_driver/BUILD.gn +++ b/src/mapleall/maple_driver/BUILD.gn @@ -36,7 +36,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_phase/include", "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] executable("maple") { @@ -58,7 +58,7 @@ executable("maple") { deps = [ ":libdriver_option", ":liboption_parser", - "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", + "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_be:libcg", "${MAPLEALL_ROOT}/maple_be:libmplad", "${MAPLEALL_ROOT}/maple_be:libmplbe", @@ -96,7 +96,7 @@ static_library("liboption_parser") { "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] output_dir = "${root_out_dir}/ar" } diff --git a/src/mapleall/maple_ipa/BUILD.gn b/src/mapleall/maple_ipa/BUILD.gn index c6c4fd93cc0da7efac298037a40740aa29d6becf..d259e172ecaa618982e025fc259f1c8bc04ee111 100644 --- a/src/mapleall/maple_ipa/BUILD.gn +++ b/src/mapleall/maple_ipa/BUILD.gn @@ -21,7 +21,7 @@ include_directories = [ "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/maple_phase/include", "${MAPLEALL_ROOT}/maple_driver/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] src_libmplipa = [ diff --git a/src/mapleall/maple_ir/BUILD.gn b/src/mapleall/maple_ir/BUILD.gn index a6836e1d5fbe1b1e3d0d53fdf5910714788d3cf6..609581dda61accbb4d8f84b78cd8d6ed988170db 100644 --- a/src/mapleall/maple_ir/BUILD.gn +++ b/src/mapleall/maple_ir/BUILD.gn @@ -18,7 +18,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/maple_phase/include", @@ -70,7 +70,7 @@ executable("irbuild") { include_dirs = include_directories deps = [ ":libmplir", - "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", + "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_driver:liboption_parser", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", ] diff --git a/src/mapleall/maple_me/BUILD.gn b/src/mapleall/maple_me/BUILD.gn index 667207393bc01f2768fff0bcdb90921aea840082..13753a45a6978ab876bdfbdcd76a4739342c3b8b 100644 --- a/src/mapleall/maple_me/BUILD.gn +++ b/src/mapleall/maple_me/BUILD.gn @@ -15,7 +15,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/maple_ipa/include", "${MAPLEALL_ROOT}/mpl2mpl/include", diff --git a/src/mapleall/mpl2mpl/BUILD.gn b/src/mapleall/mpl2mpl/BUILD.gn index 1d34903d8f120008345084f3f1821a9165f8d381..028b8430a56bcc0068c8754f57d91fe36e0dcc44 100644 --- a/src/mapleall/mpl2mpl/BUILD.gn +++ b/src/mapleall/mpl2mpl/BUILD.gn @@ -21,7 +21,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] src_libmpl2mpl = [ diff --git a/src/mplfe/BUILD.gn b/src/mplfe/BUILD.gn index 786820a0a41d1dee947b495c32e37b0421b82fb5..2bc68f21159a96d9b91978fe7dbdfd186af0728a 100644 --- a/src/mplfe/BUILD.gn +++ b/src/mplfe/BUILD.gn @@ -28,7 +28,7 @@ include_directories = [ "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/maple_me/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] static_library("lib_mplfe_util") { @@ -91,7 +91,7 @@ executable("mplfe") { ":lib_mplfe_input", ":lib_mplfe_jbc_input", ":lib_mplfe_util", - "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", + "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_driver:libdriver_option", "${MAPLEALL_ROOT}/maple_ir:libmplir", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", @@ -110,7 +110,7 @@ include_jbc_input_directories = [ "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mempool/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", ] static_library("lib_mplfe_jbc_input") { diff --git a/src/mplfe/test/BUILD.gn b/src/mplfe/test/BUILD.gn index bcaecda545505800cb79d9557c1e4fdf38843132..8a377f1ee84845d11a0582c83c3e5b92ae4f7ff9 100644 --- a/src/mplfe/test/BUILD.gn +++ b/src/mplfe/test/BUILD.gn @@ -24,7 +24,7 @@ cflags += [ include_directories = [ "${MPLFE_ROOT}/common/include", "${MPLFE_ROOT}/jbc_input/include", - "${MAPLEALL_ROOT}/huawei_secure_c/include", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include", "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/maple_util/include", "${MAPLEALL_ROOT}/maple_driver/include", @@ -66,7 +66,7 @@ executable("mplfeUT") { ] include_dirs = include_directories deps = [ - "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", + "${MAPLE_ROOT}/third_party/bounds_checking_function:libHWSecureC", "${MAPLEALL_ROOT}/maple_ir:libmplir", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", "${MPLFE_ROOT}:lib_mplfe_jbc_input", diff --git a/src/mrt/BUILD.gn b/src/mrt/BUILD.gn index a972797bcb98a150eb0802b96d2b353c7062acf0..dcb433b88399a64697579daa8c33266c3ce220d6 100644 --- a/src/mrt/BUILD.gn +++ b/src/mrt/BUILD.gn @@ -192,7 +192,7 @@ group("maple-rt") { deps = [ "${MAPLE_MRT_ROOT}/compiler-rt:libmplcompiler-rt", "${MAPLE_MRT_ROOT}/dexinterface:libdexinterface", - "${MAPLE_MRT_ROOT}/huawei_secure_c:libhuawei_secure_c", + "${MAPLE_ROOT}/third_party/bounds_checking_function:libhuawei_secure_c", "${MAPLE_MRT_ROOT}/interpreter:libzterp", "${MAPLE_MRT_ROOT}/libcore-static-binding-jni:libcore-static-binding-jni", "${MAPLE_MRT_ROOT}/maplert:libmaplert", diff --git a/src/mrt/compiler-rt/BUILD.gn b/src/mrt/compiler-rt/BUILD.gn index 0bfc72a4f4c2ee51929d61a54862a3fdfa0f7ae5..66de71224fe44a5e1309338ef95ce70aba3c9d50 100644 --- a/src/mrt/compiler-rt/BUILD.gn +++ b/src/mrt/compiler-rt/BUILD.gn @@ -82,7 +82,7 @@ include_common = [ "include", "public-headers", "${THIRD_PARTY_ROOT}/libnativehelper/include_jni", - "${MAPLEALL_ROOT}/huawei_secure_c/include/", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include/", "${MAPLE_MRT_ROOT}/maplert/include", "${MAPLE_MRT_ROOT}/maplert/public-headers/", "${MAPLE_MRT_ROOT}/libmrtbase/include/", diff --git a/src/mrt/deplibs/libcore-static-binding-jni-qemu.a b/src/mrt/deplibs/libcore-static-binding-jni-qemu.a index a1d41c786f8fdc30357df72362e40b8f957b64f3..4aa1cca2f37f3f75136717a9e89d22193a4a6412 100644 Binary files a/src/mrt/deplibs/libcore-static-binding-jni-qemu.a and b/src/mrt/deplibs/libcore-static-binding-jni-qemu.a differ diff --git a/src/mrt/deplibs/libmplandroid.so b/src/mrt/deplibs/libmplandroid.so index e180f06caba33b87daa42be5aa1484d2396ed480..b0aed0c0c9bf00aa3565fa06eda50fafaeffa58e 100755 Binary files a/src/mrt/deplibs/libmplandroid.so and b/src/mrt/deplibs/libmplandroid.so differ diff --git a/src/mrt/huawei_secure_c/BUILD.gn b/src/mrt/huawei_secure_c/BUILD.gn deleted file mode 100644 index feb0c0605055a1923939d877ee2ea11303fc2595..0000000000000000000000000000000000000000 --- a/src/mrt/huawei_secure_c/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# -# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. -# -# OpenArkCompiler is licensed under Mulan PSL v2. -# You can use this software according to the terms and conditions of the Mulan PSL v2. -# You may obtain a copy of Mulan PSL v2 at: -# -# http://license.coscl.org.cn/MulanPSL2 -# -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR -# FIT FOR A PARTICULAR PURPOSE. -# See the Mulan PSL v2 for more details. -# -sources_common = [ - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/fscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/fwscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/gets_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/memcpy_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/memmove_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/memset_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/scanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/securecutil.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/secureinput_a.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/secureinput_w.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/secureprintoutput_a.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/secureprintoutput_w.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/snprintf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/sprintf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/sscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/strcat_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/strcpy_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/strncat_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/strncpy_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/strtok_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/swprintf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/swscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vfscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vfwscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vsnprintf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vsprintf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vsscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vswprintf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vswscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/vwscanf_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/wcscat_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/wcscpy_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/wcsncat_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/wcsncpy_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/wcstok_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/wmemcpy_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/wmemmove_s.c", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src/wscanf_s.c", -] - -include_common = [ - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/include", - "${MAPLE_ROOT}/src/mapleall/huawei_secure_c/src", -] - -static_library("libhuawei_secure_c") { - sources = sources_common - include_dirs = include_common - - cflags = [] - cflags_c = [] - configs = [ "${MAPLE_MRT_ROOT}:mrt_c_flags" ] -} diff --git a/src/mrt/libcore-static-binding-jni/BUILD.gn b/src/mrt/libcore-static-binding-jni/BUILD.gn index 7cd68de04f019fe16fd245d3fe1c165c70d832d8..58172cde0f155e8df8fead04d3de1da6d04d5fbc 100644 --- a/src/mrt/libcore-static-binding-jni/BUILD.gn +++ b/src/mrt/libcore-static-binding-jni/BUILD.gn @@ -38,7 +38,7 @@ include_common = [ "${MAPLE_MRT_ROOT}/libmrtbase/include", "${MAPLE_MRT_ROOT}/libmrtbase/include/linux", "${MAPLE_MRT_ROOT}/maplert/public-headers", - "${MAPLEALL_ROOT}/huawei_secure_c/include/", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include/", "${MAPLE_MRT_ROOT}/dexinterface", "${MAPLE_MRT_ROOT}/interpreter/zterp", "${MAPLE_MRT_ROOT}", diff --git a/src/mrt/maplert/BUILD.gn b/src/mrt/maplert/BUILD.gn index 653336473fbe4555a6de31c5f8e62f29310eaf12..32a9c8a1b2b7a2375557db76d7baf1a39e4d6327 100644 --- a/src/mrt/maplert/BUILD.gn +++ b/src/mrt/maplert/BUILD.gn @@ -56,7 +56,7 @@ sources_common = [ include_common = [ "${MAPLE_MRT_ROOT}/maplert/include", "${THIRD_PARTY_ROOT}/libnativehelper/include_jni", - "${MAPLEALL_ROOT}/huawei_secure_c/include/", + "${MAPLE_ROOT}/third_party/bounds_checking_function/include/", "${MAPLE_MRT_ROOT}/compiler-rt/include", "${MAPLE_MRT_ROOT}/compiler-rt/public-headers", "${MAPLE_MRT_ROOT}/maplert/public-headers", diff --git a/src/mapleall/huawei_secure_c/BUILD.gn b/third_party/bounds_checking_function/BUILD.gn similarity index 62% rename from src/mapleall/huawei_secure_c/BUILD.gn rename to third_party/bounds_checking_function/BUILD.gn index c33c92e425f9173b78b2309d199bab658cb4c4cc..e21b3dd7f3209d8a5256a77fe7d497c7a5bf9131 100644 --- a/src/mapleall/huawei_secure_c/BUILD.gn +++ b/third_party/bounds_checking_function/BUILD.gn @@ -1,17 +1,3 @@ -# -# Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. -# -# OpenArkCompiler is licensed under Mulan PSL v2. -# You can use this software according to the terms and conditions of the Mulan PSL v2. -# You may obtain a copy of Mulan PSL v2 at: -# -# http://license.coscl.org.cn/MulanPSL2 -# -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR -# FIT FOR A PARTICULAR PURPOSE. -# See the Mulan PSL v2 for more details. -# src_libHWSecureC = [ "src/vsprintf_s.c", "src/wmemmove_s.c", @@ -62,5 +48,14 @@ include_common = [ static_library("libHWSecureC") { sources = src_libHWSecureC include_dirs = include_common - output_dir = "${root_out_dir}/ar" + output_dir = "${root_out_dir}/lib/${HOST_ARCH}" +} + +static_library("libhuawei_secure_c") { + sources = src_libHWSecureC + include_dirs = include_common + + cflags = [] + cflags_c = [] + configs = [ "${MAPLE_ROOT}/src/mrt:mrt_c_flags" ] } diff --git a/third_party/bounds_checking_function/LICENSE b/third_party/bounds_checking_function/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..faba10b6c3298de9ae7097670463f9304af091cc --- /dev/null +++ b/third_party/bounds_checking_function/LICENSE @@ -0,0 +1,124 @@ +木兰宽松许可证, 第2版 + +2020年1月 http://license.coscl.org.cn/MulanPSL2 + +您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: + +0. 定义 + +“软件” 是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 + +“贡献” 是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 + +“贡献者” 是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 + +“法人实体” 是指提交贡献的机构及其“关联实体”。 + +“关联实体” 是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 + +1. 授予版权许可 + +每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 + +2. 授予专利许可 + +每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 + +3. 无商标许可 + +“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 + +4. 分发限制 + +您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 + +5. 免责声明与责任限制 + +“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + +6. 语言 + +“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 + +条款结束 + +如何将木兰宽松许可证,第2版,应用到您的软件 + +如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: + +1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; + +2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; + +3, 请将如下声明文本放入每个源文件的头部注释中。 + +Copyright (c) [Year] [name of copyright holder] +[Software Name] is licensed under Mulan PSL v2. +You can use this software according to the terms and conditions of the Mulan PSL v2. +You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 +THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +See the Mulan PSL v2 for more details. +Mulan Permissive Software License,Version 2 +Mulan Permissive Software License,Version 2 (Mulan PSL v2) + +January 2020 http://license.coscl.org.cn/MulanPSL2 + +Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + +0. Definition + +Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + +Contribution means the copyrightable work licensed by a particular Contributor under this License. + +Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + +Legal Entity means the entity making a Contribution and all its Affiliates. + +Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + +1. Grant of Copyright License + +Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + +2. Grant of Patent License + +Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + +3. No Trademark License + +No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4. + +4. Distribution Restriction + +You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + +5. Disclaimer of Warranty and Limitation of Liability + +THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +6. Language + +THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + +END OF THE TERMS AND CONDITIONS + +How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + +To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + +Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; +Create a file named "LICENSE" which contains the whole context of this License in the first directory of your software package; +Attach the statement to the appropriate annotated syntax at the beginning of each source file. +Copyright (c) [Year] [name of copyright holder] +[Software Name] is licensed under Mulan PSL v2. +You can use this software according to the terms and conditions of the Mulan PSL v2. +You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 +THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +See the Mulan PSL v2 for more details. \ No newline at end of file diff --git a/third_party/bounds_checking_function/README.en.md b/third_party/bounds_checking_function/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..c905d57e51b80b9109123ed33c48157616e7eae2 --- /dev/null +++ b/third_party/bounds_checking_function/README.en.md @@ -0,0 +1,9 @@ +# bounds_checking_function + +#### Description + +- following the standard of C11 Annex K (bound-checking interfaces), functions of the common memory/string operation classes, such as memcpy_s, strcpy_s, are selected and implemented. + +- other standard functions in C11 Annex K will be analyzed in the future and implemented in this organization if necessary. + +- handles the release, update, and maintenance of bounds_checking_function. diff --git a/third_party/bounds_checking_function/README.md b/third_party/bounds_checking_function/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4cb88ea74afd61d685d37206a940c8b0979631c3 --- /dev/null +++ b/third_party/bounds_checking_function/README.md @@ -0,0 +1,6 @@ +# bounds_checking_function + +#### 浠嬬粛 +- 閬靛惊C11 Annex K (Bounds-checking interfaces)鐨勬爣鍑嗭紝閫夊彇骞跺疄鐜颁簡甯歌鐨勫唴瀛/瀛楃涓叉搷浣滅被鐨勫嚱鏁帮紝濡俶emcpy_s銆乻trcpy_s绛夊嚱鏁般 +- 鏈潵灏嗗垎鏋怌11 Annex K涓殑鍏朵粬鏍囧噯鍑芥暟锛屽鏋滄湁蹇呰锛屽皢鍦ㄨ缁勭粐涓疄鐜般 +- 澶勭悊杈圭晫妫鏌ュ嚱鏁扮殑鐗堟湰鍙戝竷銆佹洿鏂颁互鍙婄淮鎶ゃ diff --git a/src/mapleall/huawei_secure_c/include/securec.h b/third_party/bounds_checking_function/include/securec.h similarity index 95% rename from src/mapleall/huawei_secure_c/include/securec.h rename to third_party/bounds_checking_function/include/securec.h index 6f21773be39b2777356ab5317829dad0286dad32..e0a977e275c400445b2bd61d9858c25c15785739 100644 --- a/src/mapleall/huawei_secure_c/include/securec.h +++ b/third_party/bounds_checking_function/include/securec.h @@ -1,20 +1,22 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: The user of this secure c library should include this header file in you source code. + * This header file declare all supported API prototype of the library, + * such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s, sprintf_s, scanf_s, and so on. + * Author: lishunda + * Create: 2014-02-25 */ -#ifndef __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 -#define __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 +#ifndef SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27 +#define SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27 #include "securectype.h" #ifndef SECUREC_HAVE_STDARG_H @@ -26,21 +28,21 @@ #endif #ifndef SECUREC_HAVE_ERRNO_H -#if SECUREC_IN_KERNEL -#define SECUREC_HAVE_ERRNO_H 0 -#else #define SECUREC_HAVE_ERRNO_H 1 #endif -#endif /* EINVAL ERANGE may defined in errno.h */ #if SECUREC_HAVE_ERRNO_H +#if SECUREC_IN_KERNEL +#include +#else #include #endif +#endif /* Define error code */ #if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \ - (defined(__STDC_WANT_LIB_EXT1__) && (__STDC_WANT_LIB_EXT1__ == 0)) + (defined(__STDC_WANT_LIB_EXT1__) && (!__STDC_WANT_LIB_EXT1__)) #ifndef SECUREC_DEFINED_ERRNO_TYPE #define SECUREC_DEFINED_ERRNO_TYPE /* Just check whether macrodefinition exists. */ @@ -61,8 +63,8 @@ typedef int errno_t; #endif #ifndef EINVAL_AND_RESET -/* Once the error is detected, the dest buffer must be reseted! */ -#define EINVAL_AND_RESET (22 | 128) +/* Once the error is detected, the dest buffer must be reseted! Value is 22 or 128 */ +#define EINVAL_AND_RESET 150 #endif #ifndef ERANGE @@ -71,13 +73,13 @@ typedef int errno_t; #endif #ifndef ERANGE_AND_RESET -/* Once the error is detected, the dest buffer must be reseted! */ -#define ERANGE_AND_RESET (34 | 128) +/* Once the error is detected, the dest buffer must be reseted! Value is 34 or 128 */ +#define ERANGE_AND_RESET 162 #endif #ifndef EOVERLAP_AND_RESET -/* Once the buffer overlap is detected, the dest buffer must be reseted! */ -#define EOVERLAP_AND_RESET (54 | 128) +/* Once the buffer overlap is detected, the dest buffer must be reseted! Value is 54 or 128 */ +#define EOVERLAP_AND_RESET 182 #endif /* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */ @@ -106,7 +108,7 @@ extern "C" { #endif /* * Description: The GetHwSecureCVersion function get SecureC Version string and version number. - * Parameter: verNumber - to store version number + * Parameter: verNumber - to store version number (for example value is 0x500 | 0xa) * Return: version string */ SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber); @@ -128,7 +130,7 @@ extern "C" { #define SECUREC_ONLY_DECLARE_MEMSET 0 #endif -#if SECUREC_ONLY_DECLARE_MEMSET == 0 +#if !SECUREC_ONLY_DECLARE_MEMSET #if SECUREC_ENABLE_MEMMOVE /* @@ -375,7 +377,7 @@ extern "C" { SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context); #endif -#if SECUREC_ENABLE_GETS && SECUREC_IN_KERNEL == 0 +#if SECUREC_ENABLE_GETS && !SECUREC_IN_KERNEL /* * Description: The gets_s function reads at most one less than the number of characters specified * by destMax from the stream pointed to by stdin, into the array pointed to by buffer @@ -386,7 +388,6 @@ extern "C" { SECUREC_API char *gets_s(char *buffer, size_t destMax); #endif - #if SECUREC_ENABLE_WCHAR_FUNC #if SECUREC_ENABLE_MEMCPY /* @@ -619,17 +620,11 @@ extern "C" { (((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \ memset_sOptAsm((dest), (destMax), (c), (count)))) -#else -#define strcpy_sp strcpy_s -#define strncpy_sp strncpy_s -#define strcat_sp strcat_s -#define strncat_sp strncat_s -#define memcpy_sp memcpy_s -#define memset_sp memset_s + #endif #ifdef __cplusplus } -#endif /* __cplusplus */ -#endif /* __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 */ +#endif +#endif diff --git a/src/mapleall/huawei_secure_c/include/securectype.h b/third_party/bounds_checking_function/include/securectype.h similarity index 84% rename from src/mapleall/huawei_secure_c/include/securectype.h rename to third_party/bounds_checking_function/include/securectype.h index e0994254476992dba711242cb0db4fa88156f7a3..17cca940d83f611bdbbaeca2552ed3bb937a9113 100644 --- a/src/mapleall/huawei_secure_c/include/securectype.h +++ b/third_party/bounds_checking_function/include/securectype.h @@ -1,28 +1,26 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. - */ -/* - * [Standardize-exceptions]: Performance-sensitive - * [reason]: Strict parameter verification has been done before use + * Description: Define internal used macro and data type. The marco of SECUREC_ON_64BITS + * will be determined in this header file, which is a switch for part + * of code. Some macro are used to supress warning by MS compiler. + * Author: lishunda + * Create: 2014-02-25 */ -#ifndef __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 -#define __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 +#ifndef SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7 +#define SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7 #ifndef SECUREC_USING_STD_SECURE_LIB #if defined(_MSC_VER) && _MSC_VER >= 1400 -#if defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__ == 0 +#if defined(__STDC_WANT_SECURE_LIB__) && (!__STDC_WANT_SECURE_LIB__) /* Security functions have been provided since vs2005, default use of system library functions */ #define SECUREC_USING_STD_SECURE_LIB 0 #else @@ -33,9 +31,8 @@ #endif #endif - /* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */ -#if defined(_MSC_VER) && _MSC_VER >= 1400 && SECUREC_USING_STD_SECURE_LIB == 0 +#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (!SECUREC_USING_STD_SECURE_LIB) #ifndef SECUREC_DISABLE_CRT_FUNC #define SECUREC_DISABLE_CRT_FUNC 1 #endif @@ -90,7 +87,6 @@ #endif #endif - /* Default secure function declaration, default declarations for non-standard functions */ #ifndef SECUREC_SNPRINTF_TRUNCATED #define SECUREC_SNPRINTF_TRUNCATED 1 @@ -265,7 +261,7 @@ #endif #endif /* SECUREC_USE_STD_SECURE_LIB */ -#if SECUREC_ENABLE_SCANF_FILE == 0 +#if !SECUREC_ENABLE_SCANF_FILE #if SECUREC_ENABLE_FSCANF #undef SECUREC_ENABLE_FSCANF #define SECUREC_ENABLE_FSCANF 0 @@ -357,12 +353,14 @@ #endif /* Some system may no stddef.h */ #if SECUREC_HAVE_STDDEF_H +#if !SECUREC_IN_KERNEL #include #endif #endif +#endif /* - * Add the -DSECUREC_SUPPORT_FORMAT_WARNING compiler option to supoort -Wformat. + * Add the -DSECUREC_SUPPORT_FORMAT_WARNING=1 compiler option to supoort -Wformat=2. * Default does not check the format is that the same data type in the actual code. * In the product is different in the original data type definition of VxWorks and Linux. */ @@ -370,24 +368,28 @@ #define SECUREC_SUPPORT_FORMAT_WARNING 0 #endif -/* SECUREC_PCLINT for tool do not recognize __attribute__ just for pclint */ -#if SECUREC_SUPPORT_FORMAT_WARNING && !defined(SECUREC_PCLINT) +#if SECUREC_SUPPORT_FORMAT_WARNING #define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y)))) #else #define SECUREC_ATTRIBUTE(x, y) #endif -/* SECUREC_PCLINT for tool do not recognize __builtin_expect, just for pclint */ -#if defined(__GNUC__) && \ - ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))) && \ - !defined(SECUREC_PCLINT) /* - * This is a built-in function that can be used without a declaration, if you encounter an undeclared compilation alarm, + * Add the -DSECUREC_SUPPORT_BUILTIN_EXPECT=0 compiler option, if complier can not support __builtin_expect. + */ +#ifndef SECUREC_SUPPORT_BUILTIN_EXPECT +#define SECUREC_SUPPORT_BUILTIN_EXPECT 1 +#endif + +#if SECUREC_SUPPORT_BUILTIN_EXPECT && defined(__GNUC__) && ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))) +/* + * This is a built-in function that can be used without a declaration, if warning for declaration not found occurred, * you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options */ #ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE long __builtin_expect(long exp, long c); #endif + #define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1) #define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0) #else @@ -407,7 +409,7 @@ long __builtin_expect(long exp, long c); #endif #define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t)) -#if SECUREC_STRING_MAX_LEN > 0x7fffffff +#if SECUREC_STRING_MAX_LEN > 0x7fffffffUL #error "max string is 2G" #endif @@ -460,7 +462,6 @@ long __builtin_expect(long exp, long c); #endif #endif - #if SECUREC_WITH_PERFORMANCE_ADDONS #ifndef SECUREC_TWO_MIN @@ -484,30 +485,30 @@ long __builtin_expect(long exp, long c); /* For strcat_s performance optimization */ #if defined(__GNUC__) #define SECUREC_STRCAT_SM(dest, destMax, src) ({ \ - int catRet = EOK; \ + int catRet_ = EOK; \ if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ - char *catTmpDst = (char *)(dest); \ - size_t catRestSize = (destMax); \ - while (catRestSize > 0 && *catTmpDst != '\0') { \ - ++catTmpDst; \ - --catRestSize; \ + char *catTmpDst_ = (char *)(dest); \ + size_t catRestSize_ = (destMax); \ + while (catRestSize_ > 0 && *catTmpDst_ != '\0') { \ + ++catTmpDst_; \ + --catRestSize_; \ } \ - if (catRestSize == 0) { \ - catRet = EINVAL; \ - } else if ((strlen(src) + 1) <= catRestSize) { \ - memcpy(catTmpDst, (src), strlen(src) + 1); \ - catRet = EOK; \ + if (catRestSize_ == 0) { \ + catRet_ = EINVAL; \ + } else if ((strlen(src) + 1) <= catRestSize_) { \ + memcpy(catTmpDst_, (src), strlen(src) + 1); \ + catRet_ = EOK; \ } else { \ - catRet = ERANGE; \ + catRet_ = ERANGE; \ } \ - if (catRet != EOK) { \ - catRet = strcat_s((dest), (destMax), (src)); \ + if (catRet_ != EOK) { \ + catRet_ = strcat_s((dest), (destMax), (src)); \ } \ } else { \ - catRet = strcat_s((dest), (destMax), (src)); \ + catRet_ = strcat_s((dest), (destMax), (src)); \ } \ - catRet; \ + catRet_; \ }) #else #define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src)) @@ -516,35 +517,35 @@ long __builtin_expect(long exp, long c); /* For strncat_s performance optimization */ #if defined(__GNUC__) #define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \ - int ncatRet = EOK; \ + int ncatRet_ = EOK; \ if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ (((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ - char *ncatTmpDest = (char *)(dest); \ - size_t ncatRestSize = (size_t)(destMax); \ - while (ncatRestSize > 0 && *ncatTmpDest != '\0') { \ - ++ncatTmpDest; \ - --ncatRestSize; \ + char *ncatTmpDest_ = (char *)(dest); \ + size_t ncatRestSize_ = (size_t)(destMax); \ + while (ncatRestSize_ > 0 && *ncatTmpDest_ != '\0') { \ + ++ncatTmpDest_; \ + --ncatRestSize_; \ } \ - if (ncatRestSize == 0) { \ - ncatRet = EINVAL; \ - } else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize) { \ + if (ncatRestSize_ == 0) { \ + ncatRet_ = EINVAL; \ + } else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize_) { \ if ((size_t)(count) < strlen(src)) { \ - memcpy(ncatTmpDest, (src), (count)); \ - *(ncatTmpDest + (count)) = '\0'; \ + memcpy(ncatTmpDest_, (src), (count)); \ + *(ncatTmpDest_ + (count)) = '\0'; \ } else { \ - memcpy(ncatTmpDest, (src), strlen(src) + 1); \ + memcpy(ncatTmpDest_, (src), strlen(src) + 1); \ } \ } else { \ - ncatRet = ERANGE; \ + ncatRet_ = ERANGE; \ } \ - if (ncatRet != EOK) { \ - ncatRet = strncat_s((dest), (destMax), (src), (count)); \ + if (ncatRet_ != EOK) { \ + ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \ } \ } else { \ - ncatRet = strncat_s((dest), (destMax), (src), (count)); \ + ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \ } \ - ncatRet; \ + ncatRet_; \ }) #else #define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count)) @@ -565,5 +566,5 @@ long __builtin_expect(long exp, long c); (memset_s((dest), (destMax), (c), (count)))) #endif -#endif /* __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 */ +#endif diff --git a/src/mapleall/huawei_secure_c/src/fscanf_s.c b/third_party/bounds_checking_function/src/fscanf_s.c similarity index 82% rename from src/mapleall/huawei_secure_c/src/fscanf_s.c rename to third_party/bounds_checking_function/src/fscanf_s.c index a581cc18de3df0a9ef5e1f0d483957249b9516cf..2d1e735c3c8cec8d2c171a8eac2669588f77cc07 100644 --- a/src/mapleall/huawei_secure_c/src/fscanf_s.c +++ b/third_party/bounds_checking_function/src/fscanf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: fscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h" @@ -52,4 +52,3 @@ int fscanf_s(FILE *stream, const char *format, ...) return ret; } - diff --git a/src/mapleall/huawei_secure_c/src/fwscanf_s.c b/third_party/bounds_checking_function/src/fwscanf_s.c similarity index 82% rename from src/mapleall/huawei_secure_c/src/fwscanf_s.c rename to third_party/bounds_checking_function/src/fwscanf_s.c index 1983fccc8a7d94a673e794115c8981395c5d434a..ed2438b1d91b59cdede3669d3537da9cc0c6ee1a 100644 --- a/src/mapleall/huawei_secure_c/src/fwscanf_s.c +++ b/third_party/bounds_checking_function/src/fwscanf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: fwscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h" @@ -51,4 +51,3 @@ int fwscanf_s(FILE *stream, const wchar_t *format, ...) return ret; } - diff --git a/src/mapleall/huawei_secure_c/src/gets_s.c b/third_party/bounds_checking_function/src/gets_s.c similarity index 54% rename from src/mapleall/huawei_secure_c/src/gets_s.c rename to third_party/bounds_checking_function/src/gets_s.c index 67490ba75283cf4849c5b2049ffa728707385b22..18d785888cde0d9bdc01b1e9e2ccf9549f7a5b76 100644 --- a/src/mapleall/huawei_secure_c/src/gets_s.c +++ b/third_party/bounds_checking_function/src/gets_s.c @@ -1,26 +1,30 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: gets_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" -SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) +/* + * The parameter size is buffer size in byte + */ +SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t size) { - int i; - /* No need to determine whether integer overflow exists */ - for (i = (int)(len - 1); i >= 0 && (buffer[i] == '\r' || buffer[i] == '\n'); --i) { - buffer[i] = '\0'; + size_t len = strlen(buffer); + --len; /* Unsigned integer wrapping is accepted and is checked afterwards */ + while (len < size && (buffer[len] == '\r' || buffer[len] == '\n')) { + buffer[len] = '\0'; + --len; /* Unsigned integer wrapping is accepted and is checked next loop */ } } @@ -36,7 +40,7 @@ SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) * * * buffer Storage location for input string. - * numberOfElements The size of the buffer. + * destMax The size of the buffer. * * * buffer is updated @@ -45,13 +49,12 @@ SECUREC_INLINE void SecTrimCRLF(char *buffer, size_t len) * buffer Successful operation * NULL Improper parameter or read fail */ -char *gets_s(char *buffer, size_t numberOfElements) +char *gets_s(char *buffer, size_t destMax) { - size_t len; #ifdef SECUREC_COMPATIBLE_WIN_FORMAT - size_t bufferSize = ((numberOfElements == (size_t)-1) ? SECUREC_STRING_MAX_LEN : numberOfElements); + size_t bufferSize = ((destMax == (size_t)(-1)) ? SECUREC_STRING_MAX_LEN : destMax); #else - size_t bufferSize = numberOfElements; + size_t bufferSize = destMax; #endif if (buffer == NULL || bufferSize == 0 || bufferSize > SECUREC_STRING_MAX_LEN) { @@ -59,15 +62,11 @@ char *gets_s(char *buffer, size_t numberOfElements) return NULL; } - if (fgets(buffer, (int)bufferSize, SECUREC_STREAM_STDIN) == NULL) { - return NULL; - } - - len = strlen(buffer); - if (len > 0 && len < bufferSize) { - SecTrimCRLF(buffer, len); + if (fgets(buffer, (int)bufferSize, SECUREC_STREAM_STDIN) != NULL) { + SecTrimCRLF(buffer, bufferSize); + return buffer; } - return buffer; + return NULL; } diff --git a/src/mapleall/huawei_secure_c/src/input.inl b/third_party/bounds_checking_function/src/input.inl similarity index 68% rename from src/mapleall/huawei_secure_c/src/input.inl rename to third_party/bounds_checking_function/src/input.inl index d49cce44e27c39381f8f902bcd1af81b86d821c4..06fff4157fc784e458f86722c842928b9333f221 100644 --- a/src/mapleall/huawei_secure_c/src/input.inl +++ b/third_party/bounds_checking_function/src/input.inl @@ -1,21 +1,19 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v1. - * You can use this software according to the terms and conditions of the Mulan PSL v1. - * You may obtain a copy of Mulan PSL v1 at: - * - * http://license.coscl.org.cn/MulanPSL - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v1 for more details. - */ -/* - * [Standardize-exceptions] Use unsafe function: Performance-sensitive - * [reason] Always used in the performance critical path, - * and sufficient input validation is performed before calling + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * Description: Used by secureinput_a.c and secureinput_w.c to include. + * This file provides a template function for ANSI and UNICODE compiling by + * different type definition. The functions of SecInputS or + * SecInputSW provides internal implementation for scanf family API, such as sscanf_s, fscanf_s. + * Author: lishunda + * Create: 2014-02-25 */ #ifndef INPUT_INL_5D13A042_DC3F_4ED9_A8D1_882811274C27 @@ -25,9 +23,6 @@ #if !defined(SECUREC_CTYPE_MACRO_ADAPT) #include #endif -#ifndef EOF -#define EOF (-1) -#endif #else #if !defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT) #include @@ -37,27 +32,30 @@ #endif #endif +#ifndef EOF +#define EOF (-1) +#endif + #define SECUREC_NUM_WIDTH_SHORT 0 #define SECUREC_NUM_WIDTH_INT 1 #define SECUREC_NUM_WIDTH_LONG 2 #define SECUREC_NUM_WIDTH_LONG_LONG 3 /* Also long double */ -#define SECUREC_BUFFERED_BLOK_SIZE 1024 +#define SECUREC_BUFFERED_BLOK_SIZE 1024U #if defined(SECUREC_VXWORKS_PLATFORM) && !defined(va_copy) && !defined(__va_copy) /* The name is the same as system macro. */ -#define __va_copy(d, s) do { \ - size_t size_of_d = (size_t)sizeof(d); \ - size_t size_of_s = (size_t)sizeof(s); \ - if (size_of_d != size_of_s) { \ - (void)memcpy((d), (s), sizeof(va_list)); \ +#define __va_copy(dest, src) do { \ + size_t destSize_ = (size_t)sizeof(dest); \ + size_t srcSize_ = (size_t)sizeof(src); \ + if (destSize_ != srcSize_) { \ + (void)memcpy((dest), (src), sizeof(va_list)); \ } else { \ - (void)memcpy(&(d), &(s), sizeof(va_list)); \ + (void)memcpy(&(dest), &(src), sizeof(va_list)); \ } \ } SECUREC_WHILE_ZERO #endif - #define SECUREC_MULTI_BYTE_MAX_LEN 6 /* Compatibility macro name cannot be modifie */ @@ -76,11 +74,11 @@ #define SECUREC_MAX_64BITS_VALUE_CUT_LAST_DIGIT 18446744073709551610ULL #define SECUREC_MIN_64BITS_NEG_VALUE 9223372036854775808ULL #define SECUREC_MAX_64BITS_POS_VALUE 9223372036854775807ULL -#define SECUREC_MIN_32BITS_NEG_VALUE 2147483648ULL -#define SECUREC_MAX_32BITS_POS_VALUE 2147483647ULL -#define SECUREC_MAX_32BITS_VALUE 4294967295ULL -#define SECUREC_MAX_32BITS_VALUE_INC 4294967296ULL -#define SECUREC_MAX_32BITS_VALUE_DIV_TEN 429496729ULL +#define SECUREC_MIN_32BITS_NEG_VALUE 2147483648UL +#define SECUREC_MAX_32BITS_POS_VALUE 2147483647UL +#define SECUREC_MAX_32BITS_VALUE 4294967295UL +#define SECUREC_MAX_32BITS_VALUE_INC 4294967296UL +#define SECUREC_MAX_32BITS_VALUE_DIV_TEN 429496729UL #define SECUREC_LONG_BIT_NUM ((unsigned int)(sizeof(long) << 3U)) /* Use ULL to clean up cl6x compilation alerts */ #define SECUREC_MAX_LONG_POS_VALUE ((unsigned long)(1ULL << (SECUREC_LONG_BIT_NUM - 1)) - 1) @@ -95,10 +93,17 @@ #define SECUREC_LP64_BIT_WIDTH 64 #define SECUREC_LP32_BIT_WIDTH 32 + +#define SECUREC_CONVERT_IS_SIGNED(conv) ((conv) == 'd' || (conv) == 'i') #endif -#define SECUREC_CHAR(x) (x) #define SECUREC_BRACE '{' /* [ to { */ +#define SECUREC_FILED_WIDTH_ENOUGH(spec) ((spec)->widthSet == 0 || (spec)->width > 0) +#define SECUREC_FILED_WIDTH_DEC(spec) do { \ + if ((spec)->widthSet != 0) { \ + --(spec)->width; \ + } \ +} SECUREC_WHILE_ZERO #ifdef SECUREC_FOR_WCHAR /* Bits for all wchar, size is 65536/8, only supports wide characters with a maximum length of two bytes */ @@ -116,14 +121,9 @@ ((spec).isWCharOrLong <= 0 && (spec).arrayWidth > SECUREC_STRING_MAX_LEN) || \ ((spec).isWCharOrLong > 0 && (spec).arrayWidth > SECUREC_WCHAR_STRING_MAX_LEN)) #else -#define SECUREC_ARRAY_WIDTH_IS_WRONG(spec) ((spec).arrayWidth == 0 || \ - ((spec).isWCharOrLong <= 0 && (spec).arrayWidth > SECUREC_STRING_MAX_LEN)) +#define SECUREC_ARRAY_WIDTH_IS_WRONG(spec) ((spec).arrayWidth == 0 || (spec).arrayWidth > SECUREC_STRING_MAX_LEN) #endif -/* For next %n */ -#define SECUREC_MEET_EOF_BEFORE_NEXT_N(ch, format) (((ch) == SECUREC_EOF) && \ - ((*(format) != SECUREC_CHAR('%')) || (*((format) + 1) != SECUREC_CHAR('n')))) - typedef struct { #ifdef SECUREC_FOR_WCHAR unsigned char *table; /* Default NULL */ @@ -143,76 +143,128 @@ typedef struct { typedef struct { size_t floatStrTotalLen; /* Initialization must be length of buffer in charater */ size_t floatStrUsedLen; /* Store float string len */ - SecChar buffer[SECUREC_FLOAT_BUFSIZE + 1]; SecChar *floatStr; /* Initialization must point to buffer */ SecChar *allocatedFloatStr; /* Initialization must be NULL to store alloced point */ + SecChar buffer[SECUREC_FLOAT_BUFSIZE + 1]; } SecFloatSpec; #endif +#define SECUREC_NUMBER_STATE_DEFAULT 0U +#define SECUREC_NUMBER_STATE_STARTED 1U + typedef struct { SecInt ch; /* Char read from input */ int charCount; /* Number of characters processed */ - SecUnsignedInt64 number64; - unsigned long number; + void *argPtr; /* Variable parameter pointer, point to the end of the string */ + size_t arrayWidth; /* Length of pointer Variable parameter, in charaters */ + SecUnsignedInt64 number64; /* Store input number64 value */ + unsigned long number; /* Store input number32 value */ int numberWidth; /* 0 = SHORT, 1 = int, > 1 long or L_DOUBLE */ - int isInt64Arg; /* 1 for 64-bit integer, 0 otherwise */ - int negative; /* 0 is positive */ + int numberArgType; /* 1 for 64-bit integer, 0 otherwise. use it as decode function index */ + unsigned int negative; /* 0 is positive */ #if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX))) - int beyondMax; /* Non-zero means beyond */ + unsigned int beyondMax; /* Non-zero means beyond */ #endif - void *argPtr; /* Variable parameter pointer */ - size_t arrayWidth; /* Length of pointer Variable parameter, in charaters */ + unsigned int numberState; /* Identifies whether to start processing numbers, 1 is can input number*/ int width; /* Width number in format */ int widthSet; /* 0 is not set width in format */ int convChr; /* Lowercase format conversion characters */ int oriConvChr; /* Store original format conversion, convChr may change when parsing integers */ signed char isWCharOrLong; /* -1/0 not wchar or long, 1 for wchar or long */ - char suppress; /* 0 is not have %* in format */ + unsigned char suppress; /* 0 is not have %* in format */ } SecScanSpec; -#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX))) -#define SECUREC_INIT_NUMBER_SPEC { 0, 0, 0, 0, 0, 0, NULL, 0, 0, 0, 0, 0, 0 } -#else -#define SECUREC_INIT_NUMBER_SPEC { 0, 0, 0, 0, 0, 0, NULL, 0, 0, 0, 0, 0 } -#endif - #ifdef SECUREC_FOR_WCHAR #define SECUREC_GETC fgetwc #define SECUREC_UN_GETC ungetwc -#define SECUREC_CHAR_MASK 0xffff +/* Only supports wide characters with a maximum length of two bytes in format string */ +#define SECUREC_BRACKET_CHAR_MASK 0xffffU #else #define SECUREC_GETC fgetc #define SECUREC_UN_GETC ungetc -#define SECUREC_CHAR_MASK 0xff -#endif +#define SECUREC_BRACKET_CHAR_MASK 0xffU +#endif + +#define SECUREC_CHAR_SIZE ((unsigned int)(sizeof(SecChar))) +/* To avoid 648, mask high bit: 0x00ffffff 0x0000ffff or 0x00000000 */ +#define SECUREC_CHAR_MASK_HIGH (((((((((unsigned int)(-1) >> SECUREC_CHAR_SIZE) >> SECUREC_CHAR_SIZE) >> \ + SECUREC_CHAR_SIZE) >> SECUREC_CHAR_SIZE) >> \ + SECUREC_CHAR_SIZE) >> SECUREC_CHAR_SIZE) >> \ + SECUREC_CHAR_SIZE) >> SECUREC_CHAR_SIZE) + +/* For char is 0xff, wcahr_t is 0xffff or 0xffffffff. */ +#define SECUREC_CHAR_MASK (~((((((((((unsigned int)(-1) & SECUREC_CHAR_MASK_HIGH) << \ + SECUREC_CHAR_SIZE) << SECUREC_CHAR_SIZE) << \ + SECUREC_CHAR_SIZE) << SECUREC_CHAR_SIZE) << \ + SECUREC_CHAR_SIZE) << SECUREC_CHAR_SIZE) << \ + SECUREC_CHAR_SIZE) << SECUREC_CHAR_SIZE)) + +/* According wchar_t has multiple bytes, so use sizeof */ +#define SECUREC_GET_CHAR(stream, outCh) do { \ + if ((stream)->count >= sizeof(SecChar)) { \ + *(outCh) = (SecInt)(SECUREC_CHAR_MASK & \ + (unsigned int)(int)(*((const SecChar *)(const void *)(stream)->cur))); \ + (stream)->cur += sizeof(SecChar); \ + (stream)->count -= sizeof(SecChar); \ + } else { \ + *(outCh) = SECUREC_EOF; \ + } \ +} SECUREC_WHILE_ZERO + +#define SECUREC_UN_GET_CHAR(stream) do { \ + if ((stream)->cur > (stream)->base) { \ + (stream)->cur -= sizeof(SecChar); \ + (stream)->count += sizeof(SecChar); \ + } \ +} SECUREC_WHILE_ZERO + +/* Convert wchar_t to int and then to unsigned int to keep data clearing warning */ +#define SECUREC_TO_LOWERCASE(chr) ((int)((unsigned int)(int)(chr) | (unsigned int)('a' - 'A'))) /* Record a flag for each bit */ -#define SECUREC_BRACKET_INDEX(x) ((unsigned int)(x) >> 3) -#define SECUREC_BRACKET_VALUE(x) ((unsigned char)(1 << ((unsigned int)(x) & 7))) +#define SECUREC_BRACKET_INDEX(x) ((unsigned int)(x) >> 3U) +#define SECUREC_BRACKET_VALUE(x) ((unsigned char)(1U << ((unsigned int)(x) & 7U))) +#if SECUREC_IN_KERNEL +#define SECUREC_CONVERT_IS_UNSIGNED(conv) ((conv) == 'x' || (conv) == 'o' || (conv) == 'u') +#endif /* - * Set char in %[xxx] into table, only supports wide characters with a maximum length of two bytes + * Set char in %[xxx] into table, only supports wide characters with a maximum length of two bytes */ SECUREC_INLINE void SecBracketSetBit(unsigned char *table, SecUnsignedChar ch) { - unsigned int tableIndex = SECUREC_BRACKET_INDEX(((unsigned int)(int)(ch) & SECUREC_CHAR_MASK)); - unsigned int tableValue = SECUREC_BRACKET_VALUE(((unsigned int)(int)(ch) & SECUREC_CHAR_MASK)); + unsigned int tableIndex = SECUREC_BRACKET_INDEX(((unsigned int)(int)ch & SECUREC_BRACKET_CHAR_MASK)); + unsigned int tableValue = SECUREC_BRACKET_VALUE(((unsigned int)(int)ch & SECUREC_BRACKET_CHAR_MASK)); /* Do not use |= optimize this code, it will cause compiling warning */ table[tableIndex] = (unsigned char)(table[tableIndex] | tableValue); } +SECUREC_INLINE void SecBracketSetBitRange(unsigned char *table, SecUnsignedChar startCh, SecUnsignedChar endCh) +{ + SecUnsignedChar expCh; + /* %[a-z] %[a-a] Format %[a-\xff] end is 0xFF, condition (expCh <= endChar) cause dead loop */ + for (expCh = startCh; expCh < endCh; ++expCh) { + SecBracketSetBit(table, expCh); + } + SecBracketSetBit(table, endCh); +} /* * Determine whether the expression can be satisfied */ SECUREC_INLINE int SecCanInputForBracket(int convChr, SecInt ch, const SecBracketTable *bracketTable) { - unsigned int tableIndex = SECUREC_BRACKET_INDEX(((unsigned int)(int)(ch) & SECUREC_CHAR_MASK)); - unsigned int tableValue = SECUREC_BRACKET_VALUE(((unsigned int)(int)(ch) & SECUREC_CHAR_MASK)); + unsigned int tableIndex = SECUREC_BRACKET_INDEX(((unsigned int)(int)ch & SECUREC_BRACKET_CHAR_MASK)); + unsigned int tableValue = SECUREC_BRACKET_VALUE(((unsigned int)(int)ch & SECUREC_BRACKET_CHAR_MASK)); #ifdef SECUREC_FOR_WCHAR - return (convChr == SECUREC_BRACE && bracketTable->table != NULL && - ((bracketTable->table[tableIndex] ^ bracketTable->mask) & tableValue)); + if (((unsigned int)(int)ch & (~(SECUREC_BRACKET_CHAR_MASK))) != 0) { + /* The value of the wide character exceeds the size of two bytes */ + return 0; + } + return (int)(convChr == SECUREC_BRACE && bracketTable->table != NULL && + ((bracketTable->table[tableIndex] ^ bracketTable->mask) & tableValue) != 0); #else - return (convChr == SECUREC_BRACE && ((bracketTable->table[tableIndex] ^ bracketTable->mask) & tableValue)); + return (int)(convChr == SECUREC_BRACE && + ((bracketTable->table[tableIndex] ^ bracketTable->mask) & tableValue) != 0); #endif } @@ -221,8 +273,8 @@ SECUREC_INLINE int SecCanInputForBracket(int convChr, SecInt ch, const SecBracke */ SECUREC_INLINE int SecCanInputString(int convChr, SecInt ch) { - return ((convChr) == SECUREC_CHAR('s') && - (!((ch) >= SECUREC_CHAR('\t') && (ch) <= SECUREC_CHAR('\r')) && (ch) != SECUREC_CHAR(' '))); + return (int)(convChr == 's' && + (!(ch >= SECUREC_CHAR('\t') && ch <= SECUREC_CHAR('\r')) && ch != SECUREC_CHAR(' '))); } /* @@ -230,14 +282,14 @@ SECUREC_INLINE int SecCanInputString(int convChr, SecInt ch) */ SECUREC_INLINE int SecCanInputCharacter(int convChr) { - return (convChr == SECUREC_CHAR('c')); + return (int)(convChr == 'c'); } /* * Determine if it is a 64-bit pointer function * Return 0 is not ,1 is 64bit pointer */ -SECUREC_INLINE int SecIs64BitPtr(size_t sizeOfVoidStar) +SECUREC_INLINE int SecNumberArgType(size_t sizeOfVoidStar) { /* Point size is 4 or 8 , Under the 64 bit system, the value not 0 */ /* To clear e778 */ @@ -297,13 +349,12 @@ SECUREC_INLINE int SecAssignFloatW(const SecFloatSpec *floatSpec, const SecScan mbsLen = wcstombs(tempFloatStr, floatSpec->floatStr, tempFloatStrLen - 1); SECUREC_END_MASK_MSVC_CRT_WARNING /* This condition must satisfy mbsLen is not -1 */ - if (mbsLen < tempFloatStrLen) { - tempFloatStr[mbsLen] = '\0'; - SecAssignFloat(tempFloatStr, spec->numberWidth, spec->argPtr); - } else { + if (mbsLen >= tempFloatStrLen) { SECUREC_FREE(tempFloatStr); return -1; } + tempFloatStr[mbsLen] = '\0'; + SecAssignFloat(tempFloatStr, spec->numberWidth, spec->argPtr); SECUREC_FREE(tempFloatStr); return 0; } @@ -317,7 +368,6 @@ SECUREC_INLINE void SecInitFloatSpec(SecFloatSpec *floatSpec) floatSpec->floatStr = floatSpec->buffer; floatSpec->allocatedFloatStr = NULL; floatSpec->floatStrTotalLen = sizeof(floatSpec->buffer) / sizeof(floatSpec->buffer[0]); - floatSpec->floatStr = floatSpec->buffer; floatSpec->floatStrUsedLen = 0; } @@ -327,7 +377,7 @@ SECUREC_INLINE void SecFreeFloatSpec(SecFloatSpec *floatSpec, int *doneCount) if (memset_s(floatSpec->buffer, sizeof(floatSpec->buffer), 0, sizeof(floatSpec->buffer)) != EOK) { *doneCount = 0; /* This code just to meet the coding requirements */ } - /* The pFloatStr can be alloced in SecUpdateFloatString function, clear and free it */ + /* The pFloatStr can be alloced in SecExtendFloatLen function, clear and free it */ if (floatSpec->allocatedFloatStr != NULL) { size_t bufferSize = floatSpec->floatStrTotalLen * sizeof(SecChar); if (memset_s(floatSpec->allocatedFloatStr, bufferSize, 0, bufferSize) != EOK) { @@ -343,9 +393,8 @@ SECUREC_INLINE void SecFreeFloatSpec(SecFloatSpec *floatSpec, int *doneCount) * Splice floating point string * Return 0 OK */ -SECUREC_INLINE int SecUpdateFloatString(SecChar ch, SecFloatSpec *floatSpec) +SECUREC_INLINE int SecExtendFloatLen(SecFloatSpec *floatSpec) { - floatSpec->floatStr[floatSpec->floatStrUsedLen++] = ch; if (floatSpec->floatStrUsedLen >= floatSpec->floatStrTotalLen) { /* Buffer size is len x sizeof(SecChar) */ size_t oriSize = floatSpec->floatStrTotalLen * sizeof(SecChar); @@ -353,7 +402,7 @@ SECUREC_INLINE int SecUpdateFloatString(SecChar ch, SecFloatSpec *floatSpec) size_t nextSize = (oriSize * 2) + sizeof(SecChar); /* Multiply 2 to extend buffer size */ /* Prevents integer overflow, the maximum length of SECUREC_MAX_WIDTH_LEN is enough */ - if (nextSize <= SECUREC_MAX_WIDTH_LEN) { + if (nextSize <= (size_t)SECUREC_MAX_WIDTH_LEN) { void *nextBuffer = (void *)SECUREC_MALLOC(nextSize); if (nextBuffer == NULL) { return -1; @@ -381,102 +430,140 @@ SECUREC_INLINE int SecUpdateFloatString(SecChar ch, SecFloatSpec *floatSpec) return 0; } - /* Do not use localeconv()->decimal_pointif onlay support '.' */ SECUREC_INLINE int SecIsFloatDecimal(SecChar ch) { - return ((ch) == SECUREC_CHAR('.')); + return (int)(ch == SECUREC_CHAR('.')); } -/* - * Scan value of exponent. - * Return 0 OK - */ -SECUREC_INLINE int SecInputFloatE(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec) +SECUREC_INLINE int SecInputFloatSign(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec) { + if (!SECUREC_FILED_WIDTH_ENOUGH(spec)) { + return 0; + } spec->ch = SecGetChar(stream, &(spec->charCount)); if (spec->ch == SECUREC_CHAR('+') || spec->ch == SECUREC_CHAR('-')) { - if (spec->ch == SECUREC_CHAR('-') && SecUpdateFloatString((SecChar)'-', floatSpec) != 0) { - return -1; - } - if (spec->width != 0) { - spec->ch = SecGetChar(stream, &(spec->charCount)); - --spec->width; + SECUREC_FILED_WIDTH_DEC(spec); /* Make sure the count after un get char is correct */ + if (spec->ch == SECUREC_CHAR('-')) { + floatSpec->floatStr[floatSpec->floatStrUsedLen] = SECUREC_CHAR('-'); + ++floatSpec->floatStrUsedLen; + if (SecExtendFloatLen(floatSpec) != 0) { + return -1; + } } + } else { + SecUnGetChar(spec->ch, stream, &(spec->charCount)); } + return 0; +} - while (SecIsDigit(spec->ch) && spec->width-- != 0) { - if (SecUpdateFloatString((SecChar)spec->ch, floatSpec) != 0) { +SECUREC_INLINE int SecInputFloatDigit(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec) +{ + /* Now get integral part */ + while (SECUREC_FILED_WIDTH_ENOUGH(spec)) { + spec->ch = SecGetChar(stream, &(spec->charCount)); + if (SecIsDigit(spec->ch) == 0) { + SecUnGetChar(spec->ch, stream, &(spec->charCount)); + return 0; + } + SECUREC_FILED_WIDTH_DEC(spec); /* Must be behind un get char, otherwise the logic is incorrect */ + spec->numberState = SECUREC_NUMBER_STATE_STARTED; + floatSpec->floatStr[floatSpec->floatStrUsedLen] = (SecChar)spec->ch; + ++floatSpec->floatStrUsedLen; + if (SecExtendFloatLen(floatSpec) != 0) { return -1; } - spec->ch = SecGetChar(stream, &(spec->charCount)); } return 0; } /* - * Scan %f. - * Return 0 OK - */ -SECUREC_INLINE int SecInputFloat(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec) +* Scan value of exponent. +* Return 0 OK +*/ +SECUREC_INLINE int SecInputFloatE(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec) { - int started = -1; - spec->ch = SecGetChar(stream, &(spec->charCount)); - - floatSpec->floatStrUsedLen = 0; - if (spec->ch == SECUREC_CHAR('-')) { - floatSpec->floatStr[floatSpec->floatStrUsedLen++] = SECUREC_CHAR('-'); - --spec->width; - spec->ch = SecGetChar(stream, &(spec->charCount)); - } else if (spec->ch == SECUREC_CHAR('+')) { - --spec->width; - spec->ch = SecGetChar(stream, &(spec->charCount)); + if (SecInputFloatSign(stream, spec, floatSpec) == -1) { + return -1; } - - if (spec->widthSet == 0) { /* Must care width */ - spec->width = -1; /* -1 is unlimited */ + if (SecInputFloatDigit(stream, spec, floatSpec) != 0) { + return -1; } + return 0; +} - /* Now get integral part */ - while (SecIsDigit(spec->ch) && spec->width-- != 0) { - started = 0; - /* The ch must be '0' - '9' */ - if (SecUpdateFloatString((SecChar)spec->ch, floatSpec) != 0) { - return -1; - } +SECUREC_INLINE int SecInputFloatFractional(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec) +{ + if (SECUREC_FILED_WIDTH_ENOUGH(spec)) { spec->ch = SecGetChar(stream, &(spec->charCount)); - } - - /* Now get fractional part */ - if (SecIsFloatDecimal((SecChar)spec->ch) && spec->width-- != 0) { + if (SecIsFloatDecimal((SecChar)spec->ch) == 0) { + SecUnGetChar(spec->ch, stream, &(spec->charCount)); + return 0; + } + SECUREC_FILED_WIDTH_DEC(spec); /* Must be behind un get char, otherwise the logic is incorrect */ /* Now check for decimal */ - if (SecUpdateFloatString((SecChar)spec->ch, floatSpec) != 0) { + floatSpec->floatStr[floatSpec->floatStrUsedLen] = (SecChar)spec->ch; + ++floatSpec->floatStrUsedLen; + if (SecExtendFloatLen(floatSpec) != 0) { return -1; } - spec->ch = SecGetChar(stream, &(spec->charCount)); - while (SecIsDigit(spec->ch) && spec->width-- != 0) { - started = 0; - if (SecUpdateFloatString((SecChar)spec->ch, floatSpec) != 0) { - return -1; - } - spec->ch = SecGetChar(stream, &(spec->charCount)); + if (SecInputFloatDigit(stream, spec, floatSpec) != 0) { + return -1; } } + return 0; +} +SECUREC_INLINE int SecInputFloatExponent(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec) +{ /* Now get exponent part */ - if (started == 0 && (spec->ch == SECUREC_CHAR('e') || spec->ch == SECUREC_CHAR('E')) && spec->width-- != 0) { - if (SecUpdateFloatString((SecChar)'e', floatSpec) != 0) { + if (spec->numberState == SECUREC_NUMBER_STATE_STARTED && SECUREC_FILED_WIDTH_ENOUGH(spec)) { + spec->ch = SecGetChar(stream, &(spec->charCount)); + if (spec->ch != SECUREC_CHAR('e') && spec->ch != SECUREC_CHAR('E')) { + SecUnGetChar(spec->ch, stream, &(spec->charCount)); + return 0; + } + SECUREC_FILED_WIDTH_DEC(spec); /* Must be behind un get char, otherwise the logic is incorrect */ + floatSpec->floatStr[floatSpec->floatStrUsedLen] = SECUREC_CHAR('e'); + ++floatSpec->floatStrUsedLen; + if (SecExtendFloatLen(floatSpec) != 0) { return -1; } if (SecInputFloatE(stream, spec, floatSpec) != 0) { return -1; } } - /* Un set the last character that is not a floating point number */ - SecUnGetChar(spec->ch, stream, &(spec->charCount)); + return 0; +} + +/* +* Scan %f. +* Return 0 OK +*/ +SECUREC_INLINE int SecInputFloat(SecFileStream *stream, SecScanSpec *spec, SecFloatSpec *floatSpec) +{ + floatSpec->floatStrUsedLen = 0; + + /* The following code sequence is strict */ + if (SecInputFloatSign(stream, spec, floatSpec) != 0) { + return -1; + } + if (SecInputFloatDigit(stream, spec, floatSpec) != 0) { + return -1; + } + if (SecInputFloatFractional(stream, spec, floatSpec) != 0) { + return -1; + } + if (SecInputFloatExponent(stream, spec, floatSpec) != 0) { + return -1; + } + /* Make sure have a string terminator, buffer is large enough */ floatSpec->floatStr[floatSpec->floatStrUsedLen] = SECUREC_CHAR('\0'); - return started; + if (spec->numberState == SECUREC_NUMBER_STATE_STARTED) { + return 0; + } + return -1; } #endif @@ -487,9 +574,9 @@ SECUREC_INLINE int SecIsLeadByte(SecInt ch) { unsigned int c = (unsigned int)ch; #if !(defined(_MSC_VER) || defined(_INC_WCTYPE)) - return (int)(c & 0x80); + return (int)(c & 0x80U); /* Use bitwise operation to check if the most significant bit is 1 */ #else - return (int)isleadbyte((int)(c & 0xff)); + return (int)isleadbyte((int)(c & 0xffU)); /* Use bitwise operations to limit character values to valid ranges */ #endif } #endif @@ -528,14 +615,14 @@ SECUREC_INLINE void SecDecodeScanQualifierL(const SecUnsignedChar **format, SecS { const SecUnsignedChar *fmt = *format; if (*(fmt + 1) == SECUREC_CHAR('l')) { - spec->isInt64Arg = 1; + spec->numberArgType = 1; spec->numberWidth = SECUREC_NUM_WIDTH_LONG_LONG; ++fmt; } else { spec->numberWidth = SECUREC_NUM_WIDTH_LONG; #if defined(SECUREC_ON_64BITS) && !(defined(SECUREC_COMPATIBLE_WIN_FORMAT)) /* On window 64 system sizeof long is 32bit */ - spec->isInt64Arg = 1; + spec->numberArgType = 1; #endif spec->isWCharOrLong = 1; } @@ -551,7 +638,7 @@ SECUREC_INLINE void SecDecodeScanQualifierI(const SecUnsignedChar **format, SecS const SecUnsignedChar *fmt = *format; if ((*(fmt + 1) == SECUREC_CHAR('6')) && (*(fmt + 2) == SECUREC_CHAR('4'))) { /* Offset 2 for I64 */ - spec->isInt64Arg = 1; + spec->numberArgType = 1; *format = *format + 2; /* Add 2 to skip I64 point to '4' next loop will inc */ } else if ((*(fmt + 1) == SECUREC_CHAR('3')) && (*(fmt + 2) == SECUREC_CHAR('2'))) { /* Offset 2 for I32 */ @@ -561,10 +648,10 @@ SECUREC_INLINE void SecDecodeScanQualifierI(const SecUnsignedChar **format, SecS (*(fmt + 1) == SECUREC_CHAR('o')) || (*(fmt + 1) == SECUREC_CHAR('x')) || (*(fmt + 1) == SECUREC_CHAR('X'))) { - spec->isInt64Arg = SecIs64BitPtr(sizeof(void *)); + spec->numberArgType = SecNumberArgType(sizeof(void *)); } else { /* For %I */ - spec->isInt64Arg = SecIs64BitPtr(sizeof(void *)); + spec->numberArgType = SecNumberArgType(sizeof(void *)); *finishFlag = 1; } } @@ -572,7 +659,7 @@ SECUREC_INLINE void SecDecodeScanQualifierI(const SecUnsignedChar **format, SecS SECUREC_INLINE int SecDecodeScanWidth(const SecUnsignedChar **format, SecScanSpec *spec) { const SecUnsignedChar *fmt = *format; - while (SecIsDigit((SecInt)(int)(*fmt))) { + while (SecIsDigit((SecInt)(int)(*fmt)) != 0) { spec->widthSet = 1; if (SECUREC_MUL_TEN_ADD_BEYOND_MAX(spec->width)) { return -1; @@ -590,22 +677,23 @@ SECUREC_INLINE int SecDecodeScanWidth(const SecUnsignedChar **format, SecScanSpe SECUREC_INLINE void SecSetDefaultScanSpec(SecScanSpec *spec) { /* The ch and charCount member variables cannot be initialized here */ + spec->argPtr = NULL; + spec->arrayWidth = 0; spec->number64 = 0; spec->number = 0; spec->numberWidth = SECUREC_NUM_WIDTH_INT; /* 0 = SHORT, 1 = int, > 1 long or L_DOUBLE */ - spec->isInt64Arg = 0; /* 1 for 64-bit integer, 0 otherwise */ - spec->negative = 0; -#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX))) - spec->beyondMax = 0; -#endif - spec->argPtr = NULL; - spec->arrayWidth = 0; + spec->numberArgType = 0; /* 1 for 64-bit integer, 0 otherwise */ spec->width = 0; spec->widthSet = 0; spec->convChr = 0; spec->oriConvChr = 0; spec->isWCharOrLong = 0; spec->suppress = 0; +#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX))) + spec->beyondMax = 0; +#endif + spec->negative = 0; + spec->numberState = SECUREC_NUMBER_STATE_DEFAULT; } /* @@ -614,7 +702,7 @@ SECUREC_INLINE void SecSetDefaultScanSpec(SecScanSpec *spec) */ SECUREC_INLINE void SecDecodeScanQualifier(const SecUnsignedChar **format, SecScanSpec *spec, int *finishFlag) { - switch ((int)(unsigned char)(**(format))) { + switch (**format) { case SECUREC_CHAR('F'): /* fall-through */ /* FALLTHRU */ case SECUREC_CHAR('N'): break; @@ -625,7 +713,7 @@ SECUREC_INLINE void SecDecodeScanQualifier(const SecUnsignedChar **format, SecS #ifdef SECUREC_COMPATIBLE_LINUX_FORMAT case SECUREC_CHAR('j'): spec->numberWidth = SECUREC_NUM_WIDTH_LONG_LONG; /* For intmax_t or uintmax_t */ - spec->isInt64Arg = 1; + spec->numberArgType = 1; break; case SECUREC_CHAR('t'): /* fall-through */ /* FALLTHRU */ #endif @@ -635,7 +723,7 @@ SECUREC_INLINE void SecDecodeScanQualifier(const SecUnsignedChar **format, SecS case SECUREC_CHAR('z'): #ifdef SECUREC_ON_64BITS spec->numberWidth = SECUREC_NUM_WIDTH_LONG_LONG; - spec->isInt64Arg = 1; + spec->numberArgType = 1; #else spec->numberWidth = SECUREC_NUM_WIDTH_LONG; #endif @@ -643,7 +731,7 @@ SECUREC_INLINE void SecDecodeScanQualifier(const SecUnsignedChar **format, SecS case SECUREC_CHAR('L'): /* For long double */ /* fall-through */ /* FALLTHRU */ case SECUREC_CHAR('q'): spec->numberWidth = SECUREC_NUM_WIDTH_LONG_LONG; - spec->isInt64Arg = 1; + spec->numberArgType = 1; break; case SECUREC_CHAR('l'): SecDecodeScanQualifierL(format, spec); @@ -661,7 +749,6 @@ SECUREC_INLINE void SecDecodeScanQualifier(const SecUnsignedChar **format, SecS *finishFlag = 1; break; } - } /* * Decode width and qualifier in format @@ -690,8 +777,8 @@ SECUREC_INLINE int SecDecodeClearFormat(const SecUnsignedChar *format, int *conv { const SecUnsignedChar *fmt = format; /* To lowercase */ - int ch = (unsigned char)(*fmt) | (SECUREC_CHAR('a') - SECUREC_CHAR('A')); - if (!(ch == SECUREC_CHAR('c') || ch == SECUREC_CHAR('s') || ch == SECUREC_BRACE)) { + int ch = SECUREC_TO_LOWERCASE(*fmt); + if (!(ch == 'c' || ch == 's' || ch == SECUREC_BRACE)) { return -1; /* First argument is not a string type */ } if (ch == SECUREC_BRACE) { @@ -733,6 +820,26 @@ SECUREC_INLINE void SecAddEndingZero(void *ptr, const SecScanSpec *spec) } } +SECUREC_INLINE void SecDecodeClearArg(SecScanSpec *spec, va_list argList) +{ + va_list argListSave; /* Backup for argList value, this variable don't need initialized */ + (void)memset(&argListSave, 0, sizeof(va_list)); /* To clear e530 argListSave not initialized */ +#if defined(va_copy) + va_copy(argListSave, argList); +#elif defined(__va_copy) /* For vxworks */ + __va_copy(argListSave, argList); +#else + argListSave = argList; +#endif + spec->argPtr = (void *)va_arg(argListSave, void *); + /* Get the next argument, size of the array in characters */ + /* Use 0xffffffffUL mask to Support pass integer as array length */ + spec->arrayWidth = ((size_t)(va_arg(argListSave, size_t))) & 0xffffffffUL; + va_end(argListSave); + /* To clear e438 last value assigned not used , the compiler will optimize this code */ + (void)argListSave; +} + #ifdef SECUREC_FOR_WCHAR /* * Clean up the first %s %c buffer to zero for wchar version @@ -745,8 +852,6 @@ void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argL void SecClearDestBuf(const char *buffer, const char *format, va_list argList) #endif { - - va_list argListSave; /* Backup for argList value, this variable don't need initialized */ SecScanSpec spec; int convChr = 0; const SecUnsignedChar *fmt = (const SecUnsignedChar *)format; @@ -769,43 +874,30 @@ void SecClearDestBuf(const char *buffer, const char *format, va_list argList) /* Update wchar flag for %S %C */ SecUpdateWcharFlagByType(*fmt, &spec); + if (spec.suppress != 0) { + return; + } - if (spec.suppress != 0 || SecDecodeClearFormat(fmt, &convChr) != 0) { + if (SecDecodeClearFormat(fmt, &convChr) != 0) { return; } - if (buffer != NULL && *buffer != SECUREC_CHAR('\0') && convChr != SECUREC_CHAR('s')) { + if (buffer != NULL && *buffer != SECUREC_CHAR('\0') && convChr != 's') { /* * When buffer not empty just clear %s. * Example call sscanf by argment of (" \n", "%s", s, sizeof(s)) */ return; } - (void)memset(&argListSave, 0, sizeof(va_list)); /* To clear e530 argListSave not initialized */ -#if defined(va_copy) - va_copy(argListSave, argList); -#elif defined(__va_copy) /* For vxworks */ - __va_copy(argListSave, argList); -#else - argListSave = argList; -#endif - do { - void *argPtr = (void *)va_arg(argListSave, void *); - /* Get the next argument - size of the array in characters */ - size_t arrayWidth = ((size_t)(va_arg(argListSave, size_t))) & 0xFFFFFFFFUL; - va_end(argListSave); - /* To clear e438 last value assigned not used , the compiler will optimize this code */ - (void)argListSave; - /* There is no need to judge the upper limit */ - if (arrayWidth == 0 || argPtr == NULL) { - return; - } - /* Clear one char */ - SecAddEndingZero(argPtr, &spec); - } SECUREC_WHILE_ZERO; + SecDecodeClearArg(&spec, argList); + /* There is no need to judge the upper limit */ + if (spec.arrayWidth == 0 || spec.argPtr == NULL) { + return; + } + /* Clear one char */ + SecAddEndingZero(spec.argPtr, &spec); return; - } /* @@ -814,7 +906,7 @@ void SecClearDestBuf(const char *buffer, const char *format, va_list argList) SECUREC_INLINE void SecAssignNumber(const SecScanSpec *spec) { void *argPtr = spec->argPtr; - if (spec->isInt64Arg != 0) { + if (spec->numberArgType != 0) { #if defined(SECUREC_VXWORKS_PLATFORM) #if defined(SECUREC_VXWORKS_PLATFORM_COMP) *(SecInt64 UNALIGNED *)argPtr = (SecInt64)(spec->number64); @@ -848,7 +940,7 @@ SECUREC_INLINE void SecAssignNumber(const SecScanSpec *spec) */ SECUREC_INLINE int SecIsLongBitEqual(int bitNum) { - return (unsigned int)bitNum == SECUREC_LONG_BIT_NUM; + return (int)((unsigned int)bitNum == SECUREC_LONG_BIT_NUM); } #endif @@ -870,7 +962,7 @@ static void SecDecodeNumberDecimal(SecScanSpec *spec) #if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX))) unsigned long decimalEdge = SECUREC_MAX_32BITS_VALUE_DIV_TEN; #ifdef SECUREC_ON_64BITS - if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH)) { + if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) { decimalEdge = (unsigned long)SECUREC_MAX_64BITS_VALUE_DIV_TEN; } #endif @@ -881,6 +973,7 @@ static void SecDecodeNumberDecimal(SecScanSpec *spec) spec->number = SECUREC_MUL_TEN(spec->number); #if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX))) if (spec->number == SECUREC_MUL_TEN(decimalEdge)) { + /* This code is specially converted to unsigned long type for compatibility */ SecUnsignedInt64 number64As = (unsigned long)SECUREC_MAX_64BITS_VALUE - spec->number; if (number64As < (SecUnsignedInt64)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0'))) { spec->beyondMax = 1; @@ -888,10 +981,8 @@ static void SecDecodeNumberDecimal(SecScanSpec *spec) } #endif spec->number += (unsigned long)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0')); - } - /* * Parse Hex character to integer for 32bit . */ @@ -906,7 +997,6 @@ static void SecDecodeNumberHex(SecScanSpec *spec) spec->number += (unsigned long)(unsigned int)SecHexValueOfChar(spec->ch); } - /* * Parse Octal character to integer for 32bit . */ @@ -921,59 +1011,59 @@ static void SecDecodeNumberOctal(SecScanSpec *spec) spec->number += (unsigned long)((SecUnsignedInt)spec->ch - SECUREC_CHAR('0')); } - #if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX))) /* Compatible with integer negative values other than int */ SECUREC_INLINE void SecFinishNumberNegativeOther(SecScanSpec *spec) { - if (spec->oriConvChr == SECUREC_CHAR('d') || spec->oriConvChr == SECUREC_CHAR('i')) { + if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) { if (spec->number > SECUREC_MIN_LONG_NEG_VALUE) { spec->number = SECUREC_MIN_LONG_NEG_VALUE; } else { - spec->number = (unsigned long)(-(long)spec->number); + spec->number = (unsigned long)(0U - spec->number); /* Wrap with unsigned long numbers */ } if (spec->beyondMax != 0) { if (spec->numberWidth < SECUREC_NUM_WIDTH_INT) { spec->number = 0; - } else if (spec->numberWidth == SECUREC_NUM_WIDTH_LONG) { + } + if (spec->numberWidth == SECUREC_NUM_WIDTH_LONG) { spec->number = SECUREC_MIN_LONG_NEG_VALUE; } } } else { /* For o, u, x, X, p */ - spec->number = (unsigned long)(-(long)spec->number); + spec->number = (unsigned long)(0U - spec->number); /* Wrap with unsigned long numbers */ if (spec->beyondMax != 0) { - spec->number |= (unsigned long)SECUREC_MAX_64BITS_VALUE; + spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE; } } } /* Compatible processing of integer negative numbers */ SECUREC_INLINE void SecFinishNumberNegativeInt(SecScanSpec *spec) { - if (spec->oriConvChr == SECUREC_CHAR('d') || spec->oriConvChr == SECUREC_CHAR('i')) { + if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) { #ifdef SECUREC_ON_64BITS - if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH)) { + if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) { if ((spec->number > SECUREC_MIN_64BITS_NEG_VALUE)) { spec->number = 0; } else { - spec->number = (unsigned int)(-(int)spec->number); + spec->number = (unsigned int)(0U - (unsigned int)spec->number); /* Wrap with unsigned int numbers */ } } #else - if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH)) { + if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH) != 0) { if ((spec->number > SECUREC_MIN_32BITS_NEG_VALUE)) { spec->number = SECUREC_MIN_32BITS_NEG_VALUE; } else { - spec->number = (unsigned int)(-(int)spec->number); + spec->number = (unsigned int)(0U - (unsigned int)spec->number); /* Wrap with unsigned int numbers */ } } #endif if (spec->beyondMax != 0) { #ifdef SECUREC_ON_64BITS - if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH)) { + if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) { spec->number = 0; } #else - if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH)) { + if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH) != 0) { spec->number = SECUREC_MIN_32BITS_NEG_VALUE; } #endif @@ -983,13 +1073,13 @@ SECUREC_INLINE void SecFinishNumberNegativeInt(SecScanSpec *spec) if (spec->number > SECUREC_MAX_32BITS_VALUE_INC) { spec->number = SECUREC_MAX_32BITS_VALUE; } else { - spec->number = (unsigned int)(-(int)spec->number); + spec->number = (unsigned int)(0U - (unsigned int)spec->number); /* Wrap with unsigned int numbers */ } #else - spec->number = (unsigned int)(-(int)spec->number); + spec->number = (unsigned int)(0U - (unsigned int)spec->number); /* Wrap with unsigned int numbers */ #endif if (spec->beyondMax != 0) { - spec->number |= (unsigned long)SECUREC_MAX_64BITS_VALUE; + spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE; } } } @@ -997,19 +1087,19 @@ SECUREC_INLINE void SecFinishNumberNegativeInt(SecScanSpec *spec) /* Compatible with integer positive values other than int */ SECUREC_INLINE void SecFinishNumberPositiveOther(SecScanSpec *spec) { - if (spec->oriConvChr == SECUREC_CHAR('d') || spec->oriConvChr == SECUREC_CHAR('i')) { + if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) { if (spec->number > SECUREC_MAX_LONG_POS_VALUE) { spec->number = SECUREC_MAX_LONG_POS_VALUE; } if ((spec->beyondMax != 0 && spec->numberWidth < SECUREC_NUM_WIDTH_INT)) { - spec->number |= (unsigned long)SECUREC_MAX_64BITS_VALUE; + spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE; } if (spec->beyondMax != 0 && spec->numberWidth == SECUREC_NUM_WIDTH_LONG) { spec->number = SECUREC_MAX_LONG_POS_VALUE; } } else { if (spec->beyondMax != 0) { - spec->number |= (unsigned long)SECUREC_MAX_64BITS_VALUE; + spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE; } } } @@ -1017,23 +1107,23 @@ SECUREC_INLINE void SecFinishNumberPositiveOther(SecScanSpec *spec) /* Compatible processing of integer positive numbers */ SECUREC_INLINE void SecFinishNumberPositiveInt(SecScanSpec *spec) { - if (spec->oriConvChr == SECUREC_CHAR('d') || spec->oriConvChr == SECUREC_CHAR('i')) { + if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) { #ifdef SECUREC_ON_64BITS - if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH)) { + if (SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) { if (spec->number > SECUREC_MAX_64BITS_POS_VALUE) { - spec->number |= (unsigned long)SECUREC_MAX_64BITS_VALUE; + spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE; } } - if (spec->beyondMax != 0 && SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH)) { - spec->number |= (unsigned long)SECUREC_MAX_64BITS_VALUE; + if (spec->beyondMax != 0 && SecIsLongBitEqual(SECUREC_LP64_BIT_WIDTH) != 0) { + spec->number = (unsigned long)SECUREC_MAX_64BITS_VALUE; } #else - if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH)) { + if (SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH) != 0) { if (spec->number > SECUREC_MAX_32BITS_POS_VALUE) { spec->number = SECUREC_MAX_32BITS_POS_VALUE; } } - if (spec->beyondMax != 0 && SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH)) { + if (spec->beyondMax != 0 && SecIsLongBitEqual(SECUREC_LP32_BIT_WIDTH) != 0) { spec->number = SECUREC_MAX_32BITS_POS_VALUE; } #endif @@ -1080,7 +1170,6 @@ static void SecDecodeNumber64Hex(SecScanSpec *spec) #endif spec->number64 = SECUREC_MUL_SIXTEEN(spec->number64); spec->number64 += (SecUnsignedInt64)(unsigned int)SecHexValueOfChar(spec->ch); - } /* @@ -1098,43 +1187,45 @@ static void SecDecodeNumber64Octal(SecScanSpec *spec) } #define SECUREC_DECODE_NUMBER_FUNC_NUM 2 -/* Function name cannot add address symbol, causing 546 alarm */ -static void (*g_secDecodeNumberHex[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = \ - { SecDecodeNumberHex, SecDecodeNumber64Hex }; -static void (*g_secDecodeNumberOctal[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = \ - { SecDecodeNumberOctal, SecDecodeNumber64Octal }; -static void (*g_secDecodeNumberDecimal[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = \ - { SecDecodeNumberDecimal, SecDecodeNumber64Decimal }; /* * Parse 64-bit integer formatted input, return 0 when ch is a number. */ SECUREC_INLINE int SecDecodeNumber(SecScanSpec *spec) { - if (spec->convChr == SECUREC_CHAR('x') || spec->convChr == SECUREC_CHAR('p')) { - if (SecIsXdigit(spec->ch)) { - (*g_secDecodeNumberHex[spec->isInt64Arg])(spec); + /* Function name cannot add address symbol, causing 546 alarm */ + static void (*secDecodeNumberHex[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = { + SecDecodeNumberHex, SecDecodeNumber64Hex + }; + static void (*secDecodeNumberOctal[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = { + SecDecodeNumberOctal, SecDecodeNumber64Octal + }; + static void (*secDecodeNumberDecimal[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = { + SecDecodeNumberDecimal, SecDecodeNumber64Decimal + }; + if (spec->convChr == 'x' || spec->convChr == 'p') { + if (SecIsXdigit(spec->ch) != 0) { + (*secDecodeNumberHex[spec->numberArgType])(spec); } else { return -1; } return 0; } - if (!(SecIsDigit(spec->ch))) { + if (SecIsDigit(spec->ch) == 0) { return -1; } - if (spec->convChr == SECUREC_CHAR('o')) { - if (spec->ch < SECUREC_CHAR('8')) { - (*g_secDecodeNumberOctal[spec->isInt64Arg])(spec); + if (spec->convChr == 'o') { + if (spec->ch < SECUREC_CHAR('8')) { /* Octal maximum limit '8' */ + (*secDecodeNumberOctal[spec->numberArgType])(spec); } else { return -1; } } else { /* The convChr is 'd' */ - (*g_secDecodeNumberDecimal[spec->isInt64Arg])(spec); + (*secDecodeNumberDecimal[spec->numberArgType])(spec); } return 0; } - /* * Complete the final 32-bit integer formatted input */ @@ -1157,11 +1248,11 @@ static void SecFinishNumber(SecScanSpec *spec) #else if (spec->negative != 0) { #if defined(__hpux) - if (spec->oriConvChr != SECUREC_CHAR('p')) { - spec->number = (unsigned long)(-(long)spec->number); + if (spec->oriConvChr != 'p') { + spec->number = (unsigned long)(0U - spec->number); /* Wrap with unsigned long numbers */ } #else - spec->number = (unsigned long)(-(long)spec->number); + spec->number = (unsigned long)(0U - spec->number); /* Wrap with unsigned long numbers */ #endif } #endif @@ -1175,23 +1266,23 @@ static void SecFinishNumber64(SecScanSpec *spec) { #if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && !(defined(SECUREC_ON_UNIX))) if (spec->negative != 0) { - if (spec->oriConvChr == SECUREC_CHAR('d') || spec->oriConvChr == SECUREC_CHAR('i')) { + if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) { if (spec->number64 > SECUREC_MIN_64BITS_NEG_VALUE) { spec->number64 = SECUREC_MIN_64BITS_NEG_VALUE; } else { - spec->number64 = (SecUnsignedInt64)(-(SecInt64)spec->number64); + spec->number64 = (SecUnsignedInt64)(0U - spec->number64); /* Wrap with unsigned int64 numbers */ } if (spec->beyondMax != 0) { spec->number64 = SECUREC_MIN_64BITS_NEG_VALUE; } } else { /* For o, u, x, X, p */ - spec->number64 = (SecUnsignedInt64)(-(SecInt64)spec->number64); + spec->number64 = (SecUnsignedInt64)(0U - spec->number64); /* Wrap with unsigned int64 numbers */ if (spec->beyondMax != 0) { spec->number64 = SECUREC_MAX_64BITS_VALUE; } } } else { - if (spec->oriConvChr == SECUREC_CHAR('d') || spec->oriConvChr == SECUREC_CHAR('i')) { + if (SECUREC_CONVERT_IS_SIGNED(spec->oriConvChr)) { if (spec->number64 > SECUREC_MAX_64BITS_POS_VALUE) { spec->number64 = SECUREC_MAX_64BITS_POS_VALUE; } @@ -1207,18 +1298,16 @@ static void SecFinishNumber64(SecScanSpec *spec) #else if (spec->negative != 0) { #if defined(__hpux) - if (spec->oriConvChr != SECUREC_CHAR('p')) { - spec->number64 = (SecUnsignedInt64)(-(SecInt64)spec->number64); + if (spec->oriConvChr != 'p') { + spec->number64 = (SecUnsignedInt64)(0U - spec->number64); /* Wrap with unsigned int64 numbers */ } #else - spec->number64 = (SecUnsignedInt64)(-(SecInt64)spec->number64); + spec->number64 = (SecUnsignedInt64)(0U - spec->number64); /* Wrap with unsigned int64 numbers */ #endif } #endif return; } -static void (*g_secFinishNumber[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = \ - { SecFinishNumber, SecFinishNumber64 }; #if SECUREC_ENABLE_SCANF_FILE @@ -1227,44 +1316,50 @@ static void (*g_secFinishNumber[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *sp */ SECUREC_INLINE void SecSeekStream(SecFileStream *stream) { - if ((stream->count <= 0) && feof(stream->pf)) { - /* File pointer at the end of file, don't need to seek back */ - stream->base[0] = '\0'; - return; + if (stream->count == 0) { + if (feof(stream->pf) != 0) { + /* File pointer at the end of file, don't need to seek back */ + stream->base[0] = '\0'; + return; + } } - /* LSD seek to original position, bug fix 2014 1 21 */ - if (fseek(stream->pf, stream->oriFilePos, SEEK_SET)) { + /* Seek to original position, for file read, but nothing to input */ + if (fseek(stream->pf, stream->oriFilePos, SEEK_SET) != 0) { /* Seek failed, ignore it */ stream->oriFilePos = 0; return; } - if (stream->fileRealRead > 0) { /* LSD bug fix. when file reach to EOF, don't seek back */ + if (stream->fileRealRead > 0) { /* Do not seek without input data */ #if defined(SECUREC_COMPATIBLE_WIN_FORMAT) - int loops; + size_t residue = stream->fileRealRead % SECUREC_BUFFERED_BLOK_SIZE; + size_t loops; for (loops = 0; loops < (stream->fileRealRead / SECUREC_BUFFERED_BLOK_SIZE); ++loops) { - if (fread(stream->base, (size_t)1, (size_t)SECUREC_BUFFERED_BLOK_SIZE, - stream->pf) != SECUREC_BUFFERED_BLOK_SIZE) { + if (fread(stream->base, (size_t)SECUREC_BUFFERED_BLOK_SIZE, (size_t)1, stream->pf) != (size_t)1) { break; } } - if ((stream->fileRealRead % SECUREC_BUFFERED_BLOK_SIZE) != 0) { - size_t len = fread(stream->base, (size_t)((unsigned int)stream->fileRealRead % SECUREC_BUFFERED_BLOK_SIZE), - (size_t)1, stream->pf); - if ((len == 1 || len == 0) && (ftell(stream->pf) < stream->oriFilePos + stream->fileRealRead)) { - (void)fseek(stream->pf, stream->oriFilePos + stream->fileRealRead, SEEK_SET); + if (residue != 0) { + long curFilePos; + if (fread(stream->base, residue, (size_t)1, stream->pf) != (size_t)1) { + return; + } + curFilePos = ftell(stream->pf); + if (curFilePos < stream->oriFilePos || + (size_t)(unsigned long)(curFilePos - stream->oriFilePos) < stream->fileRealRead) { + /* Try to remedy the problem */ + (void)fseek(stream->pf, (long)stream->fileRealRead, SEEK_CUR); } } - #else - /* On linux like system */ - if (fseek(stream->pf, stream->oriFilePos + stream->fileRealRead, SEEK_SET)) { + /* Seek from oriFilePos. Regardless of the integer sign problem, call scanf will not read very large data */ + if (fseek(stream->pf, (long)stream->fileRealRead, SEEK_CUR) != 0) { /* Seek failed, ignore it */ stream->oriFilePos = 0; + return; } #endif } - return; } @@ -1273,7 +1368,7 @@ SECUREC_INLINE void SecSeekStream(SecFileStream *stream) */ SECUREC_INLINE void SecAdjustStream(SecFileStream *stream) { - if (stream != NULL && (stream->flag & SECUREC_FILE_STREAM_FLAG) && stream->base != NULL) { + if (stream != NULL && (stream->flag & SECUREC_FILE_STREAM_FLAG) != 0 && stream->base != NULL) { SecSeekStream(stream); SECUREC_FREE(stream->base); stream->base = NULL; @@ -1285,7 +1380,7 @@ SECUREC_INLINE void SecAdjustStream(SecFileStream *stream) SECUREC_INLINE void SecSkipSpaceFormat(const SecUnsignedChar **format) { const SecUnsignedChar *fmt = *format; - while (SecIsSpace((SecInt)(int)(*fmt))) { + while (SecIsSpace((SecInt)(int)(*fmt)) != 0) { ++fmt; } *format = fmt; @@ -1295,51 +1390,49 @@ SECUREC_INLINE void SecSkipSpaceFormat(const SecUnsignedChar **format) /* * Handling multi-character characters */ -SECUREC_INLINE int SecDecodeLeadByte(SecScanSpec *spec, - const SecUnsignedChar **format, SecFileStream *stream, int *counter) +SECUREC_INLINE int SecDecodeLeadByte(SecScanSpec *spec, const SecUnsignedChar **format, SecFileStream *stream) { #if SECUREC_HAVE_MBTOWC const SecUnsignedChar *fmt = *format; int ch1 = (int)spec->ch; - int ch2 = SecGetChar(stream, counter); + int ch2 = SecGetChar(stream, &(spec->charCount)); spec->ch = (SecInt)ch2; if (*fmt == SECUREC_CHAR('\0') || (int)(*fmt) != ch2) { /* LSD in console mode, ungetc twice may cause problem */ - SecUnGetChar(ch2, stream, counter); - SecUnGetChar(ch1, stream, counter); + SecUnGetChar(ch2, stream, &(spec->charCount)); + SecUnGetChar(ch1, stream, &(spec->charCount)); return -1; } ++fmt; - if (MB_CUR_MAX >= SECUREC_UTF8_BOM_HEADER_SIZE && + if ((unsigned int)MB_CUR_MAX >= SECUREC_UTF8_BOM_HEADER_SIZE && (((unsigned char)ch1 & SECUREC_UTF8_LEAD_1ST) == SECUREC_UTF8_LEAD_1ST) && (((unsigned char)ch2 & SECUREC_UTF8_LEAD_2ND) == SECUREC_UTF8_LEAD_2ND)) { /* This char is very likely to be a UTF-8 char */ wchar_t tempWChar; char temp[SECUREC_MULTI_BYTE_MAX_LEN]; - int ch3 = (int)SecGetChar(stream, counter); + int ch3 = (int)SecGetChar(stream, &(spec->charCount)); spec->ch = (SecInt)ch3; + if (*fmt == SECUREC_CHAR('\0') || (int)(*fmt) != ch3) { + SecUnGetChar(ch3, stream, &(spec->charCount)); + return -1; + } temp[0] = (char)ch1; temp[1] = (char)ch2; /* 1 index of second character */ temp[2] = (char)ch3; /* 2 index of third character */ temp[3] = '\0'; /* 3 of string terminator position */ - if (mbtowc(&tempWChar, temp, sizeof(temp)) > 0) { /* Succeed */ - if (*fmt == SECUREC_CHAR('\0') || (int)(*fmt) != ch3) { - SecUnGetChar(ch3, stream, counter); - return -1; - } ++fmt; - *counter = *counter - 1; + --spec->charCount; } else { - SecUnGetChar(ch3, stream, counter); + SecUnGetChar(ch3, stream, &(spec->charCount)); } } - *counter = *counter - 1; /* Only count as one character read */ + --spec->charCount; /* Only count as one character read */ *format = fmt; return 0; #else - SecUnGetChar(spec->ch, stream, counter); + SecUnGetChar(spec->ch, stream, &(spec->charCount)); (void)format; /* To clear e438 last value assigned not used , the compiler will optimize this code */ return -1; #endif @@ -1353,7 +1446,6 @@ SECUREC_INLINE int SecSetupBracketTable(const SecUnsignedChar **format, SecBrack { const SecUnsignedChar *fmt = *format; SecUnsignedChar prevChar = 0; - SecUnsignedChar last = 0; #if !(defined(SECUREC_COMPATIBLE_WIN_FORMAT)) if (*fmt == SECUREC_CHAR('{')) { return -1; @@ -1361,10 +1453,10 @@ SECUREC_INLINE int SecSetupBracketTable(const SecUnsignedChar **format, SecBrack #endif /* For building "table" data */ ++fmt; /* Skip [ */ - bracketTable->mask = 0; + bracketTable->mask = 0; /* Set all bits to 0 */ if (*fmt == SECUREC_CHAR('^')) { ++fmt; - bracketTable->mask = (unsigned char)0xff; + bracketTable->mask = (unsigned char)0xffU; /* Use 0xffU to set all bits to 1 */ } if (*fmt == SECUREC_CHAR(']')) { prevChar = SECUREC_CHAR(']'); @@ -1372,32 +1464,28 @@ SECUREC_INLINE int SecSetupBracketTable(const SecUnsignedChar **format, SecBrack SecBracketSetBit(bracketTable->table, SECUREC_CHAR(']')); } while (*fmt != SECUREC_CHAR('\0') && *fmt != SECUREC_CHAR(']')) { - SecUnsignedChar expCh = *(fmt++); + SecUnsignedChar expCh = *fmt; + ++fmt; if (expCh != SECUREC_CHAR('-') || prevChar == 0 || *fmt == SECUREC_CHAR(']')) { /* Normal character */ prevChar = expCh; SecBracketSetBit(bracketTable->table, expCh); } else { /* For %[a-z] */ - expCh = *(fmt++); /* Get end of range */ - if (prevChar < expCh) { /* %[a-z] */ - last = expCh; + expCh = *fmt; /* Get end of range */ + ++fmt; + if (prevChar <= expCh) { /* %[a-z] %[a-a] */ + SecBracketSetBitRange(bracketTable->table, prevChar, expCh); } else { - prevChar = expCh; -#if defined(SECUREC_COMPATIBLE_WIN_FORMAT) /* For %[z-a] */ - last = prevChar; +#if defined(SECUREC_COMPATIBLE_WIN_FORMAT) + /* Swap start and end characters */ + SecBracketSetBitRange(bracketTable->table, expCh, prevChar); #else SecBracketSetBit(bracketTable->table, SECUREC_CHAR('-')); SecBracketSetBit(bracketTable->table, expCh); - continue; #endif } - /* Format %[a-\xff] last is 0xFF, condition (rnch <= last) cause dead loop */ - for (expCh = prevChar; expCh < last; ++expCh) { - SecBracketSetBit(bracketTable->table, expCh); - } - SecBracketSetBit(bracketTable->table, last); prevChar = 0; } } @@ -1450,7 +1538,7 @@ SECUREC_INLINE wchar_t SecConvertInputCharToWchar(SecScanSpec *spec, SecFileStre temp[0] = (char)spec->ch; temp[1] = '\0'; #if defined(SECUREC_COMPATIBLE_WIN_FORMAT) - if (SecIsLeadByte(spec->ch)) { + if (SecIsLeadByte(spec->ch) != 0) { spec->ch = SecGetChar(stream, &(spec->charCount)); temp[1] = (char)spec->ch; temp[2] = '\0'; /* 2 of string terminator position */ @@ -1460,13 +1548,14 @@ SECUREC_INLINE wchar_t SecConvertInputCharToWchar(SecScanSpec *spec, SecFileStre tempWChar = L'?'; } #else - if (SecIsLeadByte(spec->ch)) { + if (SecIsLeadByte(spec->ch) != 0) { int convRes = 0; int di = 1; /* On Linux like system, the string is encoded in UTF-8 */ while (convRes <= 0 && di < (int)MB_CUR_MAX && di < SECUREC_MULTI_BYTE_MAX_LEN) { spec->ch = SecGetChar(stream, &(spec->charCount)); - temp[di++] = (char)spec->ch; + temp[di] = (char)spec->ch; + ++di; temp[di] = '\0'; convRes = mbtowc(&tempWChar, temp, sizeof(temp)); } @@ -1488,7 +1577,6 @@ SECUREC_INLINE wchar_t SecConvertInputCharToWchar(SecScanSpec *spec, SecFileStre } #endif /* SECUREC_HAVE_WCHART */ - SECUREC_INLINE int SecInputForChar(SecScanSpec *spec, SecFileStream *stream) { void *endPtr = spec->argPtr; @@ -1517,26 +1605,25 @@ SECUREC_INLINE int SecInputForChar(SecScanSpec *spec, SecFileStream *stream) */ SECUREC_INLINE int SecInputNumberDigital(SecFileStream *stream, SecScanSpec *spec) { - int loopFlag = 0; - int started = -1; - while (loopFlag == 0) { + static void (*secFinishNumber[SECUREC_DECODE_NUMBER_FUNC_NUM])(SecScanSpec *spec) = { + SecFinishNumber, SecFinishNumber64 + }; + while (SECUREC_FILED_WIDTH_ENOUGH(spec)) { + spec->ch = SecGetChar(stream, &(spec->charCount)); /* Decode ch to number */ - loopFlag = SecDecodeNumber(spec); - if (loopFlag == 0) { - started = 0; - if (spec->widthSet != 0 && --spec->width == 0) { - loopFlag = 1; - } else { - spec->ch = SecGetChar(stream, &(spec->charCount)); - } - } else { + if (SecDecodeNumber(spec) != 0) { SecUnGetChar(spec->ch, stream, &(spec->charCount)); + break; } + SECUREC_FILED_WIDTH_DEC(spec); /* Must be behind un get char, otherwise the logic is incorrect */ + spec->numberState = SECUREC_NUMBER_STATE_STARTED; } /* Handling integer negative numbers and beyond max */ - (*g_secFinishNumber[spec->isInt64Arg])(spec); - return started; - + (*secFinishNumber[spec->numberArgType])(spec); + if (spec->numberState == SECUREC_NUMBER_STATE_STARTED) { + return 0; + } + return -1; } /* @@ -1545,59 +1632,53 @@ SECUREC_INLINE int SecInputNumberDigital(SecFileStream *stream, SecScanSpec *spe */ SECUREC_INLINE int SecInputNumber(SecFileStream *stream, SecScanSpec *spec) { - spec->ch = SecGetChar(stream, &(spec->charCount)); - + /* Character already read */ if (spec->ch == SECUREC_CHAR('+') || spec->ch == SECUREC_CHAR('-')) { if (spec->ch == SECUREC_CHAR('-')) { spec->negative = 1; #if SECUREC_IN_KERNEL - if (spec->convChr == SECUREC_CHAR('x') || - spec->convChr == SECUREC_CHAR('o') || - spec->convChr == SECUREC_CHAR('u')) { - /* In kernel Refuse to enter negative number */ + /* In kernel Refuse to enter negative number */ + if (SECUREC_CONVERT_IS_UNSIGNED(spec->oriConvChr)) { return -1; } #endif } - if (spec->widthSet != 0 && --spec->width == 0) { - return -1; - } else { - spec->ch = SecGetChar(stream, &(spec->charCount)); - } + SECUREC_FILED_WIDTH_DEC(spec); /* Do not need to check width here, must be greater than 0 */ + spec->ch = SecGetChar(stream, &(spec->charCount)); /* Eat + or - */ + spec->ch = SecGetChar(stream, &(spec->charCount)); /* Get next character, used for the '0' judgments */ + SecUnGetChar(spec->ch, stream, &(spec->charCount)); /* Not sure if it was actually read, so push back */ } - if (spec->oriConvChr == SECUREC_CHAR('i')) { - /* The i could be d, o, or x, use d as default */ - spec->convChr = SECUREC_CHAR('d'); + if (spec->oriConvChr == 'i') { + spec->convChr = 'd'; /* The i could be d, o, or x, use d as default */ } - if (spec->oriConvChr == SECUREC_CHAR('x') || spec->oriConvChr == SECUREC_CHAR('i')) { - if (spec->ch != SECUREC_CHAR('0')) { - /* Scan number */ - return SecInputNumberDigital(stream, spec); + if (spec->ch == SECUREC_CHAR('0') && (spec->oriConvChr == 'x' || spec->oriConvChr == 'i') && + SECUREC_FILED_WIDTH_ENOUGH(spec)) { + /* Input string begin with 0, may be 0x123 0X123 0123 0x 01 0yy 09 0 0ab 00 */ + SECUREC_FILED_WIDTH_DEC(spec); + spec->ch = SecGetChar(stream, &(spec->charCount)); /* ch is '0' */ + + /* Read only '0' due to width limitation */ + if (!SECUREC_FILED_WIDTH_ENOUGH(spec)) { + /* The number or number64 in spec has been set 0 */ + return 0; } - /* Now input string may be 0x123 or 0X123 or just 0 */ - /* Get next char */ - spec->ch = SecGetChar(stream, &(spec->charCount)); + + spec->ch = SecGetChar(stream, &(spec->charCount)); /* Get next char to check x or X, do not dec width */ if ((SecChar)spec->ch == SECUREC_CHAR('x') || (SecChar)spec->ch == SECUREC_CHAR('X')) { - spec->convChr = SECUREC_CHAR('x'); - spec->ch = SecGetChar(stream, &(spec->charCount)); - /* Length of 0x is 2 */ - if (spec->widthSet != 0 && spec->width <= (1 + 1)) { - /* Length not enough for "0x" */ - return -1; - } - spec->width -= 2; /* Subtract 2 for the length of "0x" */ + spec->convChr = 'x'; + SECUREC_FILED_WIDTH_DEC(spec); /* Make incorrect width for x or X */ } else { - if (spec->oriConvChr != SECUREC_CHAR('x')) { - spec->convChr = SECUREC_CHAR('o'); + if (spec->oriConvChr == 'i') { + spec->convChr = 'o'; } - /* Unset the character after 0 back to stream, input only '0' result is OK */ + /* For "0y" "08" "01" "0a" ... ,push the 'y' '8' '1' 'a' back */ SecUnGetChar(spec->ch, stream, &(spec->charCount)); - spec->ch = SECUREC_CHAR('0'); + /* Since 0 has been read, it indicates that a valid character has been read */ + spec->numberState = SECUREC_NUMBER_STATE_STARTED; } } - /* Scan number */ return SecInputNumberDigital(stream, spec); } @@ -1612,15 +1693,16 @@ SECUREC_INLINE int SecInputString(SecFileStream *stream, SecScanSpec *spec, int suppressed = 0; int errNoMem = 0; - while (spec->widthSet == 0 || spec->width-- != 0) { + while (SECUREC_FILED_WIDTH_ENOUGH(spec)) { + SECUREC_FILED_WIDTH_DEC(spec); spec->ch = SecGetChar(stream, &(spec->charCount)); /* * The char condition or string condition and bracket condition. * Only supports wide characters with a maximum length of two bytes */ - if (spec->ch != SECUREC_EOF && (SecCanInputCharacter(spec->convChr) || - SecCanInputString(spec->convChr, spec->ch) || - SecCanInputForBracket(spec->convChr, spec->ch, bracketTable))) { + if (spec->ch != SECUREC_EOF && (SecCanInputCharacter(spec->convChr) != 0 || + SecCanInputString(spec->convChr, spec->ch) != 0 || + SecCanInputForBracket(spec->convChr, spec->ch, bracketTable) != 0)) { if (spec->suppress != 0) { /* Used to identify processed data for %*, use argPtr to identify will cause 613, so use suppressed */ suppressed = 1; @@ -1650,13 +1732,11 @@ SECUREC_INLINE int SecInputString(SecFileStream *stream, SecScanSpec *spec, SecAddEndingZero(startPtr, spec); return -1; } - - /* No input was scanned */ if ((spec->suppress != 0 && suppressed == 0) || (spec->suppress == 0 && startPtr == spec->argPtr)) { + /* No input was scanned */ return -1; } - if (spec->convChr != 'c') { /* Add null-terminate for strings */ SecAddEndingZero(spec->argPtr, spec); @@ -1720,19 +1800,17 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) SecFloatSpec floatSpec; SecInitFloatSpec(&floatSpec); #endif - spec.ch = 0; - spec.charCount = 0; + spec.ch = 0; /* Need to initialize to 0 */ + spec.charCount = 0; /* Need to initialize to 0 */ /* Format must not NULL, use err < 1 to claer 845 */ while (errRet < 1 && *format != SECUREC_CHAR('\0')) { /* Skip space in format and space in input */ - if (SecIsSpace((SecInt)(int)(*format))) { + if (SecIsSpace((SecInt)(int)(*format)) != 0) { /* Read first no space char */ spec.ch = SecSkipSpaceChar(stream, &(spec.charCount)); - if (spec.ch == SECUREC_EOF) { - break; - } - /* Put fist no space char backup */ + /* Read the EOF cannot be returned directly here, because the case of " %n" needs to be handled */ + /* Put fist no space char backup. put EOF back is also OK, and to modify the character count */ SecUnGetChar(spec.ch, stream, &(spec.charCount)); SecSkipSpaceFormat(&format); continue; @@ -1740,19 +1818,18 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) if (*format != SECUREC_CHAR('%')) { spec.ch = SecGetChar(stream, &(spec.charCount)); - if ((int)(*(format++)) != (int)(spec.ch)) { + if ((int)(*format) != (int)(spec.ch)) { SecUnGetChar(spec.ch, stream, &(spec.charCount)); break; } + ++format; #if !defined(SECUREC_FOR_WCHAR) && defined(SECUREC_COMPATIBLE_VERSION) - if (SecIsLeadByte(spec.ch) && SecDecodeLeadByte(&spec, &format, stream) != 0) { - break; + if (SecIsLeadByte(spec.ch) != 0) { + if (SecDecodeLeadByte(&spec, &format, stream) != 0) { + break; + } } #endif - - if (SECUREC_MEET_EOF_BEFORE_NEXT_N(spec.ch, format)) { - break; - } continue; } @@ -1764,20 +1841,19 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) ++errRet; continue; } - /* Update wchar flag for %S %C */ - SecUpdateWcharFlagByType(*format, &spec); - - if (spec.widthSet != 0 && spec.width == 0) { + if (!SECUREC_FILED_WIDTH_ENOUGH(&spec)) { /* 0 width in format */ ++errRet; continue; } - spec.convChr = (unsigned char)(*format) | (SECUREC_CHAR('a') - SECUREC_CHAR('A')); /* To lowercase */ - spec.oriConvChr = spec.convChr; + /* Update wchar flag for %S %C */ + SecUpdateWcharFlagByType(*format, &spec); - if (spec.convChr != SECUREC_CHAR('n')) { - if (spec.convChr != SECUREC_CHAR('c') && spec.convChr != SECUREC_BRACE) { + spec.convChr = SECUREC_TO_LOWERCASE(*format); + spec.oriConvChr = spec.convChr; /* convChr may be modified to handle integer logic */ + if (spec.convChr != 'n') { + if (spec.convChr != 'c' && spec.convChr != SECUREC_BRACE) { spec.ch = SecSkipSpaceChar(stream, &(spec.charCount)); } else { spec.ch = SecGetChar(stream, &(spec.charCount)); @@ -1789,12 +1865,18 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) } /* Now no 0 width in format and get one char from input */ - switch (spec.convChr) { - case SECUREC_CHAR('c'): /* Also 'C' */ + switch (spec.oriConvChr) { + case 'c': /* Also 'C' */ + if (spec.widthSet == 0) { + spec.widthSet = 1; + spec.width = 1; + } /* fall-through */ /* FALLTHRU */ - case SECUREC_CHAR('s'): /* Also 'S': */ + case 's': /* Also 'S': */ /* fall-through */ /* FALLTHRU */ case SECUREC_BRACE: + /* Unset last char to stream */ + SecUnGetChar(spec.ch, stream, &(spec.charCount)); /* Check dest buffer and size */ if (spec.suppress == 0) { spec.argPtr = (void *)va_arg(argList, void *); @@ -1803,9 +1885,10 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) ++errRet; continue; } - /* Get the next argument - size of the array in characters */ + /* Get the next argument, size of the array in characters */ #ifdef SECUREC_ON_64BITS - spec.arrayWidth = ((size_t)(va_arg(argList, size_t))) & 0xFFFFFFFFUL; + /* Use 0xffffffffUL mask to Support pass integer as array length */ + spec.arrayWidth = ((size_t)(va_arg(argList, size_t))) & 0xffffffffUL; #else /* !SECUREC_ON_64BITS */ spec.arrayWidth = (size_t)va_arg(argList, size_t); #endif @@ -1815,7 +1898,7 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) continue; } /* One element is needed for '\0' for %s and %[ */ - if (spec.convChr != SECUREC_CHAR('c')) { + if (spec.convChr != 'c') { --spec.arrayWidth; } } else { @@ -1823,12 +1906,7 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) spec.argPtr = NULL; } - if (spec.convChr == 'c') { - if (spec.widthSet == 0) { - spec.widthSet = 1; - spec.width = 1; - } - } else if (spec.convChr == SECUREC_BRACE) { + if (spec.convChr == SECUREC_BRACE) { /* Malloc when first %[ is meet for wchar version */ #ifdef SECUREC_FOR_WCHAR if (SecAllocBracketTable(&bracketTable) != 0) { @@ -1850,26 +1928,25 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) continue; } } - /* Unset last char to stream */ - SecUnGetChar(spec.ch, stream, &(spec.charCount)); - /* Set completed. Now read string */ + + /* Set completed. Now read string or character */ if (SecInputString(stream, &spec, &bracketTable, &doneCount) != 0) { ++errRet; continue; } break; - case SECUREC_CHAR('p'): + case 'p': /* Make %hp same as %p */ spec.numberWidth = SECUREC_NUM_WIDTH_INT; #ifdef SECUREC_ON_64BITS - spec.isInt64Arg = 1; + spec.numberArgType = 1; #endif /* fall-through */ /* FALLTHRU */ - case SECUREC_CHAR('o'): /* fall-through */ /* FALLTHRU */ - case SECUREC_CHAR('u'): /* fall-through */ /* FALLTHRU */ - case SECUREC_CHAR('d'): /* fall-through */ /* FALLTHRU */ - case SECUREC_CHAR('i'): /* fall-through */ /* FALLTHRU */ - case SECUREC_CHAR('x'): + case 'o': /* fall-through */ /* FALLTHRU */ + case 'u': /* fall-through */ /* FALLTHRU */ + case 'd': /* fall-through */ /* FALLTHRU */ + case 'i': /* fall-through */ /* FALLTHRU */ + case 'x': /* Unset last char to stream */ SecUnGetChar(spec.ch, stream, &(spec.charCount)); if (SecInputNumber(stream, &spec) != 0) { @@ -1887,7 +1964,7 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) ++doneCount; } break; - case SECUREC_CHAR('n'): /* Char count */ + case 'n': /* Char count */ if (spec.suppress == 0) { spec.argPtr = (void *)va_arg(argList, void *); if (spec.argPtr == NULL) { @@ -1896,16 +1973,16 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) continue; } spec.number = (unsigned long)(unsigned int)(spec.charCount); - spec.isInt64Arg = 0; + spec.numberArgType = 0; SecAssignNumber(&spec); } break; - case SECUREC_CHAR('e'): /* fall-through */ /* FALLTHRU */ - case SECUREC_CHAR('f'): /* fall-through */ /* FALLTHRU */ - case SECUREC_CHAR('g'): /* Scan a float */ -#if SECUREC_ENABLE_SCANF_FLOAT + case 'e': /* fall-through */ /* FALLTHRU */ + case 'f': /* fall-through */ /* FALLTHRU */ + case 'g': /* Scan a float */ /* Unset last char to stream */ SecUnGetChar(spec.ch, stream, &(spec.charCount)); +#if SECUREC_ENABLE_SCANF_FLOAT if (SecInputFloat(stream, &spec, &floatSpec) != 0) { ++errRet; continue; @@ -1927,7 +2004,6 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) #endif ++doneCount; } - break; #else /* SECUREC_ENABLE_SCANF_FLOAT */ ++errRet; @@ -1940,16 +2016,12 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) ++errRet; continue; } else { - --match; /* Compensate for the self-increment of the following code */ + --match; /* Compensate for the self-increment of the following code */ } + break; } - ++match; ++format; - - if (SECUREC_MEET_EOF_BEFORE_NEXT_N(spec.ch, format)) { - break; - } } #ifdef SECUREC_FOR_WCHAR @@ -1965,18 +2037,27 @@ int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList) #endif if (spec.ch == SECUREC_EOF) { - return ((doneCount || match) ? doneCount : SECUREC_SCANF_EINVAL); - } else if (formatError != 0 || paraIsNull != 0) { - /* Invalid Input Format or parameter */ + return ((doneCount != 0 || match != 0) ? doneCount : SECUREC_SCANF_EINVAL); + } + if (formatError != 0 || paraIsNull != 0) { + /* Invalid Input Format or parameter, but not meet EOF */ return SECUREC_SCANF_ERROR_PARA; } - return doneCount; } #if SECUREC_ENABLE_SCANF_FILE - -#if defined(SECUREC_NO_STD_UNGETC) +#if SECUREC_USE_STD_UNGETC +/* + * Get char from stream use std function + */ +SECUREC_INLINE SecInt SecGetCharFromStream(const SecFileStream *stream) +{ + SecInt ch; + ch = SECUREC_GETC(stream->pf); + return ch; +} +#else /* * Get char from stream or buffer */ @@ -1992,68 +2073,22 @@ SECUREC_INLINE SecInt SecGetCharFromStream(SecFileStream *stream) } return ch; } -#else -/* - * Get char from stream use std function - */ -SECUREC_INLINE SecInt SecGetCharFromStream(const SecFileStream *stream) -{ - SecInt ch; - ch = SECUREC_GETC(stream->pf); - return ch; -} #endif /* - * Make data is aligned to SecChar size - */ -SECUREC_INLINE void SecMakeDataIsAligned(SecFileStream *stream) -{ - int remainder = stream->count % (int)sizeof(SecChar); - if (remainder != 0) { - int needLen = (int)sizeof(SecChar) - remainder; - int len = (int)fread(stream->base + stream->count, (size_t)1, (size_t)(unsigned int)needLen, stream->pf); - if (len > 0 && len <= needLen) { - /* When encountering the end of a file, the read length is less than needLen */ - stream->count += len; - } - } -} - -/* - * Try to read the BOM header, when meet a BOM head, discard it + * Try to read the BOM header, when meet a BOM head, discard it, then data is Aligned to base */ SECUREC_INLINE void SecReadAndSkipBomHeader(SecFileStream *stream) { - int bomHeadSize; -#ifdef SECUREC_FOR_WCHAR - bomHeadSize = SECUREC_BOM_HEADER_SIZE; -#else - bomHeadSize = SECUREC_UTF8_BOM_HEADER_SIZE; -#endif - stream->count = (int)fread(stream->base, (size_t)1, (size_t)(unsigned int)bomHeadSize, stream->pf); - if (stream->count < 0 || stream->count > bomHeadSize) { + /* Use size_t type conversion to clean e747 */ + stream->count = fread(stream->base, (size_t)1, (size_t)SECUREC_BOM_HEADER_SIZE, stream->pf); + if (stream->count > SECUREC_BOM_HEADER_SIZE) { stream->count = 0; } -#ifdef SECUREC_FOR_WCHAR - if (stream->count >= SECUREC_BOM_HEADER_SIZE && - (((unsigned char)(stream->base[0]) == SECUREC_BOM_HEADER_LE_1ST && - (unsigned char)(stream->base[1]) == SECUREC_BOM_HEADER_LE_2ST) || - ((unsigned char)(stream->base[0]) == SECUREC_BOM_HEADER_BE_1ST && - (unsigned char)(stream->base[1]) == SECUREC_BOM_HEADER_BE_2ST))) { - /* It's BOM header, discard it */ - stream->count = 0; - } -#else - if (stream->count >= SECUREC_UTF8_BOM_HEADER_SIZE && - (unsigned char)(stream->base[0]) == SECUREC_UTF8_BOM_HEADER_1ST && - (unsigned char)(stream->base[1]) == SECUREC_UTF8_BOM_HEADER_2ND && - (unsigned char)(stream->base[2]) == SECUREC_UTF8_BOM_HEADER_3RD) { /* 2 offset of third head character */ + if (SECUREC_BEGIN_WITH_BOM(stream->base, stream->count)) { /* It's BOM header, discard it */ stream->count = 0; } -#endif - SecMakeDataIsAligned(stream); } /* @@ -2062,10 +2097,15 @@ SECUREC_INLINE void SecReadAndSkipBomHeader(SecFileStream *stream) SECUREC_INLINE SecInt SecGetCharFromFile(SecFileStream *stream) { SecInt ch; - if (stream->count == 0) { - int len; + if (stream->count < sizeof(SecChar)) { /* Load file to buffer */ - if (stream->base == NULL) { + size_t len; + if (stream->base != NULL) { + /* Put the last unread data in the buffer head */ + for (len = 0; len < stream->count; ++len) { + stream->base[len] = stream->cur[len]; + } + } else { stream->oriFilePos = ftell(stream->pf); /* Save original file read position */ if (stream->oriFilePos == -1) { /* It may be a pipe stream */ @@ -2074,19 +2114,20 @@ SECUREC_INLINE SecInt SecGetCharFromFile(SecFileStream *stream) } /* Reserve the length of BOM head */ stream->base = (char *)SECUREC_MALLOC(SECUREC_BUFFERED_BLOK_SIZE + - SECUREC_BOM_HEADER_SIZE + SECUREC_UTF8_BOM_HEADER_SIZE); + SECUREC_BOM_HEADER_SIZE + sizeof(SecChar)); /* To store '\0' and aligned to wide char */ if (stream->base == NULL) { return SECUREC_EOF; } /* First read file */ if (stream->oriFilePos == 0) { + /* Make sure the data is aligned to base */ SecReadAndSkipBomHeader(stream); } } - /* SecReadAndSkipBomHeader has read part of the data, so add offset */ - len = (int)fread(stream->base + stream->count, - (size_t)1, (size_t)SECUREC_BUFFERED_BLOK_SIZE, stream->pf); - if (len < 0 || len > SECUREC_BUFFERED_BLOK_SIZE) { + + /* Skip existing data and read data */ + len = fread(stream->base + stream->count, (size_t)1, (size_t)SECUREC_BUFFERED_BLOK_SIZE, stream->pf); + if (len > SECUREC_BUFFERED_BLOK_SIZE) { /* It won't happen, */ len = 0; } stream->count += len; @@ -2094,15 +2135,10 @@ SECUREC_INLINE SecInt SecGetCharFromFile(SecFileStream *stream) stream->flag |= SECUREC_LOAD_FILE_TO_MEM_FLAG; stream->base[stream->count] = '\0'; /* For tool Warning string null */ } - /* According wchar_t has two bytes */ - stream->count -= (int)sizeof(SecChar); - ch = (SecInt)((stream->count) >= 0 ? \ - (SecInt)(SECUREC_CHAR_MASK & \ - (unsigned int)(int)(*((const SecChar *)(const void *)stream->cur))) : SECUREC_EOF); - stream->cur += sizeof(SecChar); /* Pointer may be out of bounds, but overread does not occur */ - if (ch != SECUREC_EOF && stream->base != NULL) { - stream->fileRealRead += (int)sizeof(SecChar); + SECUREC_GET_CHAR(stream, &ch); + if (ch != SECUREC_EOF) { + stream->fileRealRead += sizeof(SecChar); } return ch; } @@ -2113,24 +2149,22 @@ SECUREC_INLINE SecInt SecGetCharFromFile(SecFileStream *stream) */ SECUREC_INLINE SecInt SecGetChar(SecFileStream *stream, int *counter) { - SecInt ch = SECUREC_EOF; + *counter = *counter + 1; /* Always plus 1 */ + /* The main scenario is scanf str */ + if ((stream->flag & SECUREC_MEM_STR_FLAG) != 0) { + SecInt ch; + SECUREC_GET_CHAR(stream, &ch); + return ch; + } #if SECUREC_ENABLE_SCANF_FILE - if ((stream->flag & SECUREC_PIPE_STREAM_FLAG) > 0) { - ch = SecGetCharFromStream(stream); - } else if ((stream->flag & SECUREC_FILE_STREAM_FLAG) > 0) { - ch = SecGetCharFromFile(stream); + if ((stream->flag & SECUREC_FILE_STREAM_FLAG) != 0) { + return SecGetCharFromFile(stream); } -#endif - if ((stream->flag & SECUREC_MEM_STR_FLAG) > 0) { - /* According wchar_t has two bytes */ - stream->count -= (int)sizeof(SecChar); - ch = (SecInt)((stream->count >= 0) ? \ - (SecInt)(SECUREC_CHAR_MASK & \ - (unsigned int)(int)(*((const SecChar *)(const void *)stream->cur))) : SECUREC_EOF); - stream->cur += sizeof(SecChar); + if ((stream->flag & SECUREC_PIPE_STREAM_FLAG) != 0) { + return SecGetCharFromStream(stream); } - *counter = *counter + 1; - return ch; +#endif + return SECUREC_EOF; } /* @@ -2138,27 +2172,29 @@ SECUREC_INLINE SecInt SecGetChar(SecFileStream *stream, int *counter) */ SECUREC_INLINE void SecUnGetCharImpl(SecInt ch, SecFileStream *stream) { - if ((stream->flag & SECUREC_PIPE_STREAM_FLAG) > 0) { + if ((stream->flag & SECUREC_MEM_STR_FLAG) != 0) { + SECUREC_UN_GET_CHAR(stream); + return; + } #if SECUREC_ENABLE_SCANF_FILE -#if defined(SECUREC_NO_STD_UNGETC) - stream->lastChar = (unsigned int)ch; - stream->fUnGet = 1; -#else + if ((stream->flag & SECUREC_LOAD_FILE_TO_MEM_FLAG) != 0) { + SECUREC_UN_GET_CHAR(stream); + if (stream->fileRealRead > 0) { + stream->fileRealRead -= sizeof(SecChar); + } + return; + } + if ((stream->flag & SECUREC_PIPE_STREAM_FLAG) != 0) { +#if SECUREC_USE_STD_UNGETC (void)SECUREC_UN_GETC(ch, stream->pf); -#endif #else - (void)ch; /* To clear e438 last value assigned not used , the compiler will optimize this code */ + stream->lastChar = (unsigned int)ch; + stream->fUnGet = 1; #endif - } else if ((stream->flag & SECUREC_MEM_STR_FLAG) || (stream->flag & SECUREC_LOAD_FILE_TO_MEM_FLAG) > 0) { - if (stream->cur > stream->base) { - stream->cur -= sizeof(SecChar); - stream->count += (int)sizeof(SecChar); - } - } -#if SECUREC_ENABLE_SCANF_FILE - if ((stream->flag & SECUREC_FILE_STREAM_FLAG) > 0 && stream->base) { - stream->fileRealRead -= (int)sizeof(SecChar); + return; } +#else + (void)ch; /* To clear e438 last value assigned not used , the compiler will optimize this code */ #endif } @@ -2167,10 +2203,10 @@ SECUREC_INLINE void SecUnGetCharImpl(SecInt ch, SecFileStream *stream) */ SECUREC_INLINE void SecUnGetChar(SecInt ch, SecFileStream *stream, int *counter) { + *counter = *counter - 1; /* Always mius 1 */ if (ch != SECUREC_EOF) { SecUnGetCharImpl(ch, stream); } - *counter = *counter - 1; } /* @@ -2181,8 +2217,11 @@ SECUREC_INLINE SecInt SecSkipSpaceChar(SecFileStream *stream, int *counter) SecInt ch; do { ch = SecGetChar(stream, counter); - } while (ch != SECUREC_EOF && SecIsSpace(ch)); + if (ch == SECUREC_EOF) { + break; + } + } while (SecIsSpace(ch) != 0); return ch; } -#endif /* __INPUT_INL__5D13A042_DC3F_4ED9_A8D1_882811274C27 */ +#endif /* INPUT_INL_5D13A042_DC3F_4ED9_A8D1_882811274C27 */ diff --git a/src/mapleall/huawei_secure_c/src/memcpy_s.c b/third_party/bounds_checking_function/src/memcpy_s.c similarity index 63% rename from src/mapleall/huawei_secure_c/src/memcpy_s.c rename to third_party/bounds_checking_function/src/memcpy_s.c index 7cffae821e18f1d36d22baae8bf81fccaa6f4a27..4062a322d25576d499877e81f9b728de2156506b 100644 --- a/src/mapleall/huawei_secure_c/src/memcpy_s.c +++ b/third_party/bounds_checking_function/src/memcpy_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: memcpy_s function + * Author: lishunda + * Create: 2014-02-25 */ /* * [Standardize-exceptions] Use unsafe function: Portability @@ -34,397 +34,399 @@ /* Use struct assignment */ \ switch (count) { \ case 1: \ - *(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(src); \ + *(unsigned char *)(dest) = *(const unsigned char *)(src); \ break; \ case 2: \ - *(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 2); \ break; \ case 3: \ - *(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 3); \ break; \ case 4: \ - *(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 4); \ break; \ case 5: \ - *(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 5); \ break; \ case 6: \ - *(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 6); \ break; \ case 7: \ - *(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 7); \ break; \ case 8: \ - *(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 8); \ break; \ case 9: \ - *(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 9); \ break; \ case 10: \ - *(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 10); \ break; \ case 11: \ - *(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 11); \ break; \ case 12: \ - *(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 12); \ break; \ case 13: \ - *(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 13); \ break; \ case 14: \ - *(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 14); \ break; \ case 15: \ - *(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 15); \ break; \ case 16: \ - *(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 16); \ break; \ case 17: \ - *(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 17); \ break; \ case 18: \ - *(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 18); \ break; \ case 19: \ - *(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 19); \ break; \ case 20: \ - *(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 20); \ break; \ case 21: \ - *(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 21); \ break; \ case 22: \ - *(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 22); \ break; \ case 23: \ - *(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 23); \ break; \ case 24: \ - *(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 24); \ break; \ case 25: \ - *(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 25); \ break; \ case 26: \ - *(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 26); \ break; \ case 27: \ - *(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 27); \ break; \ case 28: \ - *(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 28); \ break; \ case 29: \ - *(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 29); \ break; \ case 30: \ - *(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 30); \ break; \ case 31: \ - *(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 31); \ break; \ case 32: \ - *(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 32); \ break; \ case 33: \ - *(SecStrBuf33 *)(dest) = *(const SecStrBuf33 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 33); \ break; \ case 34: \ - *(SecStrBuf34 *)(dest) = *(const SecStrBuf34 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 34); \ break; \ case 35: \ - *(SecStrBuf35 *)(dest) = *(const SecStrBuf35 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 35); \ break; \ case 36: \ - *(SecStrBuf36 *)(dest) = *(const SecStrBuf36 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 36); \ break; \ case 37: \ - *(SecStrBuf37 *)(dest) = *(const SecStrBuf37 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 37); \ break; \ case 38: \ - *(SecStrBuf38 *)(dest) = *(const SecStrBuf38 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 38); \ break; \ case 39: \ - *(SecStrBuf39 *)(dest) = *(const SecStrBuf39 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 39); \ break; \ case 40: \ - *(SecStrBuf40 *)(dest) = *(const SecStrBuf40 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 40); \ break; \ case 41: \ - *(SecStrBuf41 *)(dest) = *(const SecStrBuf41 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 41); \ break; \ case 42: \ - *(SecStrBuf42 *)(dest) = *(const SecStrBuf42 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 42); \ break; \ case 43: \ - *(SecStrBuf43 *)(dest) = *(const SecStrBuf43 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 43); \ break; \ case 44: \ - *(SecStrBuf44 *)(dest) = *(const SecStrBuf44 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 44); \ break; \ case 45: \ - *(SecStrBuf45 *)(dest) = *(const SecStrBuf45 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 45); \ break; \ case 46: \ - *(SecStrBuf46 *)(dest) = *(const SecStrBuf46 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 46); \ break; \ case 47: \ - *(SecStrBuf47 *)(dest) = *(const SecStrBuf47 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 47); \ break; \ case 48: \ - *(SecStrBuf48 *)(dest) = *(const SecStrBuf48 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 48); \ break; \ case 49: \ - *(SecStrBuf49 *)(dest) = *(const SecStrBuf49 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 49); \ break; \ case 50: \ - *(SecStrBuf50 *)(dest) = *(const SecStrBuf50 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 50); \ break; \ case 51: \ - *(SecStrBuf51 *)(dest) = *(const SecStrBuf51 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 51); \ break; \ case 52: \ - *(SecStrBuf52 *)(dest) = *(const SecStrBuf52 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 52); \ break; \ case 53: \ - *(SecStrBuf53 *)(dest) = *(const SecStrBuf53 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 53); \ break; \ case 54: \ - *(SecStrBuf54 *)(dest) = *(const SecStrBuf54 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 54); \ break; \ case 55: \ - *(SecStrBuf55 *)(dest) = *(const SecStrBuf55 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 55); \ break; \ case 56: \ - *(SecStrBuf56 *)(dest) = *(const SecStrBuf56 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 56); \ break; \ case 57: \ - *(SecStrBuf57 *)(dest) = *(const SecStrBuf57 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 57); \ break; \ case 58: \ - *(SecStrBuf58 *)(dest) = *(const SecStrBuf58 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 58); \ break; \ case 59: \ - *(SecStrBuf59 *)(dest) = *(const SecStrBuf59 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 59); \ break; \ case 60: \ - *(SecStrBuf60 *)(dest) = *(const SecStrBuf60 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 60); \ break; \ case 61: \ - *(SecStrBuf61 *)(dest) = *(const SecStrBuf61 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 61); \ break; \ case 62: \ - *(SecStrBuf62 *)(dest) = *(const SecStrBuf62 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 62); \ break; \ case 63: \ - *(SecStrBuf63 *)(dest) = *(const SecStrBuf63 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 63); \ break; \ case 64: \ - *(SecStrBuf64 *)(dest) = *(const SecStrBuf64 *)(src); \ + SECUREC_COPY_VALUE_BY_STRUCT((dest), (src), 64); \ break; \ default: \ + /* Do nothing */ \ break; \ } /* END switch */ \ } else { \ - char *tmpDest = (char *)(dest); \ - const char *tmpSrc = (const char *)(src); \ + unsigned char *tmpDest_ = (unsigned char *)(dest); \ + const unsigned char *tmpSrc_ = (const unsigned char *)(src); \ switch (count) { \ case 64: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 63: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 62: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 61: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 60: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 59: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 58: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 57: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 56: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 55: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 54: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 53: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 52: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 51: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 50: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 49: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 48: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 47: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 46: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 45: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 44: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 43: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 42: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 41: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 40: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 39: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 38: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 37: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 36: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 35: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 34: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 33: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 32: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 31: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 30: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 29: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 28: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 27: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 26: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 25: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 24: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 23: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 22: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 21: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 20: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 19: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 18: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 17: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 16: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 15: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 14: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 13: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 12: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 11: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 10: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 9: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 8: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 7: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 6: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 5: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 4: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 3: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 2: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 1: \ - *(tmpDest++) = *(tmpSrc++); \ + *(tmpDest_++) = *(tmpSrc_++); \ /* fall-through */ /* FALLTHRU */ \ default: \ + /* Do nothing */ \ break; \ } \ } \ diff --git a/src/mapleall/huawei_secure_c/src/memmove_s.c b/third_party/bounds_checking_function/src/memmove_s.c similarity index 84% rename from src/mapleall/huawei_secure_c/src/memmove_s.c rename to third_party/bounds_checking_function/src/memmove_s.c index 2521e5922cfa8647fd695e494d964d1002eb8034..417df8828956f1fc1219535cd52dd7a9f66d21a1 100644 --- a/src/mapleall/huawei_secure_c/src/memmove_s.c +++ b/third_party/bounds_checking_function/src/memmove_s.c @@ -1,21 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. - */ -/* - * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain platform compatibility. - * And sufficient input validation is performed before calling + * Description: memmove_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" @@ -35,7 +30,8 @@ SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count) * Non-Overlapping Buffers * Copy from lower addresses to higher addresses */ - while (maxCount--) { + while (maxCount > 0) { + --maxCount; *pDest = *pSrc; ++pDest; ++pSrc; @@ -47,7 +43,8 @@ SECUREC_INLINE void SecUtilMemmove(void *dst, const void *src, size_t count) */ pDest = pDest + maxCount - 1; pSrc = pSrc + maxCount - 1; - while (maxCount--) { + while (maxCount > 0) { + --maxCount; *pDest = *pSrc; --pDest; --pSrc; diff --git a/src/mapleall/huawei_secure_c/src/memset_s.c b/third_party/bounds_checking_function/src/memset_s.c similarity index 54% rename from src/mapleall/huawei_secure_c/src/memset_s.c rename to third_party/bounds_checking_function/src/memset_s.c index 9949033b17a2b3cc52a021bbfe82748f76260daa..fc0cdbe6d59e94cee0d20b47052ac06455f08c17 100644 --- a/src/mapleall/huawei_secure_c/src/memset_s.c +++ b/third_party/bounds_checking_function/src/memset_s.c @@ -1,33 +1,24 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. - */ -/* - * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain platform compatibility. - * And sufficient input validation is performed before calling + * Description: memset_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" -#ifndef SECUREC_MEMSET_WITH_PERFORMANCE -#define SECUREC_MEMSET_WITH_PERFORMANCE 0 -#endif - #define SECUREC_MEMSET_PARAM_OK(dest, destMax, count) (SECUREC_LIKELY((destMax) <= SECUREC_MEM_MAX_LEN && \ (dest) != NULL && (count) <= (destMax))) -#if SECUREC_WITH_PERFORMANCE_ADDONS || SECUREC_MEMSET_WITH_PERFORMANCE +#if SECUREC_WITH_PERFORMANCE_ADDONS /* Use union to clear strict-aliasing warning */ typedef union { @@ -62,7 +53,6 @@ typedef union { SecStrBuf4 buf4; SecStrBuf3 buf3; SecStrBuf2 buf2; - SecStrBuf1 buf1; } SecStrBuf32Union; /* C standard initializes the first member of the consortium. */ static const SecStrBuf32 g_allZero = {{ @@ -89,321 +79,329 @@ SECUREC_INLINE const SecStrBuf32Union *SecStrictAliasingCast(const SecStrBuf32 * #endif #define SECUREC_UNALIGNED_SET(dest, c, count) do { \ - char *pcDest = (char *)(dest); \ + unsigned char *pDest_ = (unsigned char *)(dest); \ switch (count) { \ case 32: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 31: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 30: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 29: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 28: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 27: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 26: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 25: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 24: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 23: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 22: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 21: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 20: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 19: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 18: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 17: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 16: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 15: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 14: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 13: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 12: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 11: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 10: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 9: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 8: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 7: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 6: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 5: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 4: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 3: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 2: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ case 1: \ - *(pcDest++) = (char)(c); \ + *(pDest_++) = (unsigned char)(c); \ /* fall-through */ /* FALLTHRU */ \ default: \ + /* Do nothing */ \ break; \ } \ } SECUREC_WHILE_ZERO +#define SECUREC_SET_VALUE_BY_STRUCT(dest, dataName, n) do { \ + *(SecStrBuf##n *)(dest) = *(const SecStrBuf##n *)(&((SecStrictAliasingCast(&(dataName)))->buf##n)); \ +} SECUREC_WHILE_ZERO + #define SECUREC_ALIGNED_SET_OPT_ZERO_FF(dest, c, count) do { \ switch (c) { \ case 0: \ switch (count) { \ case 1: \ - *(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allZero))->buf1)); \ + *(unsigned char *)(dest) = (unsigned char)0; \ break; \ case 2: \ - *(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allZero))->buf2)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 2); \ break; \ case 3: \ - *(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allZero))->buf3)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 3); \ break; \ case 4: \ - *(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allZero))->buf4)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 4); \ break; \ case 5: \ - *(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allZero))->buf5)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 5); \ break; \ case 6: \ - *(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allZero))->buf6)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 6); \ break; \ case 7: \ - *(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allZero))->buf7)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 7); \ break; \ case 8: \ - *(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allZero))->buf8)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 8); \ break; \ case 9: \ - *(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allZero))->buf9)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 9); \ break; \ case 10: \ - *(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(&((SecStrictAliasingCast(&g_allZero))->buf10)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 10); \ break; \ case 11: \ - *(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(&((SecStrictAliasingCast(&g_allZero))->buf11)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 11); \ break; \ case 12: \ - *(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(&((SecStrictAliasingCast(&g_allZero))->buf12)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 12); \ break; \ case 13: \ - *(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(&((SecStrictAliasingCast(&g_allZero))->buf13)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 13); \ break; \ case 14: \ - *(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(&((SecStrictAliasingCast(&g_allZero))->buf14)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 14); \ break; \ case 15: \ - *(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(&((SecStrictAliasingCast(&g_allZero))->buf15)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 15); \ break; \ case 16: \ - *(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(&((SecStrictAliasingCast(&g_allZero))->buf16)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 16); \ break; \ case 17: \ - *(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(&((SecStrictAliasingCast(&g_allZero))->buf17)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 17); \ break; \ case 18: \ - *(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(&((SecStrictAliasingCast(&g_allZero))->buf18)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 18); \ break; \ case 19: \ - *(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(&((SecStrictAliasingCast(&g_allZero))->buf19)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 19); \ break; \ case 20: \ - *(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(&((SecStrictAliasingCast(&g_allZero))->buf20)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 20); \ break; \ case 21: \ - *(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(&((SecStrictAliasingCast(&g_allZero))->buf21)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 21); \ break; \ case 22: \ - *(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(&((SecStrictAliasingCast(&g_allZero))->buf22)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 22); \ break; \ case 23: \ - *(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(&((SecStrictAliasingCast(&g_allZero))->buf23)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 23); \ break; \ case 24: \ - *(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(&((SecStrictAliasingCast(&g_allZero))->buf24)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 24); \ break; \ case 25: \ - *(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(&((SecStrictAliasingCast(&g_allZero))->buf25)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 25); \ break; \ case 26: \ - *(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(&((SecStrictAliasingCast(&g_allZero))->buf26)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 26); \ break; \ case 27: \ - *(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(&((SecStrictAliasingCast(&g_allZero))->buf27)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 27); \ break; \ case 28: \ - *(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(&((SecStrictAliasingCast(&g_allZero))->buf28)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 28); \ break; \ case 29: \ - *(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(&((SecStrictAliasingCast(&g_allZero))->buf29)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 29); \ break; \ case 30: \ - *(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(&((SecStrictAliasingCast(&g_allZero))->buf30)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 30); \ break; \ case 31: \ - *(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(&((SecStrictAliasingCast(&g_allZero))->buf31)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 31); \ break; \ case 32: \ - *(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(&((SecStrictAliasingCast(&g_allZero))->buf32)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allZero, 32); \ break; \ default: \ + /* Do nothing */ \ break; \ } \ break; \ case 0xFF: \ switch (count) { \ case 1: \ - *(SecStrBuf1 *)(dest) = *(const SecStrBuf1 *)(&((SecStrictAliasingCast(&g_allFF))->buf1)); \ + *(unsigned char *)(dest) = (unsigned char)0xffU; \ break; \ case 2: \ - *(SecStrBuf2 *)(dest) = *(const SecStrBuf2 *)(&((SecStrictAliasingCast(&g_allFF))->buf2)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 2); \ break; \ case 3: \ - *(SecStrBuf3 *)(dest) = *(const SecStrBuf3 *)(&((SecStrictAliasingCast(&g_allFF))->buf3)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 3); \ break; \ case 4: \ - *(SecStrBuf4 *)(dest) = *(const SecStrBuf4 *)(&((SecStrictAliasingCast(&g_allFF))->buf4)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 4); \ break; \ case 5: \ - *(SecStrBuf5 *)(dest) = *(const SecStrBuf5 *)(&((SecStrictAliasingCast(&g_allFF))->buf5)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 5); \ break; \ case 6: \ - *(SecStrBuf6 *)(dest) = *(const SecStrBuf6 *)(&((SecStrictAliasingCast(&g_allFF))->buf6)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 6); \ break; \ case 7: \ - *(SecStrBuf7 *)(dest) = *(const SecStrBuf7 *)(&((SecStrictAliasingCast(&g_allFF))->buf7)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 7); \ break; \ case 8: \ - *(SecStrBuf8 *)(dest) = *(const SecStrBuf8 *)(&((SecStrictAliasingCast(&g_allFF))->buf8)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 8); \ break; \ case 9: \ - *(SecStrBuf9 *)(dest) = *(const SecStrBuf9 *)(&((SecStrictAliasingCast(&g_allFF))->buf9)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 9); \ break; \ case 10: \ - *(SecStrBuf10 *)(dest) = *(const SecStrBuf10 *)(&((SecStrictAliasingCast(&g_allFF))->buf10)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 10); \ break; \ case 11: \ - *(SecStrBuf11 *)(dest) = *(const SecStrBuf11 *)(&((SecStrictAliasingCast(&g_allFF))->buf11)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 11); \ break; \ case 12: \ - *(SecStrBuf12 *)(dest) = *(const SecStrBuf12 *)(&((SecStrictAliasingCast(&g_allFF))->buf12)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 12); \ break; \ case 13: \ - *(SecStrBuf13 *)(dest) = *(const SecStrBuf13 *)(&((SecStrictAliasingCast(&g_allFF))->buf13)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 13); \ break; \ case 14: \ - *(SecStrBuf14 *)(dest) = *(const SecStrBuf14 *)(&((SecStrictAliasingCast(&g_allFF))->buf14)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 14); \ break; \ case 15: \ - *(SecStrBuf15 *)(dest) = *(const SecStrBuf15 *)(&((SecStrictAliasingCast(&g_allFF))->buf15)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 15); \ break; \ case 16: \ - *(SecStrBuf16 *)(dest) = *(const SecStrBuf16 *)(&((SecStrictAliasingCast(&g_allFF))->buf16)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 16); \ break; \ case 17: \ - *(SecStrBuf17 *)(dest) = *(const SecStrBuf17 *)(&((SecStrictAliasingCast(&g_allFF))->buf17)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 17); \ break; \ case 18: \ - *(SecStrBuf18 *)(dest) = *(const SecStrBuf18 *)(&((SecStrictAliasingCast(&g_allFF))->buf18)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 18); \ break; \ case 19: \ - *(SecStrBuf19 *)(dest) = *(const SecStrBuf19 *)(&((SecStrictAliasingCast(&g_allFF))->buf19)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 19); \ break; \ case 20: \ - *(SecStrBuf20 *)(dest) = *(const SecStrBuf20 *)(&((SecStrictAliasingCast(&g_allFF))->buf20)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 20); \ break; \ case 21: \ - *(SecStrBuf21 *)(dest) = *(const SecStrBuf21 *)(&((SecStrictAliasingCast(&g_allFF))->buf21)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 21); \ break; \ case 22: \ - *(SecStrBuf22 *)(dest) = *(const SecStrBuf22 *)(&((SecStrictAliasingCast(&g_allFF))->buf22)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 22); \ break; \ case 23: \ - *(SecStrBuf23 *)(dest) = *(const SecStrBuf23 *)(&((SecStrictAliasingCast(&g_allFF))->buf23)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 23); \ break; \ case 24: \ - *(SecStrBuf24 *)(dest) = *(const SecStrBuf24 *)(&((SecStrictAliasingCast(&g_allFF))->buf24)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 24); \ break; \ case 25: \ - *(SecStrBuf25 *)(dest) = *(const SecStrBuf25 *)(&((SecStrictAliasingCast(&g_allFF))->buf25)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 25); \ break; \ case 26: \ - *(SecStrBuf26 *)(dest) = *(const SecStrBuf26 *)(&((SecStrictAliasingCast(&g_allFF))->buf26)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 26); \ break; \ case 27: \ - *(SecStrBuf27 *)(dest) = *(const SecStrBuf27 *)(&((SecStrictAliasingCast(&g_allFF))->buf27)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 27); \ break; \ case 28: \ - *(SecStrBuf28 *)(dest) = *(const SecStrBuf28 *)(&((SecStrictAliasingCast(&g_allFF))->buf28)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 28); \ break; \ case 29: \ - *(SecStrBuf29 *)(dest) = *(const SecStrBuf29 *)(&((SecStrictAliasingCast(&g_allFF))->buf29)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 29); \ break; \ case 30: \ - *(SecStrBuf30 *)(dest) = *(const SecStrBuf30 *)(&((SecStrictAliasingCast(&g_allFF))->buf30)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 30); \ break; \ case 31: \ - *(SecStrBuf31 *)(dest) = *(const SecStrBuf31 *)(&((SecStrictAliasingCast(&g_allFF))->buf31)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 31); \ break; \ case 32: \ - *(SecStrBuf32 *)(dest) = *(const SecStrBuf32 *)(&((SecStrictAliasingCast(&g_allFF))->buf32)); \ + SECUREC_SET_VALUE_BY_STRUCT((dest), g_allFF, 32); \ break; \ default: \ + /* Do nothing */ \ break; \ } \ break; \ default: \ SECUREC_UNALIGNED_SET((dest), (c), (count)); \ + break; \ } /* END switch */ \ } SECUREC_WHILE_ZERO -#define SECUREC_SMALL_MEM_SET(dest, c, count); do { \ +#define SECUREC_SMALL_MEM_SET(dest, c, count) do { \ if (SECUREC_ADDR_ALIGNED_8((dest))) { \ SECUREC_ALIGNED_SET_OPT_ZERO_FF((dest), (c), (count)); \ } else { \ @@ -470,11 +468,7 @@ SECUREC_INLINE errno_t SecMemsetError(void *dest, size_t destMax, int c, size_t errno_t memset_s(void *dest, size_t destMax, int c, size_t count) { if (SECUREC_MEMSET_PARAM_OK(dest, destMax, count)) { -#if SECUREC_MEMSET_WITH_PERFORMANCE - SECUREC_MEMSET_OPT(dest, c, count); -#else SECUREC_MEMSET_WARP_OPT(dest, c, count); -#endif return EOK; } /* Meet some runtime violation, return error code */ diff --git a/src/mapleall/huawei_secure_c/src/output.inl b/third_party/bounds_checking_function/src/output.inl similarity index 77% rename from src/mapleall/huawei_secure_c/src/output.inl rename to third_party/bounds_checking_function/src/output.inl index 424a5d11e595284d169a79146c2861f3ec809825..20dd4b3bd87771848a0cc2bc3606cf0dc92e32c6 100644 --- a/src/mapleall/huawei_secure_c/src/output.inl +++ b/third_party/bounds_checking_function/src/output.inl @@ -1,40 +1,76 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v1. - * You can use this software according to the terms and conditions of the Mulan PSL v1. - * You may obtain a copy of Mulan PSL v1 at: - * - * http://license.coscl.org.cn/MulanPSL - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v1 for more details. - */ -/* - * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain platform compatibility. - * And sufficient input validation is performed before calling + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * Description: Used by secureprintoutput_a.c and secureprintoutput_w.c to include. + * This file provides a template function for ANSI and UNICODE compiling + * by different type definition. The functions of SecOutputS or + * SecOutputSW provides internal implementation for printf family API, such as sprintf, swprintf_s. + * Author: lishunda + * Create: 2014-02-25 */ #ifndef OUTPUT_INL_2B263E9C_43D8_44BB_B17A_6D2033DECEE5 #define OUTPUT_INL_2B263E9C_43D8_44BB_B17A_6D2033DECEE5 +#ifndef SECUREC_ENABLE_SPRINTF_LONG_DOUBLE +/* Some compilers do not support long double */ +#define SECUREC_ENABLE_SPRINTF_LONG_DOUBLE 1 +#endif + #define SECUREC_NULL_STRING_SIZE 8 -#define SECUREC_STATE_TABLE_SIZE 337 -#define SECUREC_OFFSET_BITS_WORD 16 -#define SECUREC_OFFSET_BITS_DWORD 32 - -#define SECUREC_OFFSET_DIV_OCTAL 3 -#define SECUREC_OFFSET_DIV_HEX 4 -#define SECUREC_RADIX_OCTAL 8 -#define SECUREC_RADIX_DECIMAL 10 -#define SECUREC_RADIX_HEX 16 +#define SECUREC_STATE_TABLE_SIZE 337 + +#if defined(SECUREC_VXWORKS_VERSION_5_4) && !defined(SECUREC_ON_64BITS) +#define SECUREC_DIV_QUOTIENT_OCTAL(val64) ((val64) >> 3ULL) +#define SECUREC_DIV_RESIDUE_OCTAL(val64) ((val64) & 7ULL) + +#define SECUREC_DIV_QUOTIENT_HEX(val64) ((val64) >> 4ULL) +#define SECUREC_DIV_RESIDUE_HEX(val64) ((val64) & 0xfULL) +#endif + +#define SECUREC_RADIX_OCTAL 8U +#define SECUREC_RADIX_DECIMAL 10U +#define SECUREC_RADIX_HEX 16U #define SECUREC_PREFIX_LEN 2 /* Size include '+' and '\0' */ #define SECUREC_FLOAT_BUF_EXT 2 +/* Sign extend or Zero-extend */ +#define SECUREC_GET_LONG_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \ + (SecInt64)(long)va_arg(argList, long) : \ + (SecInt64)(unsigned long)va_arg(argList, long)) + +/* Sign extend or Zero-extend */ +#define SECUREC_GET_CHAR_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \ + SecUpdateNegativeChar(&(attr), ((char)va_arg(argList, int))) : \ + (SecInt64)(unsigned char)va_arg(argList, int)) + +/* Sign extend or Zero-extend */ +#define SECUREC_GET_SHORT_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \ + (SecInt64)(short)va_arg(argList, int) : \ + (SecInt64)(unsigned short)va_arg(argList, int)) + +/* Sign extend or Zero-extend */ +#define SECUREC_GET_INT_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \ + (SecInt64)(int)va_arg(argList, int) : \ + (SecInt64)(unsigned int)va_arg(argList, int)) + +#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT +/* Sign extend or Zero-extend. No suitable macros were found to handle the branch */ +#define SECUREC_GET_SIZE_FROM_ARG(attr) ((((attr).flags & SECUREC_FLAG_SIGNED) != 0) ? \ + ((SecIsSameSize(sizeof(size_t), sizeof(long)) != 0) ? (SecInt64)(long)va_arg(argList, long) : \ + ((SecIsSameSize(sizeof(size_t), sizeof(long long)) != 0) ? (SecInt64)(long long)va_arg(argList, long long) : \ + (SecInt64)(int)va_arg(argList, int))) : \ + (SecInt64)(size_t)va_arg(argList, size_t)) +#endif + typedef union { /* Integer formatting refers to the end of the buffer, plus 1 to prevent tool alarms */ char str[SECUREC_BUFFER_SIZE + 1]; @@ -82,60 +118,12 @@ typedef struct { } SecFloatAdapt; #endif - - - -static const char *g_itoaUpperDigits = "0123456789ABCDEFX"; -static const char *g_itoaLowerDigits = "0123456789abcdefx"; -static const unsigned char g_stateTable[SECUREC_STATE_TABLE_SIZE] = { - /* - * Type - * 0: nospecial meanin; - * 1: '%' - * 2: '.' - * 3: '*' - * 4: '0' - * 5: '1' ... '9' - * 6: ' ', '+', '-', '#' - * 7: 'h', 'l', 'L', 'w' , 'N', 'z', 'q', 't', 'j' - * 8: 'd', 'o', 'u', 'i', 'x', 'X', 'e', 'f', 'g', 'E', 'F', 'G', 's', 'c', '[', 'p' - */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x00, 0x06, 0x02, 0x00, - 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, - 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x08, 0x07, 0x00, 0x07, 0x00, 0x00, 0x08, - 0x08, 0x07, 0x00, 0x08, 0x07, 0x08, 0x00, 0x07, 0x08, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - /* Fill zero for normal char 128 byte for 0x80 - 0xff */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - /* - * State - * 0: normal - * 1: percent - * 2: flag - * 3: width - * 4: dot - * 5: precis - * 6: size - * 7: type - * 8: invalid - */ - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x01, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x01, 0x00, 0x00, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x03, 0x03, 0x08, 0x05, - 0x08, 0x08, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x05, 0x05, 0x08, 0x00, 0x00, 0x00, 0x03, 0x03, - 0x03, 0x05, 0x05, 0x08, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, - 0x00 -}; +/* Use 20 to Align the data */ +#define SECUREC_DIGITS_BUF_SIZE 20 +/* Some systems can not use pointers to point to string literals, but can use string arrays. */ +/* For example, when handling code under uboot, there is a problem with the pointer */ +static const char g_itoaUpperDigits[SECUREC_DIGITS_BUF_SIZE] = "0123456789ABCDEFX"; +static const char g_itoaLowerDigits[SECUREC_DIGITS_BUF_SIZE] = "0123456789abcdefx"; #if SECUREC_ENABLE_SPRINTF_FLOAT /* Call system sprintf to format float value */ @@ -154,16 +142,16 @@ SECUREC_INLINE int SecFormatFloat(char *strDest, const char *format, ...) return ret; } -#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT +#if defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && SECUREC_ENABLE_SPRINTF_LONG_DOUBLE /* Out put long double value to dest */ -SECUREC_INLINE void SecFormatLongDboule(SecFormatAttr *attr, const SecFloatAdapt *floatAdapt, long double ldValue) +SECUREC_INLINE void SecFormatLongDouble(SecFormatAttr *attr, const SecFloatAdapt *floatAdapt, long double ldValue) { - int fldWidth = ((attr->flags & SECUREC_FLAG_LEFT) ? (-attr->fldWidth) : attr->fldWidth); - if (attr->dynWidth && attr->dynPrecision) { + int fldWidth = (((attr->flags & SECUREC_FLAG_LEFT) != 0) ? (-attr->fldWidth) : attr->fldWidth); + if (attr->dynWidth != 0 && attr->dynPrecision != 0) { attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, fldWidth, attr->precision, ldValue); - } else if (attr->dynWidth) { + } else if (attr->dynWidth != 0) { attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, fldWidth, ldValue); - } else if (attr->dynPrecision) { + } else if (attr->dynPrecision != 0) { attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, attr->precision, ldValue); } else { attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, ldValue); @@ -175,14 +163,14 @@ SECUREC_INLINE void SecFormatLongDboule(SecFormatAttr *attr, const SecFloatAdapt #endif /* Out put double value to dest */ -SECUREC_INLINE void SecFormatDboule(SecFormatAttr *attr, const SecFloatAdapt *floatAdapt, double dValue) +SECUREC_INLINE void SecFormatDouble(SecFormatAttr *attr, const SecFloatAdapt *floatAdapt, double dValue) { - int fldWidth = ((attr->flags & SECUREC_FLAG_LEFT) ? (-attr->fldWidth) : attr->fldWidth); - if (attr->dynWidth && attr->dynPrecision) { + int fldWidth = (((attr->flags & SECUREC_FLAG_LEFT) != 0) ? (-attr->fldWidth) : attr->fldWidth); + if (attr->dynWidth != 0 && attr->dynPrecision != 0) { attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, fldWidth, attr->precision, dValue); - } else if (attr->dynWidth) { + } else if (attr->dynWidth != 0) { attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, fldWidth, dValue); - } else if (attr->dynPrecision) { + } else if (attr->dynPrecision != 0) { attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, attr->precision, dValue); } else { attr->textLen = SecFormatFloat(attr->text.str, floatAdapt->fmtStr, dValue); @@ -197,11 +185,10 @@ SECUREC_INLINE void SecFormatDboule(SecFormatAttr *attr, const SecFloatAdapt *fl /* To clear e506 warning */ SECUREC_INLINE int SecIsSameSize(size_t sizeA, size_t sizeB) { - return sizeA == sizeB; + return (int)(sizeA == sizeB); } #endif - #ifndef SECUREC_ON_64BITS /* * Compiler Optimized Division 8. @@ -214,7 +201,8 @@ SECUREC_INLINE void SecNumber32ToOctalString(SecUnsignedInt32 number, SecFormatA --attr->text.str; /* Just use lowerDigits for 0 - 9 */ *(attr->text.str) = g_itoaLowerDigits[val32 % SECUREC_RADIX_OCTAL]; - } while ((val32 /= SECUREC_RADIX_OCTAL) != 0); + val32 /= SECUREC_RADIX_OCTAL; + } while (val32 != 0); } #ifdef _AIX @@ -229,7 +217,8 @@ SECUREC_INLINE void SecNumber32ToDecString(SecUnsignedInt32 number, SecFormatAtt --attr->text.str; /* Just use lowerDigits for 0 - 9 */ *(attr->text.str) = g_itoaLowerDigits[val32 % SECUREC_RADIX_DECIMAL]; - } while ((val32 /= SECUREC_RADIX_DECIMAL) != 0); + val32 /= SECUREC_RADIX_DECIMAL; + } while (val32 != 0); } #endif /* @@ -242,7 +231,8 @@ SECUREC_INLINE void SecNumber32ToHexString(SecUnsignedInt32 number, SecFormatAtt do { --attr->text.str; *(attr->text.str) = attr->digits[val32 % SECUREC_RADIX_HEX]; - } while ((val32 /= SECUREC_RADIX_HEX) != 0); + val32 /= SECUREC_RADIX_HEX; + } while (val32 != 0); } #ifndef _AIX @@ -255,13 +245,13 @@ SECUREC_INLINE void SecNumber32ToDecStringFast(SecUnsignedInt32 number, SecForma SecUnsignedInt32 remain; --attr->text.str; *(attr->text.str) = g_itoaLowerDigits[val32 % SECUREC_RADIX_DECIMAL]; - quotient = (val32 >> 1) + (val32 >> 2); /* Fast div magic 2 */ - quotient = quotient + (quotient >> 4); /* Fast div magic 4 */ - quotient = quotient + (quotient >> 8); /* Fast div magic 8 */ - quotient = quotient + (quotient >> 16); /* Fast div magic 16 */ - quotient = quotient >> 3; /* Fast div magic 3 */ + quotient = (val32 >> 1U) + (val32 >> 2U); /* Fast div magic 2 */ + quotient = quotient + (quotient >> 4U); /* Fast div magic 4 */ + quotient = quotient + (quotient >> 8U); /* Fast div magic 8 */ + quotient = quotient + (quotient >> 16U); /* Fast div magic 16 */ + quotient = quotient >> 3U; /* Fast div magic 3 */ remain = val32 - SECUREC_MUL_TEN(quotient); - val32 = (remain > 9) ? (quotient + 1) : quotient; /* Fast div magic 9 */ + val32 = (remain > 9U) ? (quotient + 1U) : quotient; /* Fast div magic 9 */ } while (val32 != 0); } #endif @@ -284,6 +274,7 @@ SECUREC_INLINE void SecNumber32ToString(SecUnsignedInt32 number, SecFormatAttr * #endif break; default: + /* Do nothing */ break; } } @@ -295,13 +286,13 @@ SECUREC_INLINE void SecNumber32ToString(SecUnsignedInt32 number, SecFormatAttr * */ SECUREC_INLINE SecUnsignedInt64 SecU64Shr32(SecUnsignedInt64 number) { - return (((number) >> 16) >> 16); /* Two shifts of 16 bits to realize shifts of 32 bits */ + return (((number) >> 16U) >> 16U); /* Two shifts of 16 bits to realize shifts of 32 bits */ } /* * Fast divide by 10 algorithm. * Calculation divisor multiply 0xcccccccccccccccdULL, resultHi64 >> 3 as quotient */ -SECUREC_INLINE void SecU64Div10(SecUnsignedInt64 divisor, SecUnsignedInt64 *quotient, SecUnsignedInt32 *remainder) +SECUREC_INLINE void SecU64Div10(SecUnsignedInt64 divisor, SecUnsignedInt64 *quotient, SecUnsignedInt32 *residue) { SecUnsignedInt64 mask = 0xffffffffULL; /* Use 0xffffffffULL as 32 bit mask */ SecUnsignedInt64 magicHi = 0xccccccccULL; /* Fast divide 10 magic numbers high 32bit 0xccccccccULL */ @@ -315,8 +306,8 @@ SECUREC_INLINE void SecU64Div10(SecUnsignedInt64 divisor, SecUnsignedInt64 *quot SecUnsignedInt64 carry = (factorLow1 & mask) + (factorLow2 & mask) + SecU64Shr32(factorLow3); SecUnsignedInt64 resultHi64 = factorHi + SecU64Shr32(factorLow1) + SecU64Shr32(factorLow2) + SecU64Shr32(carry); - *quotient = resultHi64 >> 3; /* Fast divide 10 magic numbers 3 */ - *remainder = (SecUnsignedInt32)(divisor - ((*quotient) * 10)); /* Quotient mul 10 */ + *quotient = resultHi64 >> 3U; /* Fast divide 10 magic numbers 3 */ + *residue = (SecUnsignedInt32)(divisor - ((*quotient) * 10)); /* Quotient mul 10 */ return; } #if defined(SECUREC_VXWORKS_VERSION_5_4) && !defined(SECUREC_ON_64BITS) @@ -324,19 +315,19 @@ SECUREC_INLINE void SecU64Div10(SecUnsignedInt64 divisor, SecUnsignedInt64 *quot * Divide function for VXWORKS */ SECUREC_INLINE int SecU64Div32(SecUnsignedInt64 divisor, SecUnsignedInt32 radix, - SecUnsignedInt64 *quotient, SecUnsignedInt32 *remainder) + SecUnsignedInt64 *quotient, SecUnsignedInt32 *residue) { switch (radix) { case SECUREC_RADIX_DECIMAL: - SecU64Div10(divisor, quotient, remainder); + SecU64Div10(divisor, quotient, residue); break; case SECUREC_RADIX_HEX: - *quotient = (divisor >> SECUREC_OFFSET_DIV_HEX); - *remainder = (SecUnsignedInt32)(divisor & 0xfULL); /* Mask one hex number by 0xfULL */ + *quotient = SECUREC_DIV_QUOTIENT_HEX(divisor); + *residue = (SecUnsignedInt32)SECUREC_DIV_RESIDUE_HEX(divisor); break; case SECUREC_RADIX_OCTAL: - *quotient = (divisor >> SECUREC_OFFSET_DIV_OCTAL); - *remainder = (SecUnsignedInt32)(divisor & 0x7ULL); /* Mask one hex number by 0x7ULL */ + *quotient = SECUREC_DIV_QUOTIENT_OCTAL(divisor); + *residue = (SecUnsignedInt32)SECUREC_DIV_RESIDUE_OCTAL(divisor); break; default: return -1; /* This does not happen in the current file */ @@ -389,7 +380,8 @@ SECUREC_INLINE void SecNumber64ToDecString(SecUnsignedInt64 number, SecFormatAtt --attr->text.str; /* Just use lowerDigits for 0 - 9 */ *(attr->text.str) = g_itoaLowerDigits[val64 % SECUREC_RADIX_DECIMAL]; - } while ((val64 /= SECUREC_RADIX_DECIMAL) != 0); + val64 /= SECUREC_RADIX_DECIMAL; + } while (val64 != 0); } #endif @@ -404,7 +396,8 @@ SECUREC_INLINE void SecNumber64ToOctalString(SecUnsignedInt64 number, SecFormatA --attr->text.str; /* Just use lowerDigits for 0 - 9 */ *(attr->text.str) = g_itoaLowerDigits[val64 % SECUREC_RADIX_OCTAL]; - } while ((val64 /= SECUREC_RADIX_OCTAL) != 0); + val64 /= SECUREC_RADIX_OCTAL; + } while (val64 != 0); } /* * Compiler Optimized Division 16. @@ -416,10 +409,10 @@ SECUREC_INLINE void SecNumber64ToHexString(SecUnsignedInt64 number, SecFormatAtt do { --attr->text.str; *(attr->text.str) = attr->digits[val64 % SECUREC_RADIX_HEX]; - } while ((val64 /= SECUREC_RADIX_HEX) != 0); + val64 /= SECUREC_RADIX_HEX; + } while (val64 != 0); } - SECUREC_INLINE void SecNumber64ToString(SecUnsignedInt64 number, SecFormatAttr *attr) { switch (attr->radix) { @@ -434,6 +427,7 @@ SECUREC_INLINE void SecNumber64ToString(SecUnsignedInt64 number, SecFormatAttr * SecNumber64ToHexString(number, attr); break; default: + /* Do nothing */ break; } } @@ -445,27 +439,26 @@ SECUREC_INLINE void SecNumber64ToString(SecUnsignedInt64 number, SecFormatAttr * SECUREC_INLINE void SecNumberToString(SecUnsignedInt64 number, SecFormatAttr *attr) { #ifdef SECUREC_ON_64BITS - SecNumber64ToString(number, attr); + SecNumber64ToString(number, attr); #else /* For 32 bits system */ - if (number <= 0xFFFFFFFFUL) { - /* In most case, the value to be converted is small value */ - SecUnsignedInt32 n32Tmp = (SecUnsignedInt32)number; - SecNumber32ToString(n32Tmp, attr); - } else { - /* The value to be converted is greater than 4G */ + if (number <= 0xffffffffUL) { /* Use 0xffffffffUL to check if the value is in the 32-bit range */ + /* In most case, the value to be converted is small value */ + SecUnsignedInt32 n32Tmp = (SecUnsignedInt32)number; + SecNumber32ToString(n32Tmp, attr); + } else { + /* The value to be converted is greater than 4G */ #if defined(SECUREC_VXWORKS_VERSION_5_4) - SecNumber64ToStringSpecial(number, attr); + SecNumber64ToStringSpecial(number, attr); #else - SecNumber64ToString(number, attr); + SecNumber64ToString(number, attr); #endif - } + } #endif - } SECUREC_INLINE int SecIsNumberNeedTo32Bit(const SecFormatAttr *attr) { - return (((attr->flags & SECUREC_FLAG_I64) == 0) && + return (int)(((attr->flags & SECUREC_FLAG_I64) == 0) && #ifdef SECUREC_COMPATIBLE_LINUX_FORMAT ((attr->flags & SECUREC_FLAG_INTMAX) == 0) && #endif @@ -483,13 +476,13 @@ SECUREC_INLINE void SecNumberToBuffer(SecFormatAttr *attr, SecInt64 num64) { SecUnsignedInt64 number; /* Check for negative; copy into number */ - if ((attr->flags & SECUREC_FLAG_SIGNED) && num64 < 0) { - number = (SecUnsignedInt64)(-num64); + if ((attr->flags & SECUREC_FLAG_SIGNED) != 0 && num64 < 0) { + number = (SecUnsignedInt64)(0 - (SecUnsignedInt64)num64); /* Wrap with unsigned int64 numbers */ attr->flags |= SECUREC_FLAG_NEGATIVE; } else { number = (SecUnsignedInt64)num64; } - if (SecIsNumberNeedTo32Bit(attr)) { + if (SecIsNumberNeedTo32Bit(attr) != 0) { number = (number & (SecUnsignedInt64)0xffffffffUL); /* Use 0xffffffff as 32 bit mask */ } @@ -543,10 +536,22 @@ SECUREC_INLINE int SecIsStreamBufEnough(const SecPrintfStream *stream, int needL return ((int)(stream->count - (needLen * (int)(sizeof(SecChar)))) >= 0); } +#ifdef SECUREC_FOR_WCHAR +SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten); +SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten); +#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiCharW +#define SECUREC_WRITE_STRING SecWriteStringW +#else +SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten); +SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten); +#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiChar +#define SECUREC_WRITE_STRING SecWriteString +#endif + /* Write left padding */ SECUREC_INLINE void SecWriteLeftPadding(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut) { - if (!(attr->flags & (SECUREC_FLAG_LEFT | SECUREC_FLAG_LEADZERO)) && attr->padding > 0) { + if ((attr->flags & (SECUREC_FLAG_LEFT | SECUREC_FLAG_LEADZERO)) == 0 && attr->padding > 0) { /* Pad on left with blanks */ SECUREC_WRITE_MULTI_CHAR(SECUREC_CHAR(' '), attr->padding, stream, charsOut); } @@ -556,7 +561,7 @@ SECUREC_INLINE void SecWriteLeftPadding(SecPrintfStream *stream, const SecFormat SECUREC_INLINE void SecWritePrefix(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut) { if (attr->prefixLen > 0) { - if (SecIsStreamBufEnough(stream, attr->prefixLen)) { + if (SecIsStreamBufEnough(stream, attr->prefixLen) != 0) { /* Max prefix len is 2, use loop copy */ SecWriteStringToStreamOpt(stream, attr->prefix, attr->prefixLen); *charsOut += attr->prefixLen; @@ -569,7 +574,7 @@ SECUREC_INLINE void SecWritePrefix(SecPrintfStream *stream, const SecFormatAttr /* Write leading zeros */ SECUREC_INLINE void SecWriteLeadingZero(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut) { - if ((attr->flags & SECUREC_FLAG_LEADZERO) && !(attr->flags & SECUREC_FLAG_LEFT) && + if ((attr->flags & SECUREC_FLAG_LEADZERO) != 0 && (attr->flags & SECUREC_FLAG_LEFT) == 0 && attr->padding > 0) { SECUREC_WRITE_MULTI_CHAR(SECUREC_CHAR('0'), attr->padding, stream, charsOut); } @@ -578,7 +583,7 @@ SECUREC_INLINE void SecWriteLeadingZero(SecPrintfStream *stream, const SecFormat /* Write right padding */ SECUREC_INLINE void SecWriteRightPadding(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut) { - if (*charsOut >= 0 && (attr->flags & SECUREC_FLAG_LEFT) && attr->padding > 0) { + if (*charsOut >= 0 && (attr->flags & SECUREC_FLAG_LEFT) != 0 && attr->padding > 0) { /* Pad on right with blanks */ SECUREC_WRITE_MULTI_CHAR(SECUREC_CHAR(' '), attr->padding, stream, charsOut); } @@ -587,7 +592,7 @@ SECUREC_INLINE void SecWriteRightPadding(SecPrintfStream *stream, const SecForma /* Write text string */ SECUREC_INLINE void SecWriteStringChk(SecPrintfStream *stream, const SecChar *str, int len, int *charsOut) { - if (SecIsStreamBufEnough(stream, len)) { + if (SecIsStreamBufEnough(stream, len) != 0) { SecWriteStringToStream(stream, str, len); *charsOut += len; } else { @@ -599,7 +604,7 @@ SECUREC_INLINE void SecWriteStringChk(SecPrintfStream *stream, const SecChar *st #if SECUREC_HAVE_MBTOWC SECUREC_INLINE void SecWriteTextAfterMbtowc(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut) { - char *p = attr->text.str; + const char *p = attr->text.str; int count = attr->textLen; while (count > 0) { wchar_t wChar = L'\0'; @@ -621,7 +626,7 @@ SECUREC_INLINE void SecWriteTextAfterMbtowc(SecPrintfStream *stream, const SecFo #if SECUREC_HAVE_WCTOMB SECUREC_INLINE void SecWriteTextAfterWctomb(SecPrintfStream *stream, const SecFormatAttr *attr, int *charsOut) { - wchar_t *p = attr->text.wStr; + const wchar_t *p = attr->text.wStr; int count = attr->textLen; while (count > 0) { char tmpBuf[SECUREC_MB_LEN + 1]; @@ -692,17 +697,68 @@ SECUREC_INLINE void SecWriteText(SecPrintfStream *stream, const SecFormatAttr *a } #define SECUREC_FMT_STATE_OFFSET 256 + SECUREC_INLINE SecFmtState SecDecodeState(SecChar ch, SecFmtState lastState) { + static const unsigned char stateTable[SECUREC_STATE_TABLE_SIZE] = { + /* + * Type + * 0: nospecial meanin; + * 1: '%' + * 2: '.' + * 3: '*' + * 4: '0' + * 5: '1' ... '9' + * 6: ' ', '+', '-', '#' + * 7: 'h', 'l', 'L', 'w' , 'N', 'z', 'q', 't', 'j' + * 8: 'd', 'o', 'u', 'i', 'x', 'X', 'e', 'f', 'g', 'E', 'F', 'G', 's', 'c', '[', 'p' + */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x00, 0x06, 0x02, 0x00, + 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x08, 0x08, 0x00, 0x07, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x08, 0x07, 0x00, 0x07, 0x00, 0x00, 0x08, + 0x08, 0x07, 0x00, 0x08, 0x07, 0x08, 0x00, 0x07, 0x08, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + /* Fill zero for normal char 128 byte for 0x80 - 0xff */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* + * State + * 0: normal + * 1: percent + * 2: flag + * 3: width + * 4: dot + * 5: precis + * 6: size + * 7: type + * 8: invalid + */ + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x01, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x01, 0x00, 0x00, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x03, 0x03, 0x08, 0x05, + 0x08, 0x08, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x05, 0x05, 0x08, 0x00, 0x00, 0x00, 0x03, 0x03, + 0x03, 0x05, 0x05, 0x08, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, + 0x00 + }; + #ifdef SECUREC_FOR_WCHAR /* Convert to unsigned char to clear gcc 4.3.4 warning */ unsigned char fmtType = (unsigned char)((((unsigned int)(int)(ch)) <= (unsigned int)(int)(L'~')) ? \ - (g_stateTable[(unsigned char)(ch)]) : 0); - return (SecFmtState)(g_stateTable[fmtType * ((unsigned char)STAT_INVALID + 1) + + (stateTable[(unsigned char)(ch)]) : 0); + return (SecFmtState)(stateTable[fmtType * ((unsigned char)STAT_INVALID + 1) + (unsigned char)(lastState) + SECUREC_FMT_STATE_OFFSET]); #else - unsigned char fmtType = g_stateTable[(unsigned char)(ch)]; - return (SecFmtState)(g_stateTable[fmtType * ((unsigned char)STAT_INVALID + 1) + + unsigned char fmtType = stateTable[(unsigned char)(ch)]; + return (SecFmtState)(stateTable[fmtType * ((unsigned char)STAT_INVALID + 1) + (unsigned char)(lastState) + SECUREC_FMT_STATE_OFFSET]); #endif } @@ -726,12 +782,12 @@ SECUREC_INLINE void SecDecodeFlags(SecChar ch, SecFormatAttr *attr) attr->flags |= SECUREC_FLAG_ALTERNATE; /* Output %x with 0x */ break; default: + /* Do nothing */ break; } return; } - /* * Decoded size identifier in format string to Reduce the number of lines of function code */ @@ -804,12 +860,12 @@ SECUREC_INLINE int SecDecodeSize(SecChar ch, SecFormatAttr *attr, const SecChar attr->flags |= SECUREC_FLAG_WIDECHAR; /* For wide char */ break; default: + /* Do nothing */ break; } return 0; } - /* * Decoded char type identifier */ @@ -822,7 +878,7 @@ SECUREC_INLINE void SecDecodeTypeC(SecFormatAttr *attr, unsigned int c) #endif #ifdef SECUREC_FOR_WCHAR - if (attr->flags & SECUREC_FLAG_SHORT) { + if ((attr->flags & SECUREC_FLAG_SHORT) != 0) { /* Get multibyte character from argument */ attr->buffer.str[0] = (char)c; attr->text.str = attr->buffer.str; @@ -833,7 +889,7 @@ SECUREC_INLINE void SecDecodeTypeC(SecFormatAttr *attr, unsigned int c) attr->textIsWide = 1; } #else /* Not SECUREC_FOR_WCHAR */ - if (attr->flags & (SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR)) { + if ((attr->flags & (SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR)) != 0) { #if SECUREC_HAVE_WCHART attr->buffer.wStr[0] = (wchar_t)c; attr->text.wStr = attr->buffer.wStr; @@ -894,7 +950,6 @@ SECUREC_INLINE void SecDecodeTypeSwchar(SecFormatAttr *attr) #endif } - /* * Decoded string identifier */ @@ -906,11 +961,11 @@ SECUREC_INLINE void SecDecodeTypeS(SecFormatAttr *attr, char *argPtr) attr->text.str = argPtr; #ifdef SECUREC_FOR_WCHAR #if defined(SECUREC_COMPATIBLE_LINUX_FORMAT) - if (!(attr->flags & SECUREC_FLAG_LONG)) { + if ((attr->flags & SECUREC_FLAG_LONG) == 0) { attr->flags |= SECUREC_FLAG_SHORT; } #endif - if (attr->flags & SECUREC_FLAG_SHORT) { + if ((attr->flags & SECUREC_FLAG_SHORT) != 0) { /* The textLen now contains length in multibyte chars */ SecDecodeTypeSchar(attr); } else { @@ -918,7 +973,7 @@ SECUREC_INLINE void SecDecodeTypeS(SecFormatAttr *attr, char *argPtr) SecDecodeTypeSwchar(attr); } #else /* SECUREC_FOR_WCHAR */ - if (attr->flags & (SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR)) { + if ((attr->flags & (SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR)) != 0) { /* The textLen now contains length in wide chars */ SecDecodeTypeSwchar(attr); } else { @@ -937,7 +992,8 @@ SECUREC_INLINE void SecDecodeTypeS(SecFormatAttr *attr, char *argPtr) SECUREC_INLINE void SecOutputOneChar(SecChar ch, SecPrintfStream *stream, int *counter) { /* Count must be reduced first, In order to identify insufficient length */ - if ((stream->count -= (int)(sizeof(SecChar))) >= 0) { + stream->count -= (int)(sizeof(SecChar)); + if (stream->count >= 0) { *((SecChar *)(void *)(stream->cur)) = (SecChar)ch; stream->cur += sizeof(SecChar); *counter = *(counter) + 1; @@ -970,7 +1026,6 @@ SECUREC_INLINE int SecDecodePrecision(SecChar ch, SecFormatAttr *attr) return 0; } - /* * Check width in format */ @@ -997,14 +1052,13 @@ SECUREC_INLINE int SecDecodeWidth(SecChar ch, SecFormatAttr *attr, SecFmtState l return 0; } - /* * The sprintf_s function processes the wide character as a parameter for %C * The swprintf_s function processes the multiple character as a parameter for %C */ SECUREC_INLINE void SecUpdateWcharFlags(SecFormatAttr *attr) { - if (!(attr->flags & (SECUREC_FLAG_SHORT | SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR))) { + if ((attr->flags & (SECUREC_FLAG_SHORT | SECUREC_FLAG_LONG | SECUREC_FLAG_WIDECHAR)) == 0) { #ifdef SECUREC_FOR_WCHAR attr->flags |= SECUREC_FLAG_SHORT; #else @@ -1028,7 +1082,7 @@ SECUREC_INLINE void SecUpdatePointFlagsForKernel(SecFormatAttr *attr) attr->flags |= SECUREC_FLAG_LEADZERO; attr->fldWidth = 2 * sizeof(void *); /* 2 x byte number is the length of hex */ } - if (attr->flags & SECUREC_FLAG_ALTERNATE) { + if ((attr->flags & SECUREC_FLAG_ALTERNATE) != 0) { /* Alternate form means '0x' prefix */ attr->prefix[0] = SECUREC_CHAR('0'); attr->prefix[1] = SECUREC_CHAR('x'); @@ -1075,7 +1129,7 @@ SECUREC_INLINE void SecUpdatePointFlags(SecFormatAttr *attr) attr->flags |= SECUREC_FLAG_LONG; /* Converting a long */ #endif /* Set up for %#p on different system */ - if (attr->flags & SECUREC_FLAG_ALTERNATE) { + if ((attr->flags & SECUREC_FLAG_ALTERNATE) != 0) { /* Alternate form means '0x' prefix */ attr->prefix[0] = SECUREC_CHAR('0'); #if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT) || defined(SECUREC_VXWORKS_PLATFORM)) @@ -1108,7 +1162,7 @@ SECUREC_INLINE void SecUpdateXpxFlags(SecFormatAttr *attr, SecChar ch) /* fall-through */ /* FALLTHRU */ default: /* For %#x or %#X */ - if (attr->flags & SECUREC_FLAG_ALTERNATE) { + if ((attr->flags & SECUREC_FLAG_ALTERNATE) != 0) { /* Alternate form means '0x' prefix */ attr->prefix[0] = SECUREC_CHAR('0'); attr->prefix[1] = (SecChar)(attr->digits[16]); /* 16 for 'x' or 'X' */ @@ -1134,12 +1188,13 @@ SECUREC_INLINE void SecUpdateOudiFlags(SecFormatAttr *attr, SecChar ch) /* For unsigned octal output */ attr->radix = SECUREC_RADIX_OCTAL; attr->digits = g_itoaLowerDigits; - if (attr->flags & SECUREC_FLAG_ALTERNATE) { + if ((attr->flags & SECUREC_FLAG_ALTERNATE) != 0) { /* Alternate form means force a leading 0 */ attr->flags |= SECUREC_FLAG_FORCE_OCTAL; } break; default: + /* Do nothing */ break; } } @@ -1178,7 +1233,6 @@ SECUREC_INLINE int SecInitFloatFmt(SecFloatAdapt *floatFmt, const SecChar *forma SecSeekToFrontPercent(&fmt); /* Now fmt point to '%' */ fmtStrLen = (int)(size_t)(format - fmt) + 1; /* With ending terminator */ - if (fmtStrLen > (int)sizeof(floatFmt->buffer)) { /* When buffer is NOT enough, alloc a new buffer */ floatFmt->allocatedFmtStr = (char *)SECUREC_MALLOC((size_t)((unsigned int)fmtStrLen)); @@ -1198,7 +1252,6 @@ SECUREC_INLINE int SecInitFloatFmt(SecFloatAdapt *floatFmt, const SecChar *forma floatFmt->fmtStr[fmtStrLen - 1] = '\0'; return 0; - } /* Init float buffer and format, return 0 is OK */ @@ -1215,7 +1268,7 @@ SECUREC_INLINE int SecInitFloatBuffer(SecFloatAdapt *floatAdapt, const SecChar * * Calc buffer size to store double value * The maximum length of SECUREC_MAX_WIDTH_LEN is enough */ - if (attr->flags & SECUREC_FLAG_LONG_DOUBLE) { + if ((attr->flags & SECUREC_FLAG_LONG_DOUBLE) != 0) { if (attr->precision > (SECUREC_MAX_WIDTH_LEN - SECUREC_FLOAT_BUFSIZE_LB)) { return -1; } @@ -1277,7 +1330,7 @@ SECUREC_INLINE void SecNumberSatisfyPrecision(SecFormatAttr *attr) #if defined(SECUREC_COMPATIBLE_WIN_FORMAT) attr->flags &= ~SECUREC_FLAG_LEADZERO; #else - if (!(attr->flags & SECUREC_FLAG_POINTER)) { + if ((attr->flags & SECUREC_FLAG_POINTER) == 0) { attr->flags &= ~SECUREC_FLAG_LEADZERO; } #endif @@ -1287,8 +1340,9 @@ SECUREC_INLINE void SecNumberSatisfyPrecision(SecFormatAttr *attr) precision = attr->precision; } while (attr->textLen < precision) { + --attr->text.str; + *(attr->text.str) = '0'; ++attr->textLen; - *(--attr->text.str) = '0'; } } @@ -1298,36 +1352,44 @@ SECUREC_INLINE void SecNumberSatisfyPrecision(SecFormatAttr *attr) SECUREC_INLINE void SecNumberForceOctal(SecFormatAttr *attr) { /* Force a leading zero if FORCEOCTAL flag set */ - if ((attr->flags & SECUREC_FLAG_FORCE_OCTAL) && + if ((attr->flags & SECUREC_FLAG_FORCE_OCTAL) != 0 && (attr->textLen == 0 || attr->text.str[0] != '0')) { - *(--attr->text.str) = '0'; + --attr->text.str; + *(attr->text.str) = '0'; ++attr->textLen; } } SECUREC_INLINE void SecUpdateSignedNumberPrefix(SecFormatAttr *attr) { - if (attr->flags & SECUREC_FLAG_SIGNED) { - if (attr->flags & SECUREC_FLAG_NEGATIVE) { - /* Prefix is '-' */ - attr->prefix[0] = SECUREC_CHAR('-'); - attr->prefixLen = 1; - } else if (attr->flags & SECUREC_FLAG_SIGN) { - /* Prefix is '+' */ - attr->prefix[0] = SECUREC_CHAR('+'); - attr->prefixLen = 1; - } else if (attr->flags & SECUREC_FLAG_SIGN_SPACE) { - /* Prefix is ' ' */ - attr->prefix[0] = SECUREC_CHAR(' '); - attr->prefixLen = 1; - } + if ((attr->flags & SECUREC_FLAG_SIGNED) == 0) { + return; + } + if ((attr->flags & SECUREC_FLAG_NEGATIVE) != 0) { + /* Prefix is '-' */ + attr->prefix[0] = SECUREC_CHAR('-'); + attr->prefixLen = 1; + return; + } + if ((attr->flags & SECUREC_FLAG_SIGN) != 0) { + /* Prefix is '+' */ + attr->prefix[0] = SECUREC_CHAR('+'); + attr->prefixLen = 1; + return; + } + if ((attr->flags & SECUREC_FLAG_SIGN_SPACE) != 0) { + /* Prefix is ' ' */ + attr->prefix[0] = SECUREC_CHAR(' '); + attr->prefixLen = 1; + return; } + return; } SECUREC_INLINE void SecNumberCompatZero(SecFormatAttr *attr) { #if SECUREC_IN_KERNEL - if (attr->flags & SECUREC_FLAG_POINTER) { + if ((attr->flags & SECUREC_FLAG_POINTER) != 0) { static char strNullPointer[SECUREC_NULL_STRING_SIZE] = "(null)"; attr->text.str = strNullPointer; attr->textLen = 6; /* Length of (null) is 6 */ @@ -1337,20 +1399,20 @@ SECUREC_INLINE void SecNumberCompatZero(SecFormatAttr *attr) attr->textLen = attr->precision; } } - if (!(attr->flags & SECUREC_FLAG_POINTER) && attr->radix == SECUREC_RADIX_HEX && - (attr->flags & SECUREC_FLAG_ALTERNATE)) { + if ((attr->flags & SECUREC_FLAG_POINTER) == 0 && attr->radix == SECUREC_RADIX_HEX && + (attr->flags & SECUREC_FLAG_ALTERNATE) != 0) { /* Add 0x prefix for %x or %X, the prefix string has been set before */ attr->prefixLen = SECUREC_PREFIX_LEN; } #elif defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && (!defined(SECUREC_ON_UNIX)) - if (attr->flags & SECUREC_FLAG_POINTER) { + if ((attr->flags & SECUREC_FLAG_POINTER) != 0) { static char strNullPointer[SECUREC_NULL_STRING_SIZE] = "(nil)"; attr->text.str = strNullPointer; attr->textLen = 5; /* Length of (nil) is 5 */ attr->flags &= ~SECUREC_FLAG_LEADZERO; } #elif defined(SECUREC_VXWORKS_PLATFORM) || defined(__hpux) - if ((attr->flags & SECUREC_FLAG_POINTER) && (attr->flags & SECUREC_FLAG_ALTERNATE)) { + if ((attr->flags & SECUREC_FLAG_POINTER) != 0 && (attr->flags & SECUREC_FLAG_ALTERNATE) != 0) { /* Add 0x prefix for %p, the prefix string has been set before */ attr->prefixLen = SECUREC_PREFIX_LEN; } @@ -1375,7 +1437,6 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l int charsOut; /* Characters written */ int noOutput = 0; /* Must be initialized or compiler alerts */ SecFmtState state; - SecChar ch; /* Currently read character */ SecFormatAttr formatAttr; formatAttr.flags = 0; @@ -1398,7 +1459,8 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l /* Loop each format character */ while (*format != SECUREC_CHAR('\0') && charsOut >= 0) { SecFmtState lastState = state; - ch = *(format++); + SecChar ch = *format; /* Currently read character */ + ++format; state = SecDecodeState(ch, lastState); switch (state) { case STAT_NORMAL: @@ -1422,7 +1484,6 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l break; case STAT_WIDTH: /* Update width value */ - formatAttr.dynWidth = 0; if (ch == SECUREC_CHAR('*')) { /* get width from arg list */ formatAttr.fldWidth = (int)va_arg(argList, int); @@ -1437,7 +1498,6 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l break; case STAT_PRECIS: /* Update precison value */ - formatAttr.dynPrecision = 0; if (ch == SECUREC_CHAR('*')) { /* Get precision from arg list */ formatAttr.precision = (int)va_arg(argList, int); @@ -1495,17 +1555,17 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l break; } - if (formatAttr.flags & SECUREC_FLAG_LONG_DOUBLE) { -#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT + if ((formatAttr.flags & SECUREC_FLAG_LONG_DOUBLE) != 0) { +#if defined(SECUREC_COMPATIBLE_LINUX_FORMAT) && SECUREC_ENABLE_SPRINTF_LONG_DOUBLE long double tmp = (long double)va_arg(argList, long double); - SecFormatLongDboule(&formatAttr, &floatAdapt, tmp); + SecFormatLongDouble(&formatAttr, &floatAdapt, tmp); #else double tmp = (double)va_arg(argList, double); - SecFormatDboule(&formatAttr, &floatAdapt, tmp); + SecFormatDouble(&formatAttr, &floatAdapt, tmp); #endif } else { double tmp = (double)va_arg(argList, double); - SecFormatDboule(&formatAttr, &floatAdapt, tmp); + SecFormatDouble(&formatAttr, &floatAdapt, tmp); } /* Only need write formated float string */ @@ -1516,7 +1576,6 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l return -1; #endif } - case SECUREC_CHAR('X'): /* fall-through */ /* FALLTHRU */ case SECUREC_CHAR('p'): /* fall-through */ /* FALLTHRU */ case SECUREC_CHAR('x'): /* fall-through */ /* FALLTHRU */ @@ -1528,55 +1587,26 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l case SECUREC_CHAR('o'): { SecInt64 num64; SecUpdateOudiFlags(&formatAttr, ch); - /* Read argument into variable num64 */ - if ((formatAttr.flags & SECUREC_FLAG_I64) || (formatAttr.flags & SECUREC_FLAG_LONGLONG)) { + /* Read argument into variable num64. Be careful, depend on the order of judgment */ + if ((formatAttr.flags & SECUREC_FLAG_I64) != 0 || + (formatAttr.flags & SECUREC_FLAG_LONGLONG) != 0) { num64 = (SecInt64)va_arg(argList, SecInt64); /* Maximum Bit Width sign bit unchanged */ - } else if (formatAttr.flags & SECUREC_FLAG_LONG) { - if (formatAttr.flags & SECUREC_FLAG_SIGNED) { - num64 = (long)va_arg(argList, long); /* Sign extend */ - } else { - num64 = (SecInt64)(unsigned long)va_arg(argList, long); /* Zero-extend */ - } - } else if (formatAttr.flags & SECUREC_FLAG_CHAR) { - if (formatAttr.flags & SECUREC_FLAG_SIGNED) { - char tmp = (char)va_arg(argList, int); /* Sign extend */ - num64 = SecUpdateNegativeChar(&formatAttr, tmp); - } else { - num64 = (SecInt64)(unsigned char)va_arg(argList, int); /* Zero-extend */ - } - } else if (formatAttr.flags & SECUREC_FLAG_SHORT) { - if (formatAttr.flags & SECUREC_FLAG_SIGNED) { - num64 = (short)va_arg(argList, int); /* Sign extend */ - } else { - num64 = (SecInt64)(unsigned short)va_arg(argList, int); /* Zero-extend */ - } - } + } else if ((formatAttr.flags & SECUREC_FLAG_LONG) != 0) { + num64 = SECUREC_GET_LONG_FROM_ARG(formatAttr); + } else if ((formatAttr.flags & SECUREC_FLAG_CHAR) != 0) { + num64 = SECUREC_GET_CHAR_FROM_ARG(formatAttr); + } else if ((formatAttr.flags & SECUREC_FLAG_SHORT) != 0) { + num64 = SECUREC_GET_SHORT_FROM_ARG(formatAttr); #ifdef SECUREC_COMPATIBLE_LINUX_FORMAT - else if (formatAttr.flags & SECUREC_FLAG_PTRDIFF) { + } else if ((formatAttr.flags & SECUREC_FLAG_PTRDIFF) != 0) { num64 = (ptrdiff_t)va_arg(argList, ptrdiff_t); /* Sign extend */ - } else if (formatAttr.flags & SECUREC_FLAG_SIZE) { - if (formatAttr.flags & SECUREC_FLAG_SIGNED) { - /* No suitable macros were found to handle the branch */ - if (SecIsSameSize(sizeof(size_t), sizeof(long))) { - num64 = va_arg(argList, long); /* Sign extend */ - } else if (SecIsSameSize(sizeof(size_t), sizeof(long long))) { - num64 = va_arg(argList, long long); /* Sign extend */ - } else { - num64 = va_arg(argList, int); /* Sign extend */ - } - } else { - num64 = (SecInt64)(size_t)va_arg(argList, size_t); /* Zero-extend */ - } - } else if (formatAttr.flags & SECUREC_FLAG_INTMAX) { + } else if ((formatAttr.flags & SECUREC_FLAG_SIZE) != 0) { + num64 = SECUREC_GET_SIZE_FROM_ARG(formatAttr); + } else if ((formatAttr.flags & SECUREC_FLAG_INTMAX) != 0) { num64 = (SecInt64)va_arg(argList, SecInt64); - } #endif - else { - if (formatAttr.flags & SECUREC_FLAG_SIGNED) { - num64 = va_arg(argList, int); /* Sign extend */ - } else { - num64 = (SecInt64)(unsigned int)va_arg(argList, int); /* Zero-extend */ - } + } else { + num64 = SECUREC_GET_INT_FROM_ARG(formatAttr); } /* The order of the following calls must be correct */ @@ -1590,6 +1620,7 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l break; } default: + /* Do nothing */ break; } @@ -1624,7 +1655,8 @@ SECUREC_INLINE int SecOutputS(SecPrintfStream *stream, const char *cFormat, va_l */ SECUREC_INLINE int SecPutZeroChar(SecPrintfStream *str) { - if (--(str->count) >= 0) { + --str->count; + if (str->count >= 0) { *(str->cur) = '\0'; str->cur = str->cur + 1; return 0; diff --git a/src/mapleall/huawei_secure_c/src/scanf_s.c b/third_party/bounds_checking_function/src/scanf_s.c similarity index 81% rename from src/mapleall/huawei_secure_c/src/scanf_s.c rename to third_party/bounds_checking_function/src/scanf_s.c index 69e830da399271f247b364129f32cb178123c3c7..0ae200e682e4a65bc9c2771c69ccf49a3f0a35b4 100644 --- a/src/mapleall/huawei_secure_c/src/scanf_s.c +++ b/third_party/bounds_checking_function/src/scanf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: scanf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h" @@ -50,4 +50,3 @@ int scanf_s(const char *format, ...) return ret; } - diff --git a/src/mapleall/huawei_secure_c/src/secinput.h b/third_party/bounds_checking_function/src/secinput.h similarity index 35% rename from src/mapleall/huawei_secure_c/src/secinput.h rename to third_party/bounds_checking_function/src/secinput.h index fc49bb0d7de4984f92a589a97f387281666fdc95..15c10451a1112723d884b47b871ad7ffed455a25 100644 --- a/src/mapleall/huawei_secure_c/src/secinput.h +++ b/third_party/bounds_checking_function/src/secinput.h @@ -1,16 +1,17 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: Define macro, data struct, and declare function prototype, + * which is used by input.inl, secureinput_a.c and secureinput_w.c. + * Author: lishunda + * Create: 2014-02-25 */ #ifndef SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C @@ -21,120 +22,116 @@ #define SECUREC_SCANF_ERROR_PARA (-2) /* For internal stream flag */ -#define SECUREC_MEM_STR_FLAG 0X01 -#define SECUREC_FILE_STREAM_FLAG 0X02 -#define SECUREC_PIPE_STREAM_FLAG 0X04 -#define SECUREC_LOAD_FILE_TO_MEM_FLAG 0X08 - -#define SECUREC_BOM_HEADER_SIZE 2 -#define SECUREC_BOM_HEADER_BE_1ST 0xFEU -#define SECUREC_BOM_HEADER_BE_2ST 0xFFU -#define SECUREC_BOM_HEADER_LE_1ST 0xFFU -#define SECUREC_BOM_HEADER_LE_2ST 0xFEU -#define SECUREC_UTF8_BOM_HEADER_SIZE 3 -#define SECUREC_UTF8_BOM_HEADER_1ST 0xEFU -#define SECUREC_UTF8_BOM_HEADER_2ND 0xBBU -#define SECUREC_UTF8_BOM_HEADER_3RD 0xBFU -#define SECUREC_UTF8_LEAD_1ST 0xE0 -#define SECUREC_UTF8_LEAD_2ND 0x80 +#define SECUREC_MEM_STR_FLAG 0x01U +#define SECUREC_FILE_STREAM_FLAG 0x02U +#define SECUREC_PIPE_STREAM_FLAG 0x04U +#define SECUREC_LOAD_FILE_TO_MEM_FLAG 0x08U + +#define SECUREC_UCS_BOM_HEADER_SIZE 2U +#define SECUREC_UCS_BOM_HEADER_BE_1ST 0xfeU +#define SECUREC_UCS_BOM_HEADER_BE_2ST 0xffU +#define SECUREC_UCS_BOM_HEADER_LE_1ST 0xffU +#define SECUREC_UCS_BOM_HEADER_LE_2ST 0xfeU +#define SECUREC_UTF8_BOM_HEADER_SIZE 3U +#define SECUREC_UTF8_BOM_HEADER_1ST 0xefU +#define SECUREC_UTF8_BOM_HEADER_2ND 0xbbU +#define SECUREC_UTF8_BOM_HEADER_3RD 0xbfU +#define SECUREC_UTF8_LEAD_1ST 0xe0U +#define SECUREC_UTF8_LEAD_2ND 0x80U + +#define SECUREC_BEGIN_WITH_UCS_BOM(s, len) ((len) >= SECUREC_UCS_BOM_HEADER_SIZE && \ + (((unsigned char)((s)[0]) == SECUREC_UCS_BOM_HEADER_LE_1ST && \ + (unsigned char)((s)[1]) == SECUREC_UCS_BOM_HEADER_LE_2ST) || \ + ((unsigned char)((s)[0]) == SECUREC_UCS_BOM_HEADER_BE_1ST && \ + (unsigned char)((s)[1]) == SECUREC_UCS_BOM_HEADER_BE_2ST))) + +#define SECUREC_BEGIN_WITH_UTF8_BOM(s, len) ((len) >= SECUREC_UTF8_BOM_HEADER_SIZE && \ + (unsigned char)((s)[0]) == SECUREC_UTF8_BOM_HEADER_1ST && \ + (unsigned char)((s)[1]) == SECUREC_UTF8_BOM_HEADER_2ND && \ + (unsigned char)((s)[2]) == SECUREC_UTF8_BOM_HEADER_3RD) + +#ifdef SECUREC_FOR_WCHAR +#define SECUREC_BOM_HEADER_SIZE SECUREC_UCS_BOM_HEADER_SIZE +#define SECUREC_BEGIN_WITH_BOM(s, len) SECUREC_BEGIN_WITH_UCS_BOM((s), (len)) +#else +#define SECUREC_BOM_HEADER_SIZE SECUREC_UTF8_BOM_HEADER_SIZE +#define SECUREC_BEGIN_WITH_BOM(s, len) SECUREC_BEGIN_WITH_UTF8_BOM((s), (len)) +#endif typedef struct { unsigned int flag; /* Mark the properties of input stream */ - int count; /* The size of buffered string in bytes */ - const char *cur; /* The pointer to next read position */ char *base; /* The pointer to the header of buffered string */ + const char *cur; /* The pointer to next read position */ + size_t count; /* The size of buffered string in bytes */ #if SECUREC_ENABLE_SCANF_FILE FILE *pf; /* The file pointer */ + size_t fileRealRead; long oriFilePos; /* The original position of file offset when fscanf is called */ - int fileRealRead; -#ifdef SECUREC_NO_STD_UNGETC +#if !SECUREC_USE_STD_UNGETC unsigned int lastChar; /* The char code of last input */ int fUnGet; /* The boolean flag of pushing a char back to read stream */ #endif #endif } SecFileStream; -#ifdef SECUREC_INLINE_INIT_FILE_STREAM_STR -/* - * This initialization for eliminating redundant initialization. - */ -SECUREC_INLINE void SecInitFileStreamFromString(SecFileStream *stream, const char *cur, int count) -{ - stream->flag = SECUREC_MEM_STR_FLAG; - stream->count = count; - stream->cur = cur; - stream->base = NULL; -#if SECUREC_ENABLE_SCANF_FILE - stream->pf = NULL; - stream->oriFilePos = 0; - stream->fileRealRead = 0; -#ifdef SECUREC_NO_STD_UNGETC - stream->lastChar = 0; - stream->fUnGet = 0; -#endif -#endif -} +#if SECUREC_ENABLE_SCANF_FILE && !SECUREC_USE_STD_UNGETC +#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp) do { \ + (stream)->pf = (fp); \ + (stream)->fileRealRead = 0; \ + (stream)->oriFilePos = 0; \ + (stream)->lastChar = 0; \ + (stream)->fUnGet = 0; \ +} SECUREC_WHILE_ZERO +#elif SECUREC_ENABLE_SCANF_FILE && SECUREC_USE_STD_UNGETC +#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp) do { \ + (stream)->pf = (fp); \ + (stream)->fileRealRead = 0; \ + (stream)->oriFilePos = 0; \ +} SECUREC_WHILE_ZERO +#else +/* Disable file */ +#define SECUREC_FILE_STREAM_INIT_FILE(stream, fp) #endif -#ifdef SECUREC_INLINE_INIT_FILE_STREAM_STDIN -/* - * This initialization for eliminating redundant initialization. - */ -SECUREC_INLINE void SecInitFileStreamFromStdin(SecFileStream *stream) -{ - stream->flag = SECUREC_PIPE_STREAM_FLAG; - stream->count = 0; - stream->cur = NULL; - stream->base = NULL; -#if SECUREC_ENABLE_SCANF_FILE - stream->pf = SECUREC_STREAM_STDIN; - stream->oriFilePos = 0; - stream->fileRealRead = 0; -#ifdef SECUREC_NO_STD_UNGETC - stream->lastChar = 0; - stream->fUnGet = 0; -#endif -#endif -} -#endif +/* This initialization for eliminating redundant initialization. */ +#define SECUREC_FILE_STREAM_FROM_STRING(stream, buf, cnt) do { \ + (stream)->flag = SECUREC_MEM_STR_FLAG; \ + (stream)->base = NULL; \ + (stream)->cur = (buf); \ + (stream)->count = (cnt); \ + SECUREC_FILE_STREAM_INIT_FILE((stream), NULL); \ +} SECUREC_WHILE_ZERO +/* This initialization for eliminating redundant initialization. */ +#define SECUREC_FILE_STREAM_FROM_FILE(stream, fp) do { \ + (stream)->flag = SECUREC_FILE_STREAM_FLAG; \ + (stream)->base = NULL; \ + (stream)->cur = NULL; \ + (stream)->count = 0; \ + SECUREC_FILE_STREAM_INIT_FILE((stream), (fp)); \ +} SECUREC_WHILE_ZERO -#ifdef SECUREC_INLINE_INIT_FILE_STREAM_FILE -/* - * This initialization for eliminating redundant initialization. - * Compared with the previous version initialization 0, - * the current code causes the binary size to increase by some bytes - */ -SECUREC_INLINE void SecInitFileStreamFromFile(SecFileStream *stream, FILE *file) -{ - stream->flag = SECUREC_FILE_STREAM_FLAG; - stream->count = 0; - stream->cur = NULL; - stream->base = NULL; -#if SECUREC_ENABLE_SCANF_FILE - stream->pf = file; - stream->oriFilePos = 0; - stream->fileRealRead = 0; -#ifdef SECUREC_NO_STD_UNGETC - stream->lastChar = 0; - stream->fUnGet = 0; -#endif -#endif -} -#endif +/* This initialization for eliminating redundant initialization. */ +#define SECUREC_FILE_STREAM_FROM_STDIN(stream) do { \ + (stream)->flag = SECUREC_PIPE_STREAM_FLAG; \ + (stream)->base = NULL; \ + (stream)->cur = NULL; \ + (stream)->count = 0; \ + SECUREC_FILE_STREAM_INIT_FILE((stream), SECUREC_STREAM_STDIN); \ +} SECUREC_WHILE_ZERO #ifdef __cplusplus extern "C" { #endif - - extern int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList); - extern void SecClearDestBuf(const char *buffer, const char *format, va_list argList); -#if SECUREC_IN_KERNEL == 0 - extern int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, va_list argList); - extern void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argList); + int SecInputS(SecFileStream *stream, const char *cFormat, va_list argList); + void SecClearDestBuf(const char *buffer, const char *format, va_list argList); +#ifdef SECUREC_FOR_WCHAR + int SecInputSW(SecFileStream *stream, const wchar_t *cFormat, va_list argList); + void SecClearDestBufW(const wchar_t *buffer, const wchar_t *format, va_list argList); #endif + /* 20150105 For software and hardware decoupling,such as UMG */ -#if defined(SECUREC_SYSAPI4VXWORKS) +#ifdef SECUREC_SYSAPI4VXWORKS #ifdef feof #undef feof #endif @@ -177,11 +174,21 @@ extern "C" { #ifdef __cplusplus } #endif -/* Reserved file operation macro interface */ +/* Reserved file operation macro interface, s is FILE *, i is fileno zero. */ +#ifndef SECUREC_LOCK_FILE #define SECUREC_LOCK_FILE(s) +#endif + +#ifndef SECUREC_UNLOCK_FILE #define SECUREC_UNLOCK_FILE(s) +#endif + +#ifndef SECUREC_LOCK_STDIN #define SECUREC_LOCK_STDIN(i, s) -#define SECUREC_UNLOCK_STDIN(i, s) #endif +#ifndef SECUREC_UNLOCK_STDIN +#define SECUREC_UNLOCK_STDIN(i, s) +#endif +#endif diff --git a/src/mapleall/huawei_secure_c/src/securecutil.c b/third_party/bounds_checking_function/src/securecutil.c similarity index 51% rename from src/mapleall/huawei_secure_c/src/securecutil.c rename to third_party/bounds_checking_function/src/securecutil.c index 025591c78936a1efdc5a567e5bb231f9e02f94ec..140cbf3c2dbd0f378e1dc295d31cee13d8933ce8 100644 --- a/src/mapleall/huawei_secure_c/src/securecutil.c +++ b/third_party/bounds_checking_function/src/securecutil.c @@ -1,16 +1,18 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: Provides internal functions used by this library, such as memory + * copy and memory move. Besides, include some helper function for + * printf family API, such as SecVsnprintfImpl + * Author: lishunda + * Create: 2014-02-25 */ /* Avoid duplicate header files,not include securecutil.h */ @@ -39,24 +41,28 @@ int mbtowc(wchar_t *pwc, const char *s, size_t n) #endif #endif -/* The V100R001C01 version num is 0x5 */ -#define SECUREC_C_VERSION (0x5 << 8) -#define SECUREC_SPC_VERSION 9 -#define SECUREC_VERSION_STR "Huawei Secure C V100R001C01SPC009B003" +/* The V100R001C01 version num is 0x5 (High 8 bits) */ +#define SECUREC_C_VERSION 0x500U +#define SECUREC_SPC_VERSION 0xaU +#define SECUREC_VERSION_STR "V100R001C01SPC010B002" /* - * SPC verNumber<->verStr like: - * 0X201<->C01 - * 0X202<->SPC001 Redefine numbers after this version - * 0X502<->SPC002 - * 0X503<->SPC003 + * Get version string and version number. + * The rules for version number are as follows: + * 1) SPC verNumber<->verStr like: + * 0x201<->C01 + * 0x202<->C01SPC001 Redefine numbers after this version + * 0x502<->C01SPC002 + * 0x503<->C01SPC003 * ... * 0X50a<->SPC010 * 0X50b<->SPC011 * ... - */ -/* - * CP verNumber<->verStr like: + * 0x700<->C02 + * 0x701<->C01SPC001 + * 0x702<->C02SPC002 + * ... + * 2) CP verNumber<->verStr like: * 0X601<->CP0001 * 0X602<->CP0002 * ... diff --git a/src/mapleall/huawei_secure_c/src/securecutil.h b/third_party/bounds_checking_function/src/securecutil.h similarity index 85% rename from src/mapleall/huawei_secure_c/src/securecutil.h rename to third_party/bounds_checking_function/src/securecutil.h index 6f459991ad072fd5db19af62d9a5f4fb46ccf195..38cbd3e61ee3341bbf905402899ad37c6abe7181 100644 --- a/src/mapleall/huawei_secure_c/src/securecutil.h +++ b/third_party/bounds_checking_function/src/securecutil.h @@ -1,16 +1,17 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: Define macro, data struct, and declare internal used function prototype, + * which is used by secure functions. + * Author: lishunda + * Create: 2014-02-25 */ #ifndef SECURECUTIL_H_46C86578_F8FF_4E49_8E64_9B175241761F @@ -88,13 +89,17 @@ #endif #endif +#ifndef SECUREC_USE_STD_UNGETC +#define SECUREC_USE_STD_UNGETC 1 +#endif + #ifndef SECUREC_ENABLE_INLINE #define SECUREC_ENABLE_INLINE 0 #endif #ifndef SECUREC_INLINE #if SECUREC_ENABLE_INLINE -#define SECUREC_INLINE inline static +#define SECUREC_INLINE static inline #else #define SECUREC_INLINE static #endif @@ -112,13 +117,12 @@ #define SECUREC_STREAM_STDIN stdin #endif -#define SECUREC_INT_MAX 2147483647 -#define SECUREC_MUL_SIXTEEN(x) ((x) << 4) -#define SECUREC_MUL_EIGHT(x) ((x) << 3) -#define SECUREC_MUL_TEN(x) ((((x) << 2) + (x)) << 1) -/* Limited format input and output width */ +#define SECUREC_MUL_SIXTEEN(x) ((x) << 4U) +#define SECUREC_MUL_EIGHT(x) ((x) << 3U) +#define SECUREC_MUL_TEN(x) ((((x) << 2U) + (x)) << 1U) +/* Limited format input and output width, use signed integer */ #define SECUREC_MAX_WIDTH_LEN_DIV_TEN 21474836 -#define SECUREC_MAX_WIDTH_LEN SECUREC_MUL_TEN(SECUREC_MAX_WIDTH_LEN_DIV_TEN) +#define SECUREC_MAX_WIDTH_LEN (SECUREC_MAX_WIDTH_LEN_DIV_TEN * 10) /* Is the x multiplied by 10 greater than */ #define SECUREC_MUL_TEN_ADD_BEYOND_MAX(x) (((x) > SECUREC_MAX_WIDTH_LEN_DIV_TEN)) @@ -159,7 +163,6 @@ (((dest) < (src) && ((dest) + (destLen) + (srcLen)) >= (src)) || \ ((src) < (dest) && ((src) + (srcLen)) >= (dest))) - #if SECUREC_HAVE_STRNLEN #define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \ *(outLen) = strnlen((str), (maxLen)); \ @@ -196,34 +199,53 @@ } SECUREC_WHILE_ZERO #else #define SECUREC_CALC_STR_LEN(str, maxLen, outLen) do { \ - const char *strEnd = (const char *)(str); \ - size_t availableSize = (size_t)(maxLen); \ - while (availableSize > 0 && *strEnd != '\0') { \ - --availableSize; \ - ++strEnd; \ + const char *strEnd_ = (const char *)(str); \ + size_t availableSize_ = (size_t)(maxLen); \ + while (availableSize_ > 0 && *strEnd_ != '\0') { \ + --availableSize_; \ + ++strEnd_; \ } \ - *(outLen) = (size_t)(strEnd - (str)); \ + *(outLen) = (size_t)(strEnd_ - (str)); \ } SECUREC_WHILE_ZERO #define SECUREC_CALC_STR_LEN_OPT SECUREC_CALC_STR_LEN #endif #define SECUREC_CALC_WSTR_LEN(str, maxLen, outLen) do { \ - const wchar_t *strEnd = (const wchar_t *)(str); \ - size_t len = 0; \ - while (len < (maxLen) && *strEnd != L'\0') { \ - ++len; \ - ++strEnd; \ + const wchar_t *strEnd_ = (const wchar_t *)(str); \ + size_t len_ = 0; \ + while (len_ < (maxLen) && *strEnd_ != L'\0') { \ + ++len_; \ + ++strEnd_; \ } \ - *(outLen) = len; \ + *(outLen) = len_; \ } SECUREC_WHILE_ZERO -/* Performance optimization, product may disable inline function */ +/* + * Performance optimization, product may disable inline function. + * Using function pointer for MEMSET to prevent compiler optimization when cleaning up memory. + */ #ifdef SECUREC_USE_ASM -#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)memcpy_opt((dest), (src), (count)) -#define SECUREC_MEMSET_WARP_OPT(dest, c, count) (void)memset_opt((dest), (c), (count)) +#define SECUREC_MEMSET_FUNC_OPT memset_opt +#define SECUREC_MEMCPY_FUNC_OPT memcpy_opt #else -#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)memcpy((dest), (src), (count)) -#define SECUREC_MEMSET_WARP_OPT(dest, c, count) (void)memset((dest), (c), (count)) +#define SECUREC_MEMSET_FUNC_OPT memset +#define SECUREC_MEMCPY_FUNC_OPT memcpy +#endif + +#define SECUREC_MEMCPY_WARP_OPT(dest, src, count) (void)SECUREC_MEMCPY_FUNC_OPT((dest), (src), (count)) + +#ifndef SECUREC_MEMSET_INDIRECT_USE +/* Can be turned off for scenarios that do not allow pointer calls */ +#define SECUREC_MEMSET_INDIRECT_USE 1 +#endif + +#if SECUREC_MEMSET_INDIRECT_USE +#define SECUREC_MEMSET_WARP_OPT(dest, value, count) do { \ + void *(* const volatile fn_)(void *s_, int c_, size_t n_) = SECUREC_MEMSET_FUNC_OPT; \ + (void)(*fn_)((dest), (value), (count)); \ +} SECUREC_WHILE_ZERO +#else +#define SECUREC_MEMSET_WARP_OPT(dest, value, count) (void)SECUREC_MEMSET_FUNC_OPT((dest), (value), (count)) #endif #ifdef SECUREC_FORMAT_OUTPUT_INPUT @@ -248,11 +270,13 @@ typedef wchar_t wint_t; #ifndef WEOF #define WEOF ((wchar_t)(-1)) #endif +#define SECUREC_CHAR(x) L ## x typedef wchar_t SecChar; typedef wchar_t SecUnsignedChar; typedef wint_t SecInt; typedef wint_t SecUnsignedInt; #else /* no SECUREC_FOR_WCHAR */ +#define SECUREC_CHAR(x) (x) typedef char SecChar; typedef unsigned char SecUnsignedChar; typedef int SecInt; @@ -264,7 +288,7 @@ typedef unsigned int SecUnsignedInt; * Determine whether the address is 8-byte aligned * Some systems do not have uintptr_t type, so use NULL to clear tool alarm 507 */ -#define SECUREC_ADDR_ALIGNED_8(addr) ((((size_t)(addr)) & 7) == 0) /* Use 7 to check aligned 8 */ +#define SECUREC_ADDR_ALIGNED_8(addr) ((((size_t)(addr)) & 7U) == 0) /* Use 7 to check aligned 8 */ /* * If you define the memory allocation function, you need to define the function prototype. @@ -282,10 +306,11 @@ SECUREC_MALLOC_PROTOTYPE #define SECUREC_FREE(x) free((void *)(x)) #endif -/* Struct for performance */ -typedef struct { - unsigned char buf[1]; /* Performance optimization code structure assignment length 1 bytes */ -} SecStrBuf1; +/* Improve performance with struct assignment, buf1 is not defined to avoid tool false positive */ +#define SECUREC_COPY_VALUE_BY_STRUCT(dest, src, n) do { \ + *(SecStrBuf##n *)(void *)(dest) = *(const SecStrBuf##n *)(const void *)(src); \ +} SECUREC_WHILE_ZERO + typedef struct { unsigned char buf[2]; /* Performance optimization code structure assignment length 2 bytes */ } SecStrBuf2; @@ -476,9 +501,6 @@ typedef struct { unsigned char buf[64]; /* Performance optimization code structure assignment length 64 bytes */ } SecStrBuf64; - - - /* * User can change the error handler by modify the following definition, * such as logging the detail error in file. @@ -507,28 +529,27 @@ typedef struct { /* Default handler is none */ #ifndef SECUREC_ERROR_INVALID_PARAMTER -#define SECUREC_ERROR_INVALID_PARAMTER(msg) ((void)0) +#define SECUREC_ERROR_INVALID_PARAMTER(msg) #endif #ifndef SECUREC_ERROR_INVALID_RANGE -#define SECUREC_ERROR_INVALID_RANGE(msg) ((void)0) +#define SECUREC_ERROR_INVALID_RANGE(msg) #endif #ifndef SECUREC_ERROR_BUFFER_OVERLAP -#define SECUREC_ERROR_BUFFER_OVERLAP(msg) ((void)0) +#define SECUREC_ERROR_BUFFER_OVERLAP(msg) #endif - #ifdef __cplusplus extern "C" { #endif /* Assembly language memory copy and memory set for X86 or MIPS ... */ #ifdef SECUREC_USE_ASM - extern void *memcpy_opt(void *, const void *, size_t); - extern void *memset_opt(void *, int, size_t); + void *memcpy_opt(void *dest, const void *src, size_t n); + void *memset_opt(void *s, int c, size_t n); #endif #if defined(SECUREC_ERROR_HANDLER_BY_FILE_LOG) - extern void LogSecureCRuntimeError(const char *errDetail); + void LogSecureCRuntimeError(const char *errDetail); #endif #ifdef __cplusplus diff --git a/src/mapleall/huawei_secure_c/src/secureinput_a.c b/third_party/bounds_checking_function/src/secureinput_a.c similarity index 38% rename from src/mapleall/huawei_secure_c/src/secureinput_a.c rename to third_party/bounds_checking_function/src/secureinput_a.c index 1f2edb81380b49f077dbbbf66ec00630ec05d86a..10b7f3571b8fc630e129ad7080c694439e3993d9 100644 --- a/src/mapleall/huawei_secure_c/src/secureinput_a.c +++ b/third_party/bounds_checking_function/src/secureinput_a.c @@ -1,17 +1,19 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: By defining data type for ANSI string and including "input.inl", + * this file generates real underlying function used by scanf family API. + * Author: lishunda + * Create: 2014-02-25 */ + #define SECUREC_FORMAT_OUTPUT_INPUT 1 #ifdef SECUREC_FOR_WCHAR #undef SECUREC_FOR_WCHAR @@ -23,15 +25,15 @@ SECUREC_INLINE int SecIsDigit(SecInt ch) { - /* SecInt to unsigned char clear 571 */ - return isdigit((unsigned char)(ch) & 0x00ff); + /* SecInt to unsigned char clear 571, use bit mask to clear negative return of ch */ + return isdigit((int)((unsigned int)(unsigned char)(ch) & 0xffU)); } SECUREC_INLINE int SecIsXdigit(SecInt ch) { - return isxdigit((unsigned char)(ch) & 0x00ff); + return isxdigit((int)((unsigned int)(unsigned char)(ch) & 0xffU)); } SECUREC_INLINE int SecIsSpace(SecInt ch) { - return isspace((unsigned char)(ch) & 0x00ff); + return isspace((int)((unsigned int)(unsigned char)(ch) & 0xffU)); } diff --git a/src/mapleall/huawei_secure_c/src/secureinput_w.c b/third_party/bounds_checking_function/src/secureinput_w.c similarity index 53% rename from src/mapleall/huawei_secure_c/src/secureinput_w.c rename to third_party/bounds_checking_function/src/secureinput_w.c index 21b22fc378fd4327f6c7fbc683632192c28b5e21..79955794edc9b7a1341eab1eeba2855297a48e7f 100644 --- a/src/mapleall/huawei_secure_c/src/secureinput_w.c +++ b/third_party/bounds_checking_function/src/secureinput_w.c @@ -1,16 +1,17 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: By defining data type for UNICODE string and including "input.inl", + * this file generates real underlying function used by scanf family API. + * Author: lishunda + * Create: 2014-02-25 */ /* If some platforms don't have wchar.h, dont't include it */ @@ -40,19 +41,36 @@ #include "input.inl" -SECUREC_INLINE int SecIsDigit(SecInt ch) +SECUREC_INLINE unsigned int SecWcharHighBits(SecInt ch) { /* Convert int to unsigned int clear 571 */ - return (!((unsigned int)(int)(ch) & 0xff00) && isdigit(((unsigned int)(int)(ch) & 0x00ff))); + return ((unsigned int)(int)ch & (~0xffU)); } + +SECUREC_INLINE unsigned char SecWcharLowByte(SecInt ch) +{ + /* Convert int to unsigned int clear 571 */ + return (unsigned char)((unsigned int)(int)ch & 0xffU); +} + +SECUREC_INLINE int SecIsDigit(SecInt ch) +{ + if (SecWcharHighBits(ch) != 0) { + return 0; /* Same as isdigit */ + } + return isdigit((int)SecWcharLowByte(ch)); +} + SECUREC_INLINE int SecIsXdigit(SecInt ch) { - return (!((unsigned int)(int)(ch) & 0xff00) && isxdigit(((unsigned int)(int)(ch) & 0x00ff))); + if (SecWcharHighBits(ch) != 0) { + return 0; /* Same as isxdigit */ + } + return isxdigit((int)SecWcharLowByte(ch)); } + SECUREC_INLINE int SecIsSpace(SecInt ch) { return iswspace((wint_t)(int)(ch)); } - - diff --git a/src/mapleall/huawei_secure_c/src/secureprintoutput.h b/third_party/bounds_checking_function/src/secureprintoutput.h similarity index 82% rename from src/mapleall/huawei_secure_c/src/secureprintoutput.h rename to third_party/bounds_checking_function/src/secureprintoutput.h index 83c9f1903a098b29e5a07f0159c5b0f13fccfcb4..843217ae0f7b5304c7fd3efde78e5f909d187051 100644 --- a/src/mapleall/huawei_secure_c/src/secureprintoutput.h +++ b/third_party/bounds_checking_function/src/secureprintoutput.h @@ -1,16 +1,18 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: Define macro, enum, data struct, and declare internal used function + * prototype, which is used by output.inl, secureprintoutput_w.c and + * secureprintoutput_a.c. + * Author: lishunda + * Create: 2014-02-25 */ #ifndef SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C @@ -62,7 +64,6 @@ typedef struct { char *cur; } SecPrintfStream; - #ifndef SECUREC_BUFFER_SIZE #if SECUREC_IN_KERNEL #define SECUREC_BUFFER_SIZE 32 @@ -82,7 +83,6 @@ typedef struct { /* Buffer size for wchar, use 4 to make the compiler aligns as 8 bytes as possible */ #define SECUREC_WCHAR_BUFFER_SIZE 4 - #define SECUREC_MAX_PRECISION SECUREC_BUFFER_SIZE /* Max. # bytes in multibyte char ,see MB_LEN_MAX */ #define SECUREC_MB_LEN 16 @@ -109,13 +109,12 @@ typedef struct { ((count) > (SECUREC_STRING_MAX_LEN - 1))) #endif - #ifdef __cplusplus extern "C" { #endif - extern int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList); -#if SECUREC_IN_KERNEL == 0 - extern int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList); + int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList); +#ifdef SECUREC_FOR_WCHAR + int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList); #endif #ifdef __cplusplus } @@ -123,4 +122,3 @@ extern "C" { #endif - diff --git a/src/mapleall/huawei_secure_c/src/secureprintoutput_a.c b/third_party/bounds_checking_function/src/secureprintoutput_a.c similarity index 57% rename from src/mapleall/huawei_secure_c/src/secureprintoutput_a.c rename to third_party/bounds_checking_function/src/secureprintoutput_a.c index ab41568cce6425feb4feb1676a633545cc680bc6..64762c06775b760e278aee850081cf291f3b3255 100644 --- a/src/mapleall/huawei_secure_c/src/secureprintoutput_a.c +++ b/third_party/bounds_checking_function/src/secureprintoutput_a.c @@ -1,16 +1,17 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: By defining corresponding macro for ANSI string and including "output.inl", + * this file generates real underlying function used by printf family API. + * Author: lishunda + * Create: 2014-02-25 */ #define SECUREC_FORMAT_OUTPUT_INPUT 1 @@ -22,29 +23,28 @@ #include "secureprintoutput.h" #if SECUREC_WARP_OUTPUT #define SECUREC_FORMAT_FLAG_TABLE_SIZE 128 -static const unsigned char g_flagTable[SECUREC_FORMAT_FLAG_TABLE_SIZE] = { - /* - * Known flag is "0123456789 +-#hlLwZzjqt*I" - */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - SECUREC_INLINE const char *SecSkipKnownFlags(const char *format) { + static const unsigned char flagTable[SECUREC_FORMAT_FLAG_TABLE_SIZE] = { + /* + * Known flag is "0123456789 +-#hlLwZzjqt*I$" + */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 + }; const char *fmt = format; while (*fmt != '\0') { char fmtChar = *fmt; if ((unsigned char)fmtChar > 0x7f) { /* 0x7f is upper limit of format char value */ break; } - if (g_flagTable[(unsigned char)fmtChar] == 0) { + if (flagTable[(unsigned char)fmtChar] == 0) { break; } ++fmt; @@ -80,7 +80,7 @@ SECUREC_INLINE int SecFormatContainN(const char *format) int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList) { int retVal; - if (SecFormatContainN(format)) { + if (SecFormatContainN(format) != 0) { string[0] = '\0'; return -1; } @@ -89,7 +89,8 @@ int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list arg /* The buffer was too small; we return truncation */ string[count - 1] = '\0'; return SECUREC_PRINTF_TRUNCATE; - } else if (retVal < 0) { + } + if (retVal < 0) { string[0] = '\0'; /* Empty the dest strDest */ return -1; } @@ -100,17 +101,10 @@ int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list arg #include #endif -#define SECUREC_CHAR(x) x -#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiChar -#define SECUREC_WRITE_STRING SecWriteString - #ifndef EOF #define EOF (-1) #endif -SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten); -SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten); - #include "output.inl" /* @@ -125,14 +119,17 @@ int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list arg str.cur = string; retVal = SecOutputS(&str, format, argList); - if (retVal >= 0 && SecPutZeroChar(&str) == 0) { - return retVal; - } else if (str.count < 0) { - /* The buffer was too small; we return truncation */ + if (retVal >= 0) { + if (SecPutZeroChar(&str) == 0) { + return retVal; + } + } + if (str.count < 0) { + /* The buffer was too small, then truncate */ string[count - 1] = '\0'; return SECUREC_PRINTF_TRUNCATE; } - string[0] = '\0'; /* Empty the dest strDest */ + string[0] = '\0'; /* Empty the dest string */ return -1; } @@ -141,15 +138,17 @@ int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list arg */ SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int *pnumwritten) { - int count = num; - while (count-- > 0 && --(f->count) >= 0) { + int count; + for (count = num; count > 0; --count) { + --f->count; /* f -> count may be negative,indicating insufficient space */ + if (f->count < 0) { + *pnumwritten = -1; + return; + } *(f->cur) = ch; - ++(f->cur); + ++f->cur; *pnumwritten = *pnumwritten + 1; } - if (f->count < 0) { - *pnumwritten = -1; - } } /* @@ -158,16 +157,18 @@ SECUREC_INLINE void SecWriteMultiChar(char ch, int num, SecPrintfStream *f, int SECUREC_INLINE void SecWriteString(const char *string, int len, SecPrintfStream *f, int *pnumwritten) { const char *str = string; - int count = len; - while (count-- > 0 && --(f->count) >= 0) { + int count; + for (count = len; count > 0; --count) { + --f->count; /* f -> count may be negative,indicating insufficient space */ + if (f->count < 0) { + *pnumwritten = -1; + return; + } *(f->cur) = *str; - ++(f->cur); + ++f->cur; ++str; } *pnumwritten = *pnumwritten + (int)(size_t)(str - string); - if (f->count < 0) { - *pnumwritten = -1; - } } #endif diff --git a/src/mapleall/huawei_secure_c/src/secureprintoutput_w.c b/third_party/bounds_checking_function/src/secureprintoutput_w.c similarity index 72% rename from src/mapleall/huawei_secure_c/src/secureprintoutput_w.c rename to third_party/bounds_checking_function/src/secureprintoutput_w.c index 726299148e3f5d0be841e54f19e50c64d785b1e3..4d06a64a37ee4fcf0f4499a4daa260b18af8931a 100644 --- a/src/mapleall/huawei_secure_c/src/secureprintoutput_w.c +++ b/third_party/bounds_checking_function/src/secureprintoutput_w.c @@ -1,16 +1,17 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: By defining corresponding macro for UNICODE string and including "output.inl", + * this file generates real underlying function used by printf family API. + * Author: lishunda + * Create: 2014-02-25 */ /* If some platforms don't have wchar.h, dont't include it */ @@ -42,17 +43,9 @@ #include "secureprintoutput.h" - -#define SECUREC_CHAR(x) L ## x -#define SECUREC_WRITE_MULTI_CHAR SecWriteMultiCharW -#define SECUREC_WRITE_STRING SecWriteStringW - SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritten); -SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten); -SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten); SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount); - #include "output.inl" /* @@ -68,41 +61,41 @@ int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, str.count = (int)(sizeInWchar * sizeof(wchar_t)); retVal = SecOutputSW(&str, format, argList); - if (retVal >= 0 && SecPutWcharStrEndingZero(&str, (int)sizeof(wchar_t)) == 0) { - return (retVal); - } else if (str.count < 0) { - /* The buffer was too small; we return truncation */ + if (retVal >= 0) { + if (SecPutWcharStrEndingZero(&str, (int)sizeof(wchar_t)) == 0) { + return retVal; + } + } + if (str.count < 0) { + /* The buffer was too small, then truncate */ string[sizeInWchar - 1] = L'\0'; return SECUREC_PRINTF_TRUNCATE; } - string[0] = L'\0'; + string[0] = L'\0'; /* Empty the dest string */ return -1; } - - /* * Output a wide character zero end into the SecPrintfStream structure */ SECUREC_INLINE int SecPutWcharStrEndingZero(SecPrintfStream *str, int zeroCount) { - int i = 0; - while (i < zeroCount && SecPutZeroChar(str) == 0) { - ++i; - } - if (i == zeroCount) { - return 0; + int count; + for (count = zeroCount; count > 0; --count) { + if (SecPutZeroChar(str) != 0) { + return -1; + } } - return -1; + return 0; } - /* * Output a wide character into the SecPrintfStream structure */ SECUREC_INLINE int SecPutCharW(wchar_t ch, SecPrintfStream *f) { - if (((f)->count -= (int)sizeof(wchar_t)) >= 0) { + f->count -= (int)sizeof(wchar_t); /* f -> count may be negative,indicating insufficient space */ + if (f->count >= 0) { *(wchar_t *)(void *)(f->cur) = ch; f->cur += sizeof(wchar_t); return 0; @@ -127,8 +120,8 @@ SECUREC_INLINE void SecWriteCharW(wchar_t ch, SecPrintfStream *f, int *pnumwritt */ SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, int *pnumwritten) { - int count = num; - while (count-- > 0) { + int count; + for (count = num; count > 0; --count) { SecWriteCharW(ch, f, pnumwritten); if (*pnumwritten == -1) { break; @@ -142,8 +135,8 @@ SECUREC_INLINE void SecWriteMultiCharW(wchar_t ch, int num, SecPrintfStream *f, SECUREC_INLINE void SecWriteStringW(const wchar_t *string, int len, SecPrintfStream *f, int *pnumwritten) { const wchar_t *str = string; - int count = len; - while (count-- > 0) { + int count; + for (count = len; count > 0; --count) { SecWriteCharW(*str, f, pnumwritten); ++str; if (*pnumwritten == -1) { diff --git a/src/mapleall/huawei_secure_c/src/snprintf_s.c b/third_party/bounds_checking_function/src/snprintf_s.c similarity index 91% rename from src/mapleall/huawei_secure_c/src/snprintf_s.c rename to third_party/bounds_checking_function/src/snprintf_s.c index 377ab299c87def141744e888aeb6ae96933af47b..491c0a8d27ab0eeb201a29603801bcd4bf89c851 100644 --- a/src/mapleall/huawei_secure_c/src/snprintf_s.c +++ b/third_party/bounds_checking_function/src/snprintf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: snprintf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h" @@ -109,4 +109,3 @@ EXPORT_SYMBOL(snprintf_truncated_s); #endif - diff --git a/src/mapleall/huawei_secure_c/src/sprintf_s.c b/third_party/bounds_checking_function/src/sprintf_s.c similarity index 83% rename from src/mapleall/huawei_secure_c/src/sprintf_s.c rename to third_party/bounds_checking_function/src/sprintf_s.c index 69b2cac68fe89e70a9fa8a02029a20c559cb9d02..95b448586c5c265d7ce9c55d4f1b6bbba249f521 100644 --- a/src/mapleall/huawei_secure_c/src/sprintf_s.c +++ b/third_party/bounds_checking_function/src/sprintf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: sprintf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h" @@ -57,4 +57,3 @@ int sprintf_s(char *strDest, size_t destMax, const char *format, ...) EXPORT_SYMBOL(sprintf_s); #endif - diff --git a/src/mapleall/huawei_secure_c/src/sscanf_s.c b/third_party/bounds_checking_function/src/sscanf_s.c similarity index 83% rename from src/mapleall/huawei_secure_c/src/sscanf_s.c rename to third_party/bounds_checking_function/src/sscanf_s.c index bd9458db9f1dcaf77bda8df19068cb46db863ff0..ba5680f03329f9dfd4471e76e99baa38b1655088 100644 --- a/src/mapleall/huawei_secure_c/src/sscanf_s.c +++ b/third_party/bounds_checking_function/src/sscanf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: sscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h" @@ -57,4 +57,3 @@ int sscanf_s(const char *buffer, const char *format, ...) EXPORT_SYMBOL(sscanf_s); #endif - diff --git a/src/mapleall/huawei_secure_c/src/strcat_s.c b/third_party/bounds_checking_function/src/strcat_s.c similarity index 70% rename from src/mapleall/huawei_secure_c/src/strcat_s.c rename to third_party/bounds_checking_function/src/strcat_s.c index b90d0616d6737229dbaa335ef50f07a24a7176d7..05c1c3230f6c8375ddfa4e64ad094bae0e1342c4 100644 --- a/src/mapleall/huawei_secure_c/src/strcat_s.c +++ b/third_party/bounds_checking_function/src/strcat_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: strcat_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" @@ -52,18 +52,18 @@ SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, const char *strSr /* * - * The strcat_s function appends a copy of the string pointed to by strSrc (including the terminating null character) - * to the end of the string pointed to by strDest. - * The initial character of strSrc overwrites the terminating null character of strDest. - * strcat_s will return EOVERLAP_AND_RESET if the source and destination strings overlap. + * The strcat_s function appends a copy of the string pointed to by strSrc (including the terminating null character) + * to the end of the string pointed to by strDest. + * The initial character of strSrc overwrites the terminating null character of strDest. + * strcat_s will return EOVERLAP_AND_RESET if the source and destination strings overlap. * - * Note that the second parameter is the total size of the buffer, not the - * remaining size. + * Note that the second parameter is the total size of the buffer, not the + * remaining size. * * - * strDest Null-terminated destination string buffer. - * destMax Size of the destination string buffer. - * strSrc Null-terminated source string buffer. + * strDest Null-terminated destination string buffer. + * destMax Size of the destination string buffer. + * strSrc Null-terminated source string buffer. * * * strDest is updated @@ -71,8 +71,8 @@ SECUREC_INLINE errno_t SecDoCat(char *strDest, size_t destMax, const char *strSr * * EOK Success * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN - * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid)or - * (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN) + * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or + * (strDest != NULL and strSrc is NULL and destMax != 0 and destMax <= SECUREC_STRING_MAX_LEN) * ERANGE destMax is 0 and destMax > SECUREC_STRING_MAX_LEN * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid diff --git a/src/mapleall/huawei_secure_c/src/strcpy_s.c b/third_party/bounds_checking_function/src/strcpy_s.c similarity index 58% rename from src/mapleall/huawei_secure_c/src/strcpy_s.c rename to third_party/bounds_checking_function/src/strcpy_s.c index b53dd59b516c7b41832adc500daad5e4a54bcc8c..e7921eae1b4ff857a81806b5938de414fcdcc672 100644 --- a/src/mapleall/huawei_secure_c/src/strcpy_s.c +++ b/third_party/bounds_checking_function/src/strcpy_s.c @@ -1,21 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. - */ -/* - * [Standardize-exceptions] Use unsafe function: Performance-sensitive - * [reason] Always used in the performance critical path, - * and sufficient input validation is performed before calling + * Description: strcpy_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" @@ -24,226 +19,227 @@ #define SECUREC_STRCPY_WITH_PERFORMANCE 1 #endif -#if (SECUREC_IN_KERNEL == 0) && SECUREC_STRCPY_WITH_PERFORMANCE +#define SECUREC_STRCPY_PARAM_OK(strDest, destMax, strSrc) ((destMax) > 0 && \ + (destMax) <= SECUREC_STRING_MAX_LEN && (strDest) != NULL && (strSrc) != NULL && (strDest) != (strSrc)) + +#if (!SECUREC_IN_KERNEL) && SECUREC_STRCPY_WITH_PERFORMANCE #ifndef SECUREC_STRCOPY_THRESHOLD_SIZE #define SECUREC_STRCOPY_THRESHOLD_SIZE 32UL #endif - - /* The purpose of converting to void is to clean up the alarm */ -#define SECUREC_SMALL_STR_COPY(strDest, strSrc, srcStrLen) do { \ +#define SECUREC_SMALL_STR_COPY(strDest, strSrc, lenWithTerm) do { \ if (SECUREC_ADDR_ALIGNED_8(strDest) && SECUREC_ADDR_ALIGNED_8(strSrc)) { \ /* Use struct assignment */ \ - switch (srcStrLen) { \ + switch (lenWithTerm) { \ case 1: \ - *(SecStrBuf1 *)(void *)(strDest) = *(const SecStrBuf1 *)(const void *)(strSrc); \ + *(strDest) = *(strSrc); \ break; \ case 2: \ - *(SecStrBuf2 *)(void *)(strDest) = *(const SecStrBuf2 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 2); \ break; \ case 3: \ - *(SecStrBuf3 *)(void *)(strDest) = *(const SecStrBuf3 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 3); \ break; \ case 4: \ - *(SecStrBuf4 *)(void *)(strDest) = *(const SecStrBuf4 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 4); \ break; \ case 5: \ - *(SecStrBuf5 *)(void *)(strDest) = *(const SecStrBuf5 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 5); \ break; \ case 6: \ - *(SecStrBuf6 *)(void *)(strDest) = *(const SecStrBuf6 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 6); \ break; \ case 7: \ - *(SecStrBuf7 *)(void *)(strDest) = *(const SecStrBuf7 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 7); \ break; \ case 8: \ - *(SecStrBuf8 *)(void *)(strDest) = *(const SecStrBuf8 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 8); \ break; \ case 9: \ - *(SecStrBuf9 *)(void *)(strDest) = *(const SecStrBuf9 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 9); \ break; \ case 10: \ - *(SecStrBuf10 *)(void *)(strDest) = *(const SecStrBuf10 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 10); \ break; \ case 11: \ - *(SecStrBuf11 *)(void *)(strDest) = *(const SecStrBuf11 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 11); \ break; \ case 12: \ - *(SecStrBuf12 *)(void *)(strDest) = *(const SecStrBuf12 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 12); \ break; \ case 13: \ - *(SecStrBuf13 *)(void *)(strDest) = *(const SecStrBuf13 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 13); \ break; \ case 14: \ - *(SecStrBuf14 *)(void *)(strDest) = *(const SecStrBuf14 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 14); \ break; \ case 15: \ - *(SecStrBuf15 *)(void *)(strDest) = *(const SecStrBuf15 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 15); \ break; \ case 16: \ - *(SecStrBuf16 *)(void *)(strDest) = *(const SecStrBuf16 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 16); \ break; \ case 17: \ - *(SecStrBuf17 *)(void *)(strDest) = *(const SecStrBuf17 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 17); \ break; \ case 18: \ - *(SecStrBuf18 *)(void *)(strDest) = *(const SecStrBuf18 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 18); \ break; \ case 19: \ - *(SecStrBuf19 *)(void *)(strDest) = *(const SecStrBuf19 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 19); \ break; \ case 20: \ - *(SecStrBuf20 *)(void *)(strDest) = *(const SecStrBuf20 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 20); \ break; \ case 21: \ - *(SecStrBuf21 *)(void *)(strDest) = *(const SecStrBuf21 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 21); \ break; \ case 22: \ - *(SecStrBuf22 *)(void *)(strDest) = *(const SecStrBuf22 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 22); \ break; \ case 23: \ - *(SecStrBuf23 *)(void *)(strDest) = *(const SecStrBuf23 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 23); \ break; \ case 24: \ - *(SecStrBuf24 *)(void *)(strDest) = *(const SecStrBuf24 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 24); \ break; \ case 25: \ - *(SecStrBuf25 *)(void *)(strDest) = *(const SecStrBuf25 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 25); \ break; \ case 26: \ - *(SecStrBuf26 *)(void *)(strDest) = *(const SecStrBuf26 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 26); \ break; \ case 27: \ - *(SecStrBuf27 *)(void *)(strDest) = *(const SecStrBuf27 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 27); \ break; \ case 28: \ - *(SecStrBuf28 *)(void *)(strDest) = *(const SecStrBuf28 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 28); \ break; \ case 29: \ - *(SecStrBuf29 *)(void *)(strDest) = *(const SecStrBuf29 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 29); \ break; \ case 30: \ - *(SecStrBuf30 *)(void *)(strDest) = *(const SecStrBuf30 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 30); \ break; \ case 31: \ - *(SecStrBuf31 *)(void *)(strDest) = *(const SecStrBuf31 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 31); \ break; \ case 32: \ - *(SecStrBuf32 *)(void *)(strDest) = *(const SecStrBuf32 *)(const void *)(strSrc); \ + SECUREC_COPY_VALUE_BY_STRUCT((strDest), (strSrc), 32); \ break; \ default: \ + /* Do nothing */ \ break; \ } /* END switch */ \ } else { \ - char *tmpStrDest = (char *)(strDest); \ - const char *tmpStrSrc = (const char *)(strSrc); \ - switch (srcStrLen) { \ + char *tmpStrDest_ = (char *)(strDest); \ + const char *tmpStrSrc_ = (const char *)(strSrc); \ + switch (lenWithTerm) { \ case 32: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 31: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 30: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 29: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 28: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 27: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 26: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 25: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 24: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 23: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 22: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 21: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 20: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 19: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 18: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 17: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 16: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 15: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 14: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 13: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 12: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 11: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 10: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 9: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 8: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 7: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 6: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 5: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 4: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 3: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 2: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ case 1: \ - *(tmpStrDest++) = *(tmpStrSrc++); \ + *(tmpStrDest_++) = *(tmpStrSrc_++); \ /* fall-through */ /* FALLTHRU */ \ default: \ + /* Do nothing */ \ break; \ } \ } \ } SECUREC_WHILE_ZERO #endif - - -#if SECUREC_IN_KERNEL || (SECUREC_STRCPY_WITH_PERFORMANCE == 0) +#if SECUREC_IN_KERNEL || (!SECUREC_STRCPY_WITH_PERFORMANCE) #define SECUREC_STRCPY_OPT(dest, src, lenWithTerm) SECUREC_MEMCPY_WARP_OPT((dest), (src), (lenWithTerm)) #else /* @@ -266,7 +262,7 @@ SECUREC_INLINE errno_t CheckSrcRange(char *strDest, size_t destMax, const char * size_t tmpDestMax = destMax; const char *tmpSrc = strSrc; /* Use destMax as boundary checker and destMax must be greater than zero */ - while (*(tmpSrc) != '\0' && tmpDestMax > 0) { + while (*tmpSrc != '\0' && tmpDestMax > 0) { ++tmpSrc; --tmpDestMax; } @@ -286,7 +282,8 @@ errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { SECUREC_ERROR_INVALID_RANGE("strcpy_s"); return ERANGE; - } else if (strDest == NULL || strSrc == NULL) { + } + if (strDest == NULL || strSrc == NULL) { SECUREC_ERROR_INVALID_PARAMTER("strcpy_s"); if (strDest != NULL) { strDest[0] = '\0'; @@ -325,7 +322,7 @@ errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc) */ errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc) { - if ((destMax > 0 && destMax <= SECUREC_STRING_MAX_LEN && strDest != NULL && strSrc != NULL && strDest != strSrc)) { + if (SECUREC_STRCPY_PARAM_OK(strDest, destMax, strSrc)) { size_t srcStrLen; SECUREC_CALC_STR_LEN(strSrc, destMax, &srcStrLen); ++srcStrLen; /* The length include '\0' */ diff --git a/src/mapleall/huawei_secure_c/src/strncat_s.c b/third_party/bounds_checking_function/src/strncat_s.c similarity index 92% rename from src/mapleall/huawei_secure_c/src/strncat_s.c rename to third_party/bounds_checking_function/src/strncat_s.c index 0fbfceb003b8712814fb0607261ee810d7ab3b06..3baf9bf242e3fdc279adf34540b82d6b519763e1 100644 --- a/src/mapleall/huawei_secure_c/src/strncat_s.c +++ b/third_party/bounds_checking_function/src/strncat_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: strncat_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" diff --git a/src/mapleall/huawei_secure_c/src/strncpy_s.c b/third_party/bounds_checking_function/src/strncpy_s.c similarity index 87% rename from src/mapleall/huawei_secure_c/src/strncpy_s.c rename to third_party/bounds_checking_function/src/strncpy_s.c index 484cb6dc62672eb4ad165d7c5e948a6f9c58ce79..5bbf0814563f12d84aa42307b1bb7933f14b1248 100644 --- a/src/mapleall/huawei_secure_c/src/strncpy_s.c +++ b/third_party/bounds_checking_function/src/strncpy_s.c @@ -1,21 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. - */ -/* - * [Standardize-exceptions] Use unsafe function: Performance-sensitive - * [reason] Always used in the performance critical path, - * and sufficient input validation is performed before calling + * Description: strncpy_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" @@ -61,22 +56,24 @@ errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t if (destMax == 0 || destMax > SECUREC_STRING_MAX_LEN) { SECUREC_ERROR_INVALID_RANGE("strncpy_s"); return ERANGE; - } else if (strDest == NULL || strSrc == NULL) { + } + if (strDest == NULL || strSrc == NULL) { SECUREC_ERROR_INVALID_PARAMTER("strncpy_s"); if (strDest != NULL) { strDest[0] = '\0'; return EINVAL_AND_RESET; } return EINVAL; - } else if (count > SECUREC_STRING_MAX_LEN) { + } + if (count > SECUREC_STRING_MAX_LEN) { strDest[0] = '\0'; /* Clear dest string */ SECUREC_ERROR_INVALID_RANGE("strncpy_s"); return ERANGE_AND_RESET; - } else if (count == 0) { + } + if (count == 0) { strDest[0] = '\0'; return EOK; } - return CheckSrcCountRange(strDest, destMax, strSrc, count); } diff --git a/src/mapleall/huawei_secure_c/src/strtok_s.c b/third_party/bounds_checking_function/src/strtok_s.c similarity index 83% rename from src/mapleall/huawei_secure_c/src/strtok_s.c rename to third_party/bounds_checking_function/src/strtok_s.c index 6dbeb7105f280476a3af00509916abf39dd7d196..b04793bcf667fc6687ead42a7d744cbd80e222d4 100644 --- a/src/mapleall/huawei_secure_c/src/strtok_s.c +++ b/third_party/bounds_checking_function/src/strtok_s.c @@ -1,21 +1,20 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: strtok_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" - SECUREC_INLINE int SecIsInDelimit(char ch, const char *strDelimit) { const char *ctl = strDelimit; @@ -33,7 +32,7 @@ SECUREC_INLINE char *SecFindBegin(char *strToken, const char *strDelimit) { char *token = strToken; while (*token != '\0') { - if (SecIsInDelimit(*token, strDelimit)) { + if (SecIsInDelimit(*token, strDelimit) != 0) { ++token; continue; } @@ -51,7 +50,7 @@ SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit) /* Find the rest of the token. If it is not the end of the string, put a null there */ char *token = strToken; while (*token != '\0') { - if (SecIsInDelimit(*token, strDelimit)) { + if (SecIsInDelimit(*token, strDelimit) != 0) { /* Find a delimiter, set string termintor */ *token = '\0'; ++token; @@ -67,12 +66,10 @@ SECUREC_INLINE char *SecFindRest(char *strToken, const char *strDelimit) */ SECUREC_INLINE char *SecUpdateToken(char *strToken, const char *strDelimit, char **context) { - /* Point to updated position */ - char *token = SecFindRest(strToken, strDelimit); - /* Record string position for next search in the context */ - *context = token; + /* Point to updated position. Record string position for next search in the context */ + *context = SecFindRest(strToken, strDelimit); /* Determine if a token has been found. */ - if (token == strToken) { + if (*context == strToken) { return NULL; } return strToken; diff --git a/src/mapleall/huawei_secure_c/src/swprintf_s.c b/third_party/bounds_checking_function/src/swprintf_s.c similarity index 78% rename from src/mapleall/huawei_secure_c/src/swprintf_s.c rename to third_party/bounds_checking_function/src/swprintf_s.c index 7be1357b6ce01fb0a22d059d693f40ca93ac0a2f..2d2ad42b19d3ce766277d4ee1f51561c7bbe861f 100644 --- a/src/mapleall/huawei_secure_c/src/swprintf_s.c +++ b/third_party/bounds_checking_function/src/swprintf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: swprintf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h" @@ -47,4 +47,3 @@ int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...) return ret; } - diff --git a/src/mapleall/huawei_secure_c/src/swscanf_s.c b/third_party/bounds_checking_function/src/swscanf_s.c similarity index 82% rename from src/mapleall/huawei_secure_c/src/swscanf_s.c rename to third_party/bounds_checking_function/src/swscanf_s.c index 90072d37027ae0e5dad9801cadb4f15d7d4f878e..987b6893d66ebd7db2f84d06902b16f138cb07ce 100644 --- a/src/mapleall/huawei_secure_c/src/swscanf_s.c +++ b/third_party/bounds_checking_function/src/swscanf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: swscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h" @@ -53,4 +53,3 @@ int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...) return ret; } - diff --git a/src/mapleall/huawei_secure_c/src/vfscanf_s.c b/third_party/bounds_checking_function/src/vfscanf_s.c similarity index 82% rename from src/mapleall/huawei_secure_c/src/vfscanf_s.c rename to third_party/bounds_checking_function/src/vfscanf_s.c index 6408807a4a36a911a3a0542cba8b735778673acd..96aee67fa9b0b8ab8de3353bebc48aff6725c462 100644 --- a/src/mapleall/huawei_secure_c/src/vfscanf_s.c +++ b/third_party/bounds_checking_function/src/vfscanf_s.c @@ -1,19 +1,18 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vfscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ -#define SECUREC_INLINE_INIT_FILE_STREAM_FILE 1 #include "secinput.h" /* @@ -53,7 +52,7 @@ int vfscanf_s(FILE *stream, const char *format, va_list argList) } SECUREC_LOCK_FILE(stream); - SecInitFileStreamFromFile(&fStr, stream); + SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream); retVal = SecInputS(&fStr, format, argList); SECUREC_UNLOCK_FILE(stream); if (retVal < 0) { @@ -64,4 +63,3 @@ int vfscanf_s(FILE *stream, const char *format, va_list argList) return retVal; } - diff --git a/src/mapleall/huawei_secure_c/src/vfwscanf_s.c b/third_party/bounds_checking_function/src/vfwscanf_s.c similarity index 80% rename from src/mapleall/huawei_secure_c/src/vfwscanf_s.c rename to third_party/bounds_checking_function/src/vfwscanf_s.c index a66f305c2f1906627d013ab3a6f12871832bed2d..0fd0c350cd3ecb825191e2066ce83c51b9c1aae2 100644 --- a/src/mapleall/huawei_secure_c/src/vfwscanf_s.c +++ b/third_party/bounds_checking_function/src/vfwscanf_s.c @@ -1,19 +1,22 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vfwscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ -#define SECUREC_INLINE_INIT_FILE_STREAM_FILE 1 +#ifndef SECUREC_FOR_WCHAR +#define SECUREC_FOR_WCHAR +#endif + #include "secinput.h" /* @@ -53,7 +56,7 @@ int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) } SECUREC_LOCK_FILE(stream); - SecInitFileStreamFromFile(&fStr, stream); + SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream); retVal = SecInputSW(&fStr, format, argList); SECUREC_UNLOCK_FILE(stream); if (retVal < 0) { @@ -63,4 +66,3 @@ int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) return retVal; } - diff --git a/src/mapleall/huawei_secure_c/src/vscanf_s.c b/third_party/bounds_checking_function/src/vscanf_s.c similarity index 83% rename from src/mapleall/huawei_secure_c/src/vscanf_s.c rename to third_party/bounds_checking_function/src/vscanf_s.c index 2f05d78d113fc78261b4df0e2402a89b82f3f20b..23edffe13777deaa59619c468306f208e9b42fd1 100644 --- a/src/mapleall/huawei_secure_c/src/vscanf_s.c +++ b/third_party/bounds_checking_function/src/vscanf_s.c @@ -1,19 +1,18 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ -#define SECUREC_INLINE_INIT_FILE_STREAM_STDIN 1 #include "secinput.h" /* @@ -42,7 +41,7 @@ int vscanf_s(const char *format, va_list argList) { int retVal; /* If initialization causes e838 */ SecFileStream fStr; - SecInitFileStreamFromStdin(&fStr); + SECUREC_FILE_STREAM_FROM_STDIN(&fStr); /* * The "va_list" has different definition on different platform, so we can't use argList == NULL * To determine it's invalid. If you has fixed platform, you can check some fields to validate it, @@ -54,9 +53,7 @@ int vscanf_s(const char *format, va_list argList) } SECUREC_LOCK_STDIN(0, fStr.pf); - retVal = SecInputS(&fStr, format, argList); - SECUREC_UNLOCK_STDIN(0, fStr.pf); if (retVal < 0) { SECUREC_ERROR_INVALID_PARAMTER("vscanf_s"); @@ -65,4 +62,3 @@ int vscanf_s(const char *format, va_list argList) return retVal; } - diff --git a/src/mapleall/huawei_secure_c/src/vsnprintf_s.c b/third_party/bounds_checking_function/src/vsnprintf_s.c similarity index 92% rename from src/mapleall/huawei_secure_c/src/vsnprintf_s.c rename to third_party/bounds_checking_function/src/vsnprintf_s.c index 07c66263c7cbbe8e654cf18a13f7a8257968f257..36619d87afac42ba914ce2475f68a2cfbcb5c980 100644 --- a/src/mapleall/huawei_secure_c/src/vsnprintf_s.c +++ b/third_party/bounds_checking_function/src/vsnprintf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vsnprintf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "secureprintoutput.h" @@ -69,12 +69,10 @@ int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, if (retVal < 0) { strDest[0] = '\0'; /* Empty the dest strDest */ - if (retVal == SECUREC_PRINTF_TRUNCATE) { /* Buffer too small */ SECUREC_ERROR_INVALID_RANGE("vsnprintf_s"); } - SECUREC_ERROR_INVALID_PARAMTER("vsnprintf_s"); return -1; } @@ -123,7 +121,6 @@ int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, va_ } retVal = SecVsnprintfImpl(strDest, destMax, format, argList); - if (retVal < 0) { if (retVal == SECUREC_PRINTF_TRUNCATE) { return (int)(destMax - 1); /* To skip error handler, return strlen(strDest) */ @@ -140,4 +137,3 @@ EXPORT_SYMBOL(vsnprintf_truncated_s); #endif #endif - diff --git a/src/mapleall/huawei_secure_c/src/vsprintf_s.c b/third_party/bounds_checking_function/src/vsprintf_s.c similarity index 84% rename from src/mapleall/huawei_secure_c/src/vsprintf_s.c rename to third_party/bounds_checking_function/src/vsprintf_s.c index 797c6f6e52654b33e47ce36d420aecf8cb40a7f1..012f522c4987d99a448a5f4b6a157a5d3a271e9f 100644 --- a/src/mapleall/huawei_secure_c/src/vsprintf_s.c +++ b/third_party/bounds_checking_function/src/vsprintf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vsprintf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "secureprintoutput.h" @@ -50,7 +50,6 @@ int vsprintf_s(char *strDest, size_t destMax, const char *format, va_list argLis } retVal = SecVsnprintfImpl(strDest, destMax, format, argList); - if (retVal < 0) { strDest[0] = '\0'; if (retVal == SECUREC_PRINTF_TRUNCATE) { @@ -67,4 +66,3 @@ int vsprintf_s(char *strDest, size_t destMax, const char *format, va_list argLis EXPORT_SYMBOL(vsprintf_s); #endif - diff --git a/src/mapleall/huawei_secure_c/src/vsscanf_s.c b/third_party/bounds_checking_function/src/vsscanf_s.c similarity index 83% rename from src/mapleall/huawei_secure_c/src/vsscanf_s.c rename to third_party/bounds_checking_function/src/vsscanf_s.c index 7a445840f235303672d254ea0b334892d074b6e7..6612d2fa0098cdb7db2162b48f85674d4ab0c5d1 100644 --- a/src/mapleall/huawei_secure_c/src/vsscanf_s.c +++ b/third_party/bounds_checking_function/src/vsscanf_s.c @@ -1,19 +1,18 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vsscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ -#define SECUREC_INLINE_INIT_FILE_STREAM_STR 1 #include "secinput.h" #if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL && \ (!defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT)) @@ -71,11 +70,11 @@ int vsscanf_s(const char *buffer, const char *format, va_list argList) * " \v\f\t\r\n", "%s", str, strSize * Do not check all character, just first and last character then consider it is white string */ - if (isspace((int)buffer[0]) && isspace((int)buffer[count - 1])) { + if (isspace((int)(unsigned char)buffer[0]) != 0 && isspace((int)(unsigned char)buffer[count - 1]) != 0) { SecClearDestBuf(buffer, format, argList); } #endif - SecInitFileStreamFromString(&fStr, buffer, (int)count); + SECUREC_FILE_STREAM_FROM_STRING(&fStr, buffer, count); retVal = SecInputS(&fStr, format, argList); if (retVal < 0) { SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s"); diff --git a/src/mapleall/huawei_secure_c/src/vswprintf_s.c b/third_party/bounds_checking_function/src/vswprintf_s.c similarity index 79% rename from src/mapleall/huawei_secure_c/src/vswprintf_s.c rename to third_party/bounds_checking_function/src/vswprintf_s.c index b63b4dfc353b7d05033f6890ba184a54dd03a8ec..38b0b4045fd49e2788607ad984e399a74586eb8d 100644 --- a/src/mapleall/huawei_secure_c/src/vswprintf_s.c +++ b/third_party/bounds_checking_function/src/vswprintf_s.c @@ -1,20 +1,23 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vswprintf_s function + * Author: lishunda + * Create: 2014-02-25 */ -#include "secureprintoutput.h" +#ifndef SECUREC_FOR_WCHAR +#define SECUREC_FOR_WCHAR +#endif +#include "secureprintoutput.h" /* * @@ -45,9 +48,8 @@ int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list } retVal = SecVswprintfImpl(strDest, destMax, format, argList); - if (retVal < 0) { - strDest[0] = '\0'; + strDest[0] = L'\0'; if (retVal == SECUREC_PRINTF_TRUNCATE) { /* Buffer too small */ SECUREC_ERROR_INVALID_RANGE("vswprintf_s"); @@ -59,4 +61,3 @@ int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list return retVal; } - diff --git a/src/mapleall/huawei_secure_c/src/vswscanf_s.c b/third_party/bounds_checking_function/src/vswscanf_s.c similarity index 81% rename from src/mapleall/huawei_secure_c/src/vswscanf_s.c rename to third_party/bounds_checking_function/src/vswscanf_s.c index 0aafab7c2fa7f9aae5a994c82f6127316bde4bea..d416b96c7f4f440524aa6eb8517803775aba75cc 100644 --- a/src/mapleall/huawei_secure_c/src/vswscanf_s.c +++ b/third_party/bounds_checking_function/src/vswscanf_s.c @@ -1,19 +1,22 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vswscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ -#define SECUREC_INLINE_INIT_FILE_STREAM_STR 1 +#ifndef SECUREC_FOR_WCHAR +#define SECUREC_FOR_WCHAR +#endif + #include "secinput.h" SECUREC_INLINE size_t SecWcslen(const wchar_t *s) @@ -66,7 +69,7 @@ int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList) SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s"); return SECUREC_SCANF_EINVAL; } - SecInitFileStreamFromString(&fStr, (const char *)buffer, (int)count * ((int)sizeof(wchar_t))); + SECUREC_FILE_STREAM_FROM_STRING(&fStr, (const char *)buffer, count * sizeof(wchar_t)); retVal = SecInputSW(&fStr, format, argList); if (retVal < 0) { SECUREC_ERROR_INVALID_PARAMTER("vswscanf_s"); @@ -75,4 +78,3 @@ int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList) return retVal; } - diff --git a/src/mapleall/huawei_secure_c/src/vwscanf_s.c b/third_party/bounds_checking_function/src/vwscanf_s.c similarity index 79% rename from src/mapleall/huawei_secure_c/src/vwscanf_s.c rename to third_party/bounds_checking_function/src/vwscanf_s.c index 03b1497c9fff0b1a0f1d9d0053b0fe4610ea71a8..90f49a1c332562434bb43cf1fe68c551ca046807 100644 --- a/src/mapleall/huawei_secure_c/src/vwscanf_s.c +++ b/third_party/bounds_checking_function/src/vwscanf_s.c @@ -1,19 +1,22 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: vwscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ -#define SECUREC_INLINE_INIT_FILE_STREAM_STDIN 1 +#ifndef SECUREC_FOR_WCHAR +#define SECUREC_FOR_WCHAR +#endif + #include "secinput.h" /* @@ -43,19 +46,15 @@ int vwscanf_s(const wchar_t *format, va_list argList) { int retVal; /* If initialization causes e838 */ SecFileStream fStr; - - SecInitFileStreamFromStdin(&fStr); + SECUREC_FILE_STREAM_FROM_STDIN(&fStr); if (format == NULL || fStr.pf == NULL) { SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s"); return SECUREC_SCANF_EINVAL; } SECUREC_LOCK_STDIN(0, fStr.pf); - retVal = SecInputSW(&fStr, format, argList); - SECUREC_UNLOCK_STDIN(0, fStr.pf); - if (retVal < 0) { SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s"); return SECUREC_SCANF_EINVAL; @@ -64,4 +63,3 @@ int vwscanf_s(const wchar_t *format, va_list argList) return retVal; } - diff --git a/src/mapleall/huawei_secure_c/src/wcscat_s.c b/third_party/bounds_checking_function/src/wcscat_s.c similarity index 91% rename from src/mapleall/huawei_secure_c/src/wcscat_s.c rename to third_party/bounds_checking_function/src/wcscat_s.c index 0371f84f0f62d434a17aac488c5bdb30afa138fa..780907bf3d85a0e1fbf74b535e0bc761ba2dce4c 100644 --- a/src/mapleall/huawei_secure_c/src/wcscat_s.c +++ b/third_party/bounds_checking_function/src/wcscat_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: wcscat_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" @@ -106,4 +106,3 @@ errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) return SecDoCatW(strDest, destMax, strSrc); } - diff --git a/src/mapleall/huawei_secure_c/src/wcscpy_s.c b/third_party/bounds_checking_function/src/wcscpy_s.c similarity index 87% rename from src/mapleall/huawei_secure_c/src/wcscpy_s.c rename to third_party/bounds_checking_function/src/wcscpy_s.c index 26615c9f3b6d17cb1921f77789a3eebb7381abb0..89c281df6bf5f58a4596725787462e8559ce76c0 100644 --- a/src/mapleall/huawei_secure_c/src/wcscpy_s.c +++ b/third_party/bounds_checking_function/src/wcscpy_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: wcscpy_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" @@ -21,7 +21,7 @@ SECUREC_INLINE errno_t SecDoCpyW(wchar_t *strDest, size_t destMax, const wchar_t SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen); if (srcStrLen == destMax) { - strDest[0] = '\0'; + strDest[0] = L'\0'; SECUREC_ERROR_INVALID_RANGE("wcscpy_s"); return ERANGE_AND_RESET; } @@ -85,4 +85,3 @@ errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc) return SecDoCpyW(strDest, destMax, strSrc); } - diff --git a/src/mapleall/huawei_secure_c/src/wcsncat_s.c b/third_party/bounds_checking_function/src/wcsncat_s.c similarity index 87% rename from src/mapleall/huawei_secure_c/src/wcsncat_s.c rename to third_party/bounds_checking_function/src/wcsncat_s.c index da6388c6b62e31eae304f5f2b30b469befded63c..6151da4425553a73bc016a09dcf33fc8cea91675 100644 --- a/src/mapleall/huawei_secure_c/src/wcsncat_s.c +++ b/third_party/bounds_checking_function/src/wcsncat_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: wcsncat_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" @@ -76,7 +76,8 @@ SECUREC_INLINE errno_t SecDoCatLimitW(wchar_t *strDest, size_t destMax, const wc * EOK Success * EINVAL strDest is NULL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN * EINVAL_AND_RESET (strDest unterminated and all other parameters are valid) or - * (strDest != NULL and strSrc is NULLL and destMax != 0 and destMax <= SECUREC_WCHAR_STRING_MAX_LEN) + * (strDest != NULL and strSrc is NULLL and destMax != 0 and + * destMax <= SECUREC_WCHAR_STRING_MAX_LEN) * ERANGE destMax > SECUREC_WCHAR_STRING_MAX_LEN or destMax is 0 * ERANGE_AND_RESET strDest have not enough space and all other parameters are valid and not overlap * EOVERLAP_AND_RESET dest buffer and source buffer are overlapped and all parameters are valid @@ -99,7 +100,7 @@ errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_ } if (count > SECUREC_WCHAR_STRING_MAX_LEN) { #ifdef SECUREC_COMPATIBLE_WIN_FORMAT - if (count == ((size_t)-1)) { + if (count == ((size_t)(-1))) { /* Windows internal functions may pass in -1 when calling this function */ return SecDoCatLimitW(strDest, destMax, strSrc, destMax); } @@ -111,4 +112,3 @@ errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_ return SecDoCatLimitW(strDest, destMax, strSrc, count); } - diff --git a/src/mapleall/huawei_secure_c/src/wcsncpy_s.c b/third_party/bounds_checking_function/src/wcsncpy_s.c similarity index 86% rename from src/mapleall/huawei_secure_c/src/wcsncpy_s.c rename to third_party/bounds_checking_function/src/wcsncpy_s.c index 8cd20a1f59e8ff603e311a2b0c3b9ecf0b583c7a..8bd5737bbc46cbfe4a59d6307293f7803069e373 100644 --- a/src/mapleall/huawei_secure_c/src/wcsncpy_s.c +++ b/third_party/bounds_checking_function/src/wcsncpy_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: wcsncpy_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" @@ -24,7 +24,7 @@ SECUREC_INLINE errno_t SecDoCpyLimitW(wchar_t *strDest, size_t destMax, const wc SECUREC_CALC_WSTR_LEN(strSrc, destMax, &srcStrLen); } if (srcStrLen == destMax) { - strDest[0] = '\0'; + strDest[0] = L'\0'; SECUREC_ERROR_INVALID_RANGE("wcsncpy_s"); return ERANGE_AND_RESET; } @@ -82,7 +82,7 @@ errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_ if (strDest == NULL || strSrc == NULL) { SECUREC_ERROR_INVALID_PARAMTER("wcsncpy_s"); if (strDest != NULL) { - strDest[0] = '\0'; + strDest[0] = L'\0'; return EINVAL_AND_RESET; } return EINVAL; @@ -93,13 +93,13 @@ errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_ return SecDoCpyLimitW(strDest, destMax, strSrc, destMax - 1); } #endif - strDest[0] = '\0'; /* Clear dest string */ + strDest[0] = L'\0'; /* Clear dest string */ SECUREC_ERROR_INVALID_RANGE("wcsncpy_s"); return ERANGE_AND_RESET; } if (count == 0) { - strDest[0] = '\0'; + strDest[0] = L'\0'; return EOK; } diff --git a/src/mapleall/huawei_secure_c/src/wcstok_s.c b/third_party/bounds_checking_function/src/wcstok_s.c similarity index 79% rename from src/mapleall/huawei_secure_c/src/wcstok_s.c rename to third_party/bounds_checking_function/src/wcstok_s.c index 5e9763dd0599bdc2719d5c8ad212719761d98050..19284f334ed87aedf78a73860ddf2d7d92ff61f7 100644 --- a/src/mapleall/huawei_secure_c/src/wcstok_s.c +++ b/third_party/bounds_checking_function/src/wcstok_s.c @@ -1,21 +1,20 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: wcstok_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" - SECUREC_INLINE int SecIsInDelimitW(wchar_t ch, const wchar_t *strDelimit) { const wchar_t *ctl = strDelimit; @@ -33,7 +32,7 @@ SECUREC_INLINE wchar_t *SecFindBeginW(wchar_t *strToken, const wchar_t *strDelim { wchar_t *token = strToken; while (*token != L'\0') { - if (SecIsInDelimitW(*token, strDelimit)) { + if (SecIsInDelimitW(*token, strDelimit) != 0) { ++token; continue; } @@ -50,7 +49,7 @@ SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken, const wchar_t *strDelimi { wchar_t *token = strToken; while (*token != L'\0') { - if (SecIsInDelimitW(*token, strDelimit)) { + if (SecIsInDelimitW(*token, strDelimit) != 0) { /* Find a delimiter, set string termintor */ *token = L'\0'; ++token; @@ -66,12 +65,10 @@ SECUREC_INLINE wchar_t *SecFindRestW(wchar_t *strToken, const wchar_t *strDelimi */ SECUREC_INLINE wchar_t *SecUpdateTokenW(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context) { - /* Point to updated position */ - wchar_t *token = SecFindRestW(strToken, strDelimit); - /* Update the context */ - *context = token; - /* Determine if a token has been found. */ - if (token == strToken) { + /* Point to updated position. Record string position for next search in the context */ + *context = SecFindRestW(strToken, strDelimit); + /* Determine if a token has been found */ + if (*context == strToken) { return NULL; } return strToken; diff --git a/src/mapleall/huawei_secure_c/src/wmemcpy_s.c b/third_party/bounds_checking_function/src/wmemcpy_s.c similarity index 81% rename from src/mapleall/huawei_secure_c/src/wmemcpy_s.c rename to third_party/bounds_checking_function/src/wmemcpy_s.c index d540290fdf6283bdec36559f5d662dc5bd8aae85..99611809ff97c16567b016f244830db915633134 100644 --- a/src/mapleall/huawei_secure_c/src/wmemcpy_s.c +++ b/third_party/bounds_checking_function/src/wmemcpy_s.c @@ -1,21 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. - */ -/* - * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain platform compatibility. - * And sufficient input validation is performed before calling + * Description: wmemcpy_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" diff --git a/src/mapleall/huawei_secure_c/src/wmemmove_s.c b/third_party/bounds_checking_function/src/wmemmove_s.c similarity index 80% rename from src/mapleall/huawei_secure_c/src/wmemmove_s.c rename to third_party/bounds_checking_function/src/wmemmove_s.c index 04eab65859744240b501395b319a4590280db52f..e66e29b7398ed9c75219a20a4b6338dc71badae8 100644 --- a/src/mapleall/huawei_secure_c/src/wmemmove_s.c +++ b/third_party/bounds_checking_function/src/wmemmove_s.c @@ -1,21 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. - */ -/* - * [Standardize-exceptions] Use unsafe function: Portability - * [reason] Use unsafe function to implement security function to maintain platform compatibility. - * And sufficient input validation is performed before calling + * Description: wmemmove_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securecutil.h" diff --git a/src/mapleall/huawei_secure_c/src/wscanf_s.c b/third_party/bounds_checking_function/src/wscanf_s.c similarity index 80% rename from src/mapleall/huawei_secure_c/src/wscanf_s.c rename to third_party/bounds_checking_function/src/wscanf_s.c index d40657c0c0b7e399c70f8708f83dd9f1ddf535d5..0a3df7768b1ea6cc035b94a0378d6625b9a300c4 100644 --- a/src/mapleall/huawei_secure_c/src/wscanf_s.c +++ b/third_party/bounds_checking_function/src/wscanf_s.c @@ -1,16 +1,16 @@ /* - * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. - * - * OpenArkCompiler is licensed under the Mulan PSL v2. + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved. + * Licensed under Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR - * FIT FOR A PARTICULAR PURPOSE. + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v2 for more details. + * Description: wscanf_s function + * Author: lishunda + * Create: 2014-02-25 */ #include "securec.h"