提交 03d40661 编写于 作者: 李鸿章

add securec to submodule

上级 e84c0e1f
......@@ -80,10 +80,9 @@ TESTS*.xml
package-lock.json
build/lib
build/bdist.*
build/*
!build/scripts
!build/build.sh
output/
!output/README.md
third_party/securec/build
[submodule "third_party/securec"]
path = third_party/securec
url = https://gitee.com/openeuler/bounds_checking_function.git
cmake_minimum_required(VERSION 3.14)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Updating submodules")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update failed with ${GIT_SUBMOD_RESULT}, please checkout submodules.")
endif()
endif()
elseif(NOT EXISTS "${PROJECT_SOURCE_DIR}/third_party/securec/src")
message(FATAL_ERROR "git command not found or not in a git repository, third_party/securec/src not exists.")
else()
message(WARNING "git command not found or not in a git repository, submodules not updated.")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -fPIC -O0 -Wall -fvisibility=hidden -Wno-deprecated-declarations -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer -D_LIBCPP_INLINE_VISIBILITY='' -D'_LIBCPP_EXTERN_TEMPLATE(...)='")
set(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -fPIC -O3 -Wall -fvisibility=hidden -Wno-deprecated-declarations")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#add flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include -Werror")
include_directories(./third_party/securec/include)
aux_source_directory(./third_party/securec/src SECUREC_SRCS)
add_library(securec ${SECUREC_SRCS})
......@@ -34,7 +34,10 @@ rename_wheel() {
}
build_wheel() {
PROJECT_BASEDIR=$(cd "$(dirname "$SCRIPT_BASEDIR")" || exit; pwd)
PROJECT_BASEDIR=$(
cd "$(dirname "$SCRIPT_BASEDIR")" || exit
pwd
)
cd "${PROJECT_BASEDIR}" || exit
if [ $# -gt 0 ]; then
......
......@@ -19,7 +19,7 @@ SCRIPT_BASEDIR=$(
)
THIRD_PARTY_DIR=$(realpath "${SCRIPT_BASEDIR}/../../third_party")
SECUREC_SOURCE_DIR="${THIRD_PARTY_DIR}/securec"
BUILDDIR=$(dirname "$SCRIPT_BASEDIR")
build_securec() {
CMAKE=$(command -v cmake)
......@@ -27,14 +27,19 @@ build_securec() {
echo "Could not find cmake command"
exit 1
fi
cd "${SECUREC_SOURCE_DIR}" || exit
rm -rf build
mkdir build
cd build || exit
cd "$BUILDDIR" || exit
${CMAKE} ..
make
cd - >/dev/null 2>&1 || exit
}
clean_securec() {
cd "$BUILDDIR" || exit
for file in *; do
if [ "$file" == build.sh ] || [ "$file" == scripts ] || [ "$file" == lib ]; then
continue
fi
rm -rf "$file"
done
}
build_crc32() {
......@@ -72,9 +77,9 @@ build_crc32() {
PYTHON_INCLUDE=$(echo "${PYBIND11_INCLUDES}" | awk '{print $1}' | sed "s/^-I//g")
PYTHON_HEADERS=$(echo "${PYBIND11_INCLUDES}" | awk '{print $2}' | sed "s/^-I//g")
${CPP} -O2 -O3 -shared -std=c++11 -fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 \
-Wno-maybe-uninitialized -Wno-unused-parameter -Wall -Wl,-z,relro,-z,now,-z,noexecstack \
-I"${THIRD_PARTY_DIR}" -I"${DATAVISUAL_DIR}/utils" -I"${PYTHON_INCLUDE}" -I"${PYTHON_HEADERS}" \
-o "${CRC32_SO_FILE}" crc32.cc "${SECUREC_SOURCE_DIR}/build/src/libsecurec.a"
-Wno-maybe-uninitialized -Wno-unused-parameter -Wall -Wl,-z,relro,-z,now,-z,noexecstack \
-I"${THIRD_PARTY_DIR}" -I"${DATAVISUAL_DIR}/utils" -I"${PYTHON_INCLUDE}" -I"${PYTHON_HEADERS}" \
-o "${CRC32_SO_FILE}" crc32.cc "$BUILDDIR/libsecurec.a"
if [ ! -f "${CRC32_SO_FILE}" ]; then
echo "crc so file does not exist, build failed"
......@@ -88,3 +93,5 @@ build_securec
cd "${SCRIPT_BASEDIR}" || exit
build_crc32
clean_securec
......@@ -29,7 +29,7 @@ IS_BUILD_CRC=""
build_crc32() {
echo "Start to check crc32."
if [ -d "$CRC32_OUTPUT_DIR" ]; then
cd "$CRC32_OUTPUT_DIR"
cd "$CRC32_OUTPUT_DIR" || exit
result=$(find . -maxdepth 1 -name "crc32*.so")
if [ -z "$result" ]; then
echo "Start to build crc32."
......
securec @ 737ad71e
Subproject commit 737ad71e2c5cec766ad672e3fa7a66bbd37489cd
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -fPIC -O0 -Wall -fvisibility=hidden -Wno-deprecated-declarations -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer -D_LIBCPP_INLINE_VISIBILITY='' -D'_LIBCPP_EXTERN_TEMPLATE(...)='")
SET(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -fPIC -O3 -Wall -fvisibility=hidden -Wno-deprecated-declarations")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#add flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include -Werror")
include_directories(./include)
add_subdirectory(src)
此差异已折叠。
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* [Standardize-exceptions]: Performance-sensitive
* [reason]: Strict parameter verification has been done before use
*/
#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
/* Security functions have been provided since vs2005, default use of system library functions */
#define SECUREC_USING_STD_SECURE_LIB 0
#else
#define SECUREC_USING_STD_SECURE_LIB 1
#endif
#else
#define SECUREC_USING_STD_SECURE_LIB 0
#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
#ifndef SECUREC_DISABLE_CRT_FUNC
#define SECUREC_DISABLE_CRT_FUNC 1
#endif
#ifndef SECUREC_DISABLE_CRT_IMP
#define SECUREC_DISABLE_CRT_IMP 1
#endif
#else /* MSC VER */
#ifndef SECUREC_DISABLE_CRT_FUNC
#define SECUREC_DISABLE_CRT_FUNC 0
#endif
#ifndef SECUREC_DISABLE_CRT_IMP
#define SECUREC_DISABLE_CRT_IMP 0
#endif
#endif
#if SECUREC_DISABLE_CRT_FUNC
#ifdef __STDC_WANT_SECURE_LIB__
#undef __STDC_WANT_SECURE_LIB__
#endif
#define __STDC_WANT_SECURE_LIB__ 0
#endif
#if SECUREC_DISABLE_CRT_IMP
#ifdef _CRTIMP_ALTERNATIVE
#undef _CRTIMP_ALTERNATIVE
#endif
#define _CRTIMP_ALTERNATIVE /* comment microsoft *_s function */
#endif
/* Compile in kernel under macro control */
#ifndef SECUREC_IN_KERNEL
#ifdef __KERNEL__
#define SECUREC_IN_KERNEL 1
#else
#define SECUREC_IN_KERNEL 0
#endif
#endif
#if SECUREC_IN_KERNEL
#ifndef SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_SCANF_FILE 0
#endif
#ifndef SECUREC_ENABLE_WCHAR_FUNC
#define SECUREC_ENABLE_WCHAR_FUNC 0
#endif
#else /* SECUREC_IN_KERNEL */
#ifndef SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_SCANF_FILE 1
#endif
#ifndef SECUREC_ENABLE_WCHAR_FUNC
#define SECUREC_ENABLE_WCHAR_FUNC 1
#endif
#endif
/* Default secure function declaration, default declarations for non-standard functions */
#ifndef SECUREC_SNPRINTF_TRUNCATED
#define SECUREC_SNPRINTF_TRUNCATED 1
#endif
#if SECUREC_USING_STD_SECURE_LIB
#if defined(_MSC_VER) && _MSC_VER >= 1400
/* Declare secure functions that are not available in the vs compiler */
#ifndef SECUREC_ENABLE_MEMSET
#define SECUREC_ENABLE_MEMSET 1
#endif
/* vs 2005 have vsnprintf_s function */
#ifndef SECUREC_ENABLE_VSNPRINTF
#define SECUREC_ENABLE_VSNPRINTF 0
#endif
#ifndef SECUREC_ENABLE_SNPRINTF
/* vs 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */
#define snprintf_s _snprintf_s
#define SECUREC_ENABLE_SNPRINTF 0
#endif
/* befor vs 2010 do not have v functions */
#if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS)
#ifndef SECUREC_ENABLE_VFSCANF
#define SECUREC_ENABLE_VFSCANF 1
#endif
#ifndef SECUREC_ENABLE_VSCANF
#define SECUREC_ENABLE_VSCANF 1
#endif
#ifndef SECUREC_ENABLE_VSSCANF
#define SECUREC_ENABLE_VSSCANF 1
#endif
#endif
#else /* _MSC_VER */
#ifndef SECUREC_ENABLE_MEMSET
#define SECUREC_ENABLE_MEMSET 0
#endif
#ifndef SECUREC_ENABLE_SNPRINTF
#define SECUREC_ENABLE_SNPRINTF 0
#endif
#ifndef SECUREC_ENABLE_VSNPRINTF
#define SECUREC_ENABLE_VSNPRINTF 0
#endif
#endif
#ifndef SECUREC_ENABLE_MEMMOVE
#define SECUREC_ENABLE_MEMMOVE 0
#endif
#ifndef SECUREC_ENABLE_MEMCPY
#define SECUREC_ENABLE_MEMCPY 0
#endif
#ifndef SECUREC_ENABLE_STRCPY
#define SECUREC_ENABLE_STRCPY 0
#endif
#ifndef SECUREC_ENABLE_STRNCPY
#define SECUREC_ENABLE_STRNCPY 0
#endif
#ifndef SECUREC_ENABLE_STRCAT
#define SECUREC_ENABLE_STRCAT 0
#endif
#ifndef SECUREC_ENABLE_STRNCAT
#define SECUREC_ENABLE_STRNCAT 0
#endif
#ifndef SECUREC_ENABLE_SPRINTF
#define SECUREC_ENABLE_SPRINTF 0
#endif
#ifndef SECUREC_ENABLE_VSPRINTF
#define SECUREC_ENABLE_VSPRINTF 0
#endif
#ifndef SECUREC_ENABLE_SSCANF
#define SECUREC_ENABLE_SSCANF 0
#endif
#ifndef SECUREC_ENABLE_VSSCANF
#define SECUREC_ENABLE_VSSCANF 0
#endif
#ifndef SECUREC_ENABLE_SCANF
#define SECUREC_ENABLE_SCANF 0
#endif
#ifndef SECUREC_ENABLE_VSCANF
#define SECUREC_ENABLE_VSCANF 0
#endif
#ifndef SECUREC_ENABLE_FSCANF
#define SECUREC_ENABLE_FSCANF 0
#endif
#ifndef SECUREC_ENABLE_VFSCANF
#define SECUREC_ENABLE_VFSCANF 0
#endif
#ifndef SECUREC_ENABLE_STRTOK
#define SECUREC_ENABLE_STRTOK 0
#endif
#ifndef SECUREC_ENABLE_GETS
#define SECUREC_ENABLE_GETS 0
#endif
#else /* SECUREC_USE_STD_SECURE_LIB */
#ifndef SECUREC_ENABLE_MEMSET
#define SECUREC_ENABLE_MEMSET 1
#endif
#ifndef SECUREC_ENABLE_MEMMOVE
#define SECUREC_ENABLE_MEMMOVE 1
#endif
#ifndef SECUREC_ENABLE_MEMCPY
#define SECUREC_ENABLE_MEMCPY 1
#endif
#ifndef SECUREC_ENABLE_STRCPY
#define SECUREC_ENABLE_STRCPY 1
#endif
#ifndef SECUREC_ENABLE_STRNCPY
#define SECUREC_ENABLE_STRNCPY 1
#endif
#ifndef SECUREC_ENABLE_STRCAT
#define SECUREC_ENABLE_STRCAT 1
#endif
#ifndef SECUREC_ENABLE_STRNCAT
#define SECUREC_ENABLE_STRNCAT 1
#endif
#ifndef SECUREC_ENABLE_SPRINTF
#define SECUREC_ENABLE_SPRINTF 1
#endif
#ifndef SECUREC_ENABLE_VSPRINTF
#define SECUREC_ENABLE_VSPRINTF 1
#endif
#ifndef SECUREC_ENABLE_SNPRINTF
#define SECUREC_ENABLE_SNPRINTF 1
#endif
#ifndef SECUREC_ENABLE_VSNPRINTF
#define SECUREC_ENABLE_VSNPRINTF 1
#endif
#ifndef SECUREC_ENABLE_SSCANF
#define SECUREC_ENABLE_SSCANF 1
#endif
#ifndef SECUREC_ENABLE_VSSCANF
#define SECUREC_ENABLE_VSSCANF 1
#endif
#ifndef SECUREC_ENABLE_SCANF
#if SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_SCANF 1
#else
#define SECUREC_ENABLE_SCANF 0
#endif
#endif
#ifndef SECUREC_ENABLE_VSCANF
#if SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_VSCANF 1
#else
#define SECUREC_ENABLE_VSCANF 0
#endif
#endif
#ifndef SECUREC_ENABLE_FSCANF
#if SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_FSCANF 1
#else
#define SECUREC_ENABLE_FSCANF 0
#endif
#endif
#ifndef SECUREC_ENABLE_VFSCANF
#if SECUREC_ENABLE_SCANF_FILE
#define SECUREC_ENABLE_VFSCANF 1
#else
#define SECUREC_ENABLE_VFSCANF 0
#endif
#endif
#ifndef SECUREC_ENABLE_STRTOK
#define SECUREC_ENABLE_STRTOK 1
#endif
#ifndef SECUREC_ENABLE_GETS
#define SECUREC_ENABLE_GETS 1
#endif
#endif /* SECUREC_USE_STD_SECURE_LIB */
#if SECUREC_ENABLE_SCANF_FILE == 0
#if SECUREC_ENABLE_FSCANF
#undef SECUREC_ENABLE_FSCANF
#define SECUREC_ENABLE_FSCANF 0
#endif
#if SECUREC_ENABLE_VFSCANF
#undef SECUREC_ENABLE_VFSCANF
#define SECUREC_ENABLE_VFSCANF 0
#endif
#if SECUREC_ENABLE_SCANF
#undef SECUREC_ENABLE_SCANF
#define SECUREC_ENABLE_SCANF 0
#endif
#if SECUREC_ENABLE_FSCANF
#undef SECUREC_ENABLE_FSCANF
#define SECUREC_ENABLE_FSCANF 0
#endif
#endif
#if SECUREC_IN_KERNEL
#include <linux/kernel.h>
#include <linux/module.h>
#else
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#endif
/* If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable .
* The macro is automatically closed on the windows platform and linux kernel
*/
#ifndef SECUREC_WITH_PERFORMANCE_ADDONS
#if SECUREC_IN_KERNEL
#define SECUREC_WITH_PERFORMANCE_ADDONS 0
#else
#define SECUREC_WITH_PERFORMANCE_ADDONS 1
#endif
#endif
/* if enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */
#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT)
#define SECUREC_COMPATIBLE_WIN_FORMAT
#endif
#endif
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
/* in windows platform, can't use optimized function for there is no __builtin_constant_p like function */
/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */
#ifdef SECUREC_WITH_PERFORMANCE_ADDONS
#undef SECUREC_WITH_PERFORMANCE_ADDONS
#define SECUREC_WITH_PERFORMANCE_ADDONS 0
#endif
#endif
#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \
defined(SECUREC_VXWORKS_VERSION_5_4)
#if !defined(SECUREC_VXWORKS_PLATFORM)
#define SECUREC_VXWORKS_PLATFORM
#endif
#endif
/* if enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */
#if !(defined(SECUREC_COMPATIBLE_WIN_FORMAT) || defined(SECUREC_VXWORKS_PLATFORM))
#if !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
#define SECUREC_COMPATIBLE_LINUX_FORMAT
#endif
#endif
#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
#include <stddef.h>
#endif
/* add the -DSECUREC_SUPPORT_FORMAT_WARNING compiler option to supoort -Wformat.
* 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.
*/
#ifndef SECUREC_SUPPORT_FORMAT_WARNING
#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)
#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,
* you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options
*/
#if defined(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
#define SECUREC_LIKELY(x) (x)
#define SECUREC_UNLIKELY(x) (x)
#endif
/* define the max length of the string */
#ifndef SECUREC_STRING_MAX_LEN
#define SECUREC_STRING_MAX_LEN (0x7fffffffUL)
#endif
#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t))
/* add SECUREC_MEM_MAX_LEN for memcpy and memmove */
#ifndef SECUREC_MEM_MAX_LEN
#define SECUREC_MEM_MAX_LEN (0x7fffffffUL)
#endif
#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t))
#if SECUREC_STRING_MAX_LEN > 0x7fffffff
#error "max string is 2G"
#endif
#if (defined(__GNUC__) && defined(__SIZEOF_POINTER__))
#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8)
#error "unsupported system"
#endif
#endif
#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64)
#define SECUREC_ON_64BITS
#endif
#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__))
#if __SIZEOF_POINTER__ == 8
#define SECUREC_ON_64BITS
#endif
#endif
#if defined(__SVR4) || defined(__svr4__)
#define SECUREC_ON_SOLARIS
#endif
#if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS))
#define SECUREC_ON_UNIX
#endif
/* codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow system on default,
* and strtold. The function
* strtold is referenced first at ISO9899:1999(C99), and some old compilers can
* not support these functions. Here provides a macro to open these functions:
* SECUREC_SUPPORT_STRTOLD -- if defined, strtold will be used
*/
#ifndef SECUREC_SUPPORT_STRTOLD
#define SECUREC_SUPPORT_STRTOLD 0
#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT))
#if defined(__USE_ISOC99) || \
(defined(_AIX) && defined(_ISOC99_SOURCE)) || \
(defined(__hpux) && defined(__ia64)) || \
(defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
defined(_STDC_C99) || defined(__EXTENSIONS__))
#undef SECUREC_SUPPORT_STRTOLD
#define SECUREC_SUPPORT_STRTOLD 1
#endif
#endif
#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_)))
#undef SECUREC_SUPPORT_STRTOLD
#define SECUREC_SUPPORT_STRTOLD 0
#endif
#endif
#if SECUREC_WITH_PERFORMANCE_ADDONS
#ifndef SECUREC_TWO_MIN
#define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
/* for strncpy_s performance optimization */
#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \
(((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
(SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \
(((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \
(memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count))))
#define SECUREC_STRCPY_SM(dest, destMax, src) \
(((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
(strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \
(strcpy_error((dest), (destMax), (src))))
/* for strcat_s performance optimization */
#if defined(__GNUC__)
#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \
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; \
} \
if (catRestSize == 0) { \
catRet = EINVAL; \
} else if ((strlen(src) + 1) <= catRestSize) { \
memcpy(catTmpDst, (src), strlen(src) + 1); \
catRet = EOK; \
} else { \
catRet = ERANGE; \
} \
if (catRet != EOK) { \
catRet = strcat_s((dest), (destMax), (src)); \
} \
} else { \
catRet = strcat_s((dest), (destMax), (src)); \
} \
catRet; \
})
#else
#define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src))
#endif
/* for strncat_s performance optimization */
#if defined(__GNUC__)
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \
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; \
} \
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'; \
} else { \
memcpy(ncatTmpDest, (src), strlen(src) + 1); \
} \
} else { \
ncatRet = ERANGE; \
} \
if (ncatRet != EOK) { \
ncatRet = strncat_s((dest), (destMax), (src), (count)); \
} \
} else { \
ncatRet = strncat_s((dest), (destMax), (src), (count)); \
} \
ncatRet; \
})
#else
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count))
#endif
/* SECUREC_MEMCPY_SM do NOT check buffer overlap by default */
#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \
(!(((size_t)(destMax) == 0) || \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((void *)(src) == NULL))? \
(memcpy((dest), (src), (count)), EOK) : \
(memcpy_s((dest), (destMax), (src), (count))))
#define SECUREC_MEMSET_SM(dest, destMax, c, count) \
(!(((size_t)(destMax) == 0) || \
(((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \
(memset((dest), (c), (count)), EOK) : \
(memset_s((dest), (destMax), (c), (count))))
#endif
#endif /* __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7 */
aux_source_directory(. SECUREC_SRCS)
add_library(securec ${SECUREC_SRCS})
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The fscanf_s function is equivalent to fscanf except that the c, s,
* and [ conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a*)
* The fscanf function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same
* form and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
* format Format control string, see Format Specifications.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The convered value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int fscanf_s(FILE *stream, const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vfscanf_s(stream, format, argList);
va_end(argList);
(void)argList; /* to clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The fwscanf_s function is the wide-character equivalent of the fscanf_s function
* The fwscanf_s function reads data from the current position of stream into
* the locations given by argument (if any). Each argument must be a pointer
* to a variable of a type that corresponds to a type specifier in format.
* format controls the interpretation of the input fields and has the same
* form and function as the format argument for scanf.
*
* <INPUT PARAMETERS>
* stream Pointer to FILE structure.
* format Format control string, see Format Specifications.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* Each of these functions returns the number of fields successfully converted
* and assigned; the return value does not include fields that were read but
* not assigned. A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int fwscanf_s(FILE *stream, const wchar_t *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vfwscanf_s(stream, format, argList);
va_end(argList);
(void)argList; /* to clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "securecutil.h"
static void SecTrimCRLF(char *buffer, size_t len)
{
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';
}
return;
}
/*
* <FUNCTION 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
* The line consists of all characters up to and including
* the first newline character ('\n'). gets_s then replaces the newline
* character with a null character ('\0') before returning the line.
* If the first character read is the end-of-file character, a null character
* is stored at the beginning of buffer and NULL is returned.
*
* <INPUT PARAMETERS>
* buffer Storage location for input string.
* numberOfElements The size of the buffer.
*
* <OUTPUT PARAMETERS>
* buffer is updated
*
* <RETURN VALUE>
* buffer Successful operation
* NULL Improper parameter or read fail
*/
char *gets_s(char *buffer, size_t numberOfElements)
{
size_t len;
#ifdef SECUREC_COMPATIBLE_WIN_FORMAT
size_t bufferSize = ((numberOfElements == (size_t)-1) ? SECUREC_STRING_MAX_LEN : numberOfElements);
#else
size_t bufferSize = numberOfElements;
#endif
if (buffer == NULL || bufferSize == 0 || bufferSize > SECUREC_STRING_MAX_LEN) {
SECUREC_ERROR_INVALID_PARAMTER("gets_s");
return NULL;
}
if (fgets(buffer, (int)bufferSize, stdin) == NULL) {
return NULL;
}
len = strlen(buffer);
if (len > 0 && len < bufferSize) {
SecTrimCRLF(buffer, len);
}
return buffer;
}
此差异已折叠。
此差异已折叠。
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "securecutil.h"
#ifdef SECUREC_NOT_CALL_LIBC_CORE_API
/*
* Implementing memory data movement
*/
static void SecUtilMemmove(void *dst, const void *src, size_t count)
{
unsigned char *pDest = (unsigned char *)dst;
const unsigned char *pSrc = (const unsigned char *)src;
size_t maxCount = count;
if (dst <= src || pDest >= (pSrc + maxCount)) {
/*
* Non-Overlapping Buffers
* copy from lower addresses to higher addresses
*/
while (maxCount--) {
*pDest = *pSrc;
++pDest;
++pSrc;
}
} else {
/*
* Overlapping Buffers
* copy from higher addresses to lower addresses
*/
pDest = pDest + maxCount - 1;
pSrc = pSrc + maxCount - 1;
while (maxCount--) {
*pDest = *pSrc;
--pDest;
--pSrc;
}
}
}
#endif
/*
* <FUNCTION DESCRIPTION>
* The memmove_s function copies count bytes of characters from src to dest.
* This function can be assigned correctly when memory overlaps.
* <INPUT PARAMETERS>
* dest Destination object.
* destMax Size of the destination buffer.
* src Source object.
* count Number of characters to copy.
*
* <OUTPUT PARAMETERS>
* dest buffer is uptdated.
*
* <RETURN VALUE>
* EOK Success
* EINVAL dest is NULL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* EINVAL_AND_RESET dest != NULL and src is NULLL and destMax != 0 and destMax <= SECUREC_MEM_MAX_LEN
* ERANGE destMax > SECUREC_MEM_MAX_LEN or destMax is 0
* ERANGE_AND_RESET count > destMax and dest != NULL and src != NULL and destMax != 0
* and destMax <= SECUREC_MEM_MAX_LEN
*
* If an error occured, dest will be filled with 0 when dest and destMax valid.
* If some regions of the source area and the destination overlap, memmove_s
* ensures that the original source bytes in the overlapping region are copied
* before being overwritten.
*/
errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count)
{
if (destMax == 0 || destMax > SECUREC_MEM_MAX_LEN) {
SECUREC_ERROR_INVALID_RANGE("memmove_s");
return ERANGE;
}
if (dest == NULL || src == NULL) {
SECUREC_ERROR_INVALID_PARAMTER("memmove_s");
if (dest != NULL) {
(void)memset(dest, 0, destMax);
return EINVAL_AND_RESET;
}
return EINVAL;
}
if (count > destMax) {
(void)memset(dest, 0, destMax);
SECUREC_ERROR_INVALID_RANGE("memmove_s");
return ERANGE_AND_RESET;
}
if (dest == src) {
return EOK;
}
if (count > 0) {
#ifdef SECUREC_NOT_CALL_LIBC_CORE_API
SecUtilMemmove(dest, src, count);
#else
/* use underlying memmove for performance consideration */
(void)memmove(dest, src, count);
#endif
}
return EOK;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(memmove_s);
#endif
此差异已折叠。
此差异已折叠。
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "securec.h"
/*
* <FUNCTION DESCRIPTION>
* The scanf_s function is equivalent to fscanf_s with the argument stdin interposed before the arguments to scanf_s
* The scanf_s function reads data from the standard input stream stdin and
* writes the data into the location that's given by argument. Each argument
* must be a pointer to a variable of a type that corresponds to a type specifier
* in format. If copying occurs between strings that overlap, the behavior is
* undefined.
*
* <INPUT PARAMETERS>
* format Format control string.
* ... Optional arguments.
*
* <OUTPUT PARAMETERS>
* ... The converted value stored in user assigned address
*
* <RETURN VALUE>
* Returns the number of fields successfully converted and assigned;
* the return value does not include fields that were read but not assigned.
* A return value of 0 indicates that no fields were assigned.
* return -1 if an error occurs.
*/
int scanf_s(const char *format, ...)
{
int ret; /* If initialization causes e838 */
va_list argList;
va_start(argList, format);
ret = vscanf_s(format, argList);
va_end(argList);
(void)argList; /* to clear e438 last value assigned not used , the compiler will optimize this code */
return ret;
}
此差异已折叠。
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Avoid duplicate header files,not include securecutil.h */
#include "securecutil.h"
#if defined(ANDROID) && (SECUREC_HAVE_WCTOMB || SECUREC_HAVE_MBTOWC)
#include <wchar.h>
#if SECUREC_HAVE_WCTOMB
/*
* Convert wide characters to narrow multi-bytes
*/
int wctomb(char *s, wchar_t wc)
{
return wcrtomb(s, wc, NULL);
}
#endif
#if SECUREC_HAVE_MBTOWC
/*
* Converting narrow multi-byte characters to wide characters
*/
int mbtowc(wchar_t *pwc, const char *s, size_t n)
{
return mbrtowc(pwc, s, n, NULL);
}
#endif
#endif
/* high Num << 8 | num of SPC Ver */
#define SECUREC_C_VERSION (0x5 << 8)
#define SECUREC_SPC_VERSION 7
#define SECUREC_VERSION_STR "Huawei Secure C V100R001C01SPC007B002"
/* SPC verNumber<->verStr like:
* 0X201<->C01
* 0X202<->SPC001 Redefine numbers after this version
* 0X502<->SPC002
* 0X503<->SPC003
* ...
* 0X50a<->SPC010
* 0X50b<->SPC011
* ...
*/
/* CP verNumber<->verStr like:
* 0X601<->CP0001
* 0X602<->CP0002
* ...
*/
const char *GetHwSecureCVersion(unsigned short *verNumber)
{
if (verNumber != NULL) {
*verNumber = (unsigned short)(SECUREC_C_VERSION | SECUREC_SPC_VERSION);
}
return SECUREC_VERSION_STR;
}
#if SECUREC_IN_KERNEL
EXPORT_SYMBOL(GetHwSecureCVersion);
#endif
此差异已折叠。
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define SECUREC_FORMAT_OUTPUT_INPUT 1
#ifdef SECUREC_FOR_WCHAR
#undef SECUREC_FOR_WCHAR
#endif
#include "secinput.h"
#include "input.inl"
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册