From 845bef3240436e109a60ef66030f048ae50242e3 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 02:13:07 +0000 Subject: [PATCH 01/10] =?UTF-8?q?=E9=9D=9E=E5=AE=89=E5=85=A8=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuyifei --- frameworks/libhilog/BUILD.gn | 5 ++- .../libhilog/vsnprintf/include/vsprintf_p.h | 21 ++++++++++++ frameworks/libhilog/vsnprintf/output_p.inl | 32 +++++++++++-------- frameworks/libhilog/vsnprintf/vsprintf_p.c | 21 ++++++++++++ interfaces/native/innerkits/BUILD.gn | 6 +++- 5 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 frameworks/libhilog/vsnprintf/include/vsprintf_p.h create mode 100644 frameworks/libhilog/vsnprintf/vsprintf_p.c diff --git a/frameworks/libhilog/BUILD.gn b/frameworks/libhilog/BUILD.gn index d1ca37c..c8bbd92 100644 --- a/frameworks/libhilog/BUILD.gn +++ b/frameworks/libhilog/BUILD.gn @@ -63,7 +63,10 @@ template("libhilog_source") { "$utils_root/log_utils.cpp", ] - vsnprintf_sources = [ "$vsnprintf_root/vsnprintf_s_p.c" ] + vsnprintf_sources = [ + "$vsnprintf_root/vsnprintf_s_p.c", + "$vsnprintf_root/vsprintf_p.c", + ] sources = [ "hilog.cpp", diff --git a/frameworks/libhilog/vsnprintf/include/vsprintf_p.h b/frameworks/libhilog/vsnprintf/include/vsprintf_p.h new file mode 100644 index 0000000..579f289 --- /dev/null +++ b/frameworks/libhilog/vsnprintf/include/vsprintf_p.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Huawei Device 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. + */ + +#ifndef HILOG_OVERRIDE_VSPRINTF_P_H +#define HILOG_OVERRIDE_VSPRINTF_P_H + +int vsprintf_p(char *strDest, size_t destMax, const char *format, va_list argList); + +#endif /* HILOG_OVERRIDE_VSPRINTF_P_H */ \ No newline at end of file diff --git a/frameworks/libhilog/vsnprintf/output_p.inl b/frameworks/libhilog/vsnprintf/output_p.inl index eb6ba05..42e9c1a 100644 --- a/frameworks/libhilog/vsnprintf/output_p.inl +++ b/frameworks/libhilog/vsnprintf/output_p.inl @@ -19,6 +19,8 @@ * And sufficient input validation is performed before calling */ +#include "vsprintf_p.h" + #ifndef OUTPUT_P_INL_2B263E9C_43D8_44BB_B17A_6D2033DECEE5 #define OUTPUT_P_INL_2B263E9C_43D8_44BB_B17A_6D2033DECEE5 @@ -58,14 +60,14 @@ typedef union { #endif } SecBuffer; -static int SecIndirectSprintf(char *strDest, const char *format, ...) +static int SecIndirectSprintf(char *strDest, size_t destMax, const char *format, ...) { int ret; /* If initialization causes e838 */ va_list arglist; va_start(arglist, format); SECUREC_MASK_MSVC_CRT_WARNING - ret = vsprintf(strDest, format, arglist); + ret = vsprintf_p(strDest, destMax, format, arglist); SECUREC_END_MASK_MSVC_CRT_WARNING va_end(arglist); (void)arglist; /* to clear e438 last value assigned not used , the compiler will optimize this code */ @@ -689,6 +691,7 @@ NORMAL_CHAR: /* floating point conversion */ formatBuf.str = buffer.str; /* output buffer for float string with default size */ + size_t formatBufLen = sizeof(buffer); /* compute the precision value */ if (formatAttr.precision < 0) { @@ -718,7 +721,8 @@ NORMAL_CHAR: if (bufferSize >= SECUREC_BUFFER_SIZE) { /* the current value of SECUREC_BUFFER_SIZE could NOT store the formatted float string */ /* size include '+' and '\0' */ - floatBuf = (char *)SECUREC_MALLOC(((size_t)(unsigned int)bufferSize + (size_t)2)); + formatBufLen = (size_t)(unsigned int)bufferSize + (size_t)2; + floatBuf = (char *)SECUREC_MALLOC(formatBufLen); if (floatBuf != NULL) { formatBuf.str = floatBuf; } else { @@ -772,32 +776,32 @@ NORMAL_CHAR: long double tmp = (long double)va_arg(arglist, long double); /* call system sprintf to format float value */ if (formatAttr.dynWidth && formatAttr.dynPrecision) { - textLen = SecIndirectSprintf(formatBuf.str, (char *)fltFmtStr, + textLen = SecIndirectSprintf(formatBuf.str, formatBufLen, (char *)fltFmtStr, formatAttr.fldWidth,formatAttr.precision, tmp); } else if (formatAttr.dynWidth) { - textLen = SecIndirectSprintf(formatBuf.str, (char *)fltFmtStr, + textLen = SecIndirectSprintf(formatBuf.str, formatBufLen, (char *)fltFmtStr, formatAttr.fldWidth, tmp); } else if (formatAttr.dynPrecision) { - textLen = SecIndirectSprintf(formatBuf.str, (char *)fltFmtStr, + textLen = SecIndirectSprintf(formatBuf.str, formatBufLen, (char *)fltFmtStr, formatAttr.precision, tmp); } else { - textLen = SecIndirectSprintf(formatBuf.str, (char *)fltFmtStr, tmp); + textLen = SecIndirectSprintf(formatBuf.str, formatBufLen, (char *)fltFmtStr, tmp); } } else #endif { double tmp = (double)va_arg(arglist, double); if (formatAttr.dynWidth && formatAttr.dynPrecision) { - textLen = SecIndirectSprintf(formatBuf.str, (char *)fltFmtStr, formatAttr.fldWidth, - formatAttr.precision, tmp); + textLen = SecIndirectSprintf(formatBuf.str, formatBufLen, (char *)fltFmtStr, + formatAttr.fldWidth, formatAttr.precision, tmp); } else if (formatAttr.dynWidth) { - textLen = SecIndirectSprintf(formatBuf.str, (char *)fltFmtStr, formatAttr.fldWidth, - tmp); + textLen = SecIndirectSprintf(formatBuf.str, formatBufLen, (char *)fltFmtStr, + formatAttr.fldWidth, tmp); } else if (formatAttr.dynPrecision) { - textLen = SecIndirectSprintf(formatBuf.str, (char *)fltFmtStr, formatAttr.precision, - tmp); + textLen = SecIndirectSprintf(formatBuf.str, formatBufLen, (char *)fltFmtStr, + formatAttr.precision, tmp); } else { - textLen = SecIndirectSprintf(formatBuf.str, (char *)fltFmtStr, tmp); + textLen = SecIndirectSprintf(formatBuf.str, formatBufLen, (char *)fltFmtStr, tmp); } } diff --git a/frameworks/libhilog/vsnprintf/vsprintf_p.c b/frameworks/libhilog/vsnprintf/vsprintf_p.c new file mode 100644 index 0000000..5ca49ca --- /dev/null +++ b/frameworks/libhilog/vsnprintf/vsprintf_p.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Huawei Device 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 + +int vsprintf_p(char *strDest, size_t destMax, const char *format, va_list argList) +{ + return vsprintf_s(strDest, destMax, format, argList); +} \ No newline at end of file diff --git a/interfaces/native/innerkits/BUILD.gn b/interfaces/native/innerkits/BUILD.gn index 6acc3af..bdb885e 100644 --- a/interfaces/native/innerkits/BUILD.gn +++ b/interfaces/native/innerkits/BUILD.gn @@ -136,7 +136,10 @@ ohos_static_library("libhilog_base") { "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", ] - vsnprintf_sources = [ "$vsnprintf_root/vsnprintf_s_p.c" ] + vsnprintf_sources = [ + "$vsnprintf_root/vsnprintf_s_p.c", + "$vsnprintf_root/vsprintf_p.c", + ] sources = [ "$libhilog_base_root/hilog_base.c" ] sources += vsnprintf_sources @@ -145,6 +148,7 @@ ohos_static_library("libhilog_base") { "HILOG_PROHIBIT_ALLOCATION", ] configs = [ ":libhilog_base_config" ] + external_deps = [ "bounds_checking_function:libsec_static" ] subsystem_name = "hiviewdfx" part_name = "hilog" -- Gitee From 66c0b5b82a6abefad702916bf5f9924c947c35d7 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 02:15:03 +0000 Subject: [PATCH 02/10] update frameworks/libhilog/vsnprintf/include/vsprintf_p.h. Signed-off-by: liuyifei --- frameworks/libhilog/vsnprintf/include/vsprintf_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/libhilog/vsnprintf/include/vsprintf_p.h b/frameworks/libhilog/vsnprintf/include/vsprintf_p.h index 579f289..8c0a060 100644 --- a/frameworks/libhilog/vsnprintf/include/vsprintf_p.h +++ b/frameworks/libhilog/vsnprintf/include/vsprintf_p.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device 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 -- Gitee From 55ad131d7b565700fcdb469c2cf3fe0ae143525f Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 02:15:40 +0000 Subject: [PATCH 03/10] update frameworks/libhilog/vsnprintf/vsprintf_p.c. Signed-off-by: liuyifei --- frameworks/libhilog/vsnprintf/vsprintf_p.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/libhilog/vsnprintf/vsprintf_p.c b/frameworks/libhilog/vsnprintf/vsprintf_p.c index 5ca49ca..0078381 100644 --- a/frameworks/libhilog/vsnprintf/vsprintf_p.c +++ b/frameworks/libhilog/vsnprintf/vsprintf_p.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device 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 -- Gitee From 1816b13fedf8ad9aa0375ff5a6879e1eb4e80c35 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 03:52:36 +0000 Subject: [PATCH 04/10] update frameworks/libhilog/vsnprintf/include/vsprintf_p.h. Signed-off-by: liuyifei --- .../vsnprintf/include/{vsprintf_p.h => vsprintf_p.c} | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) rename frameworks/libhilog/vsnprintf/include/{vsprintf_p.h => vsprintf_p.c} (92%) diff --git a/frameworks/libhilog/vsnprintf/include/vsprintf_p.h b/frameworks/libhilog/vsnprintf/include/vsprintf_p.c similarity index 92% rename from frameworks/libhilog/vsnprintf/include/vsprintf_p.h rename to frameworks/libhilog/vsnprintf/include/vsprintf_p.c index 8c0a060..68ec83f 100644 --- a/frameworks/libhilog/vsnprintf/include/vsprintf_p.h +++ b/frameworks/libhilog/vsnprintf/include/vsprintf_p.c @@ -15,7 +15,10 @@ #ifndef HILOG_OVERRIDE_VSPRINTF_P_H #define HILOG_OVERRIDE_VSPRINTF_P_H - + +#include +#include + int vsprintf_p(char *strDest, size_t destMax, const char *format, va_list argList); #endif /* HILOG_OVERRIDE_VSPRINTF_P_H */ \ No newline at end of file -- Gitee From ca5452d90c7ec1de2e9d7fa86f78e3c582c7bdf7 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 03:53:43 +0000 Subject: [PATCH 05/10] rename Signed-off-by: liuyifei --- .../libhilog/vsnprintf/include/{vsprintf_p.c => vsprintf_p.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frameworks/libhilog/vsnprintf/include/{vsprintf_p.c => vsprintf_p.h} (100%) diff --git a/frameworks/libhilog/vsnprintf/include/vsprintf_p.c b/frameworks/libhilog/vsnprintf/include/vsprintf_p.h similarity index 100% rename from frameworks/libhilog/vsnprintf/include/vsprintf_p.c rename to frameworks/libhilog/vsnprintf/include/vsprintf_p.h -- Gitee From eb10be44d42d7004a2940d231edec6797efc2f5e Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 03:54:36 +0000 Subject: [PATCH 06/10] update frameworks/libhilog/vsnprintf/vsprintf_p.c. Signed-off-by: liuyifei --- frameworks/libhilog/vsnprintf/vsprintf_p.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/libhilog/vsnprintf/vsprintf_p.c b/frameworks/libhilog/vsnprintf/vsprintf_p.c index 0078381..2a633ef 100644 --- a/frameworks/libhilog/vsnprintf/vsprintf_p.c +++ b/frameworks/libhilog/vsnprintf/vsprintf_p.c @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "vsprintf_p.h" + #include int vsprintf_p(char *strDest, size_t destMax, const char *format, va_list argList) -- Gitee From 7353088c2beddef64693f51b231c4635f3b9a0b3 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 04:14:26 +0000 Subject: [PATCH 07/10] update frameworks/libhilog/vsnprintf/output_p.inl. Signed-off-by: liuyifei --- frameworks/libhilog/vsnprintf/output_p.inl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frameworks/libhilog/vsnprintf/output_p.inl b/frameworks/libhilog/vsnprintf/output_p.inl index 42e9c1a..38922d9 100644 --- a/frameworks/libhilog/vsnprintf/output_p.inl +++ b/frameworks/libhilog/vsnprintf/output_p.inl @@ -720,8 +720,7 @@ NORMAL_CHAR: if (bufferSize >= SECUREC_BUFFER_SIZE) { /* the current value of SECUREC_BUFFER_SIZE could NOT store the formatted float string */ - /* size include '+' and '\0' */ - formatBufLen = (size_t)(unsigned int)bufferSize + (size_t)2; + formatBufLen = (size_t)(unsigned int)bufferSize + (size_t)2; // size 2: include '+' and '\0' floatBuf = (char *)SECUREC_MALLOC(formatBufLen); if (floatBuf != NULL) { formatBuf.str = floatBuf; -- Gitee From 6d3fb231123311138728df0ca2f34800664af433 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 06:10:25 +0000 Subject: [PATCH 08/10] update frameworks/libhilog/vsnprintf/include/vsprintf_p.h. Signed-off-by: liuyifei --- frameworks/libhilog/vsnprintf/include/vsprintf_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/libhilog/vsnprintf/include/vsprintf_p.h b/frameworks/libhilog/vsnprintf/include/vsprintf_p.h index 68ec83f..fecb5fc 100644 --- a/frameworks/libhilog/vsnprintf/include/vsprintf_p.h +++ b/frameworks/libhilog/vsnprintf/include/vsprintf_p.h @@ -19,6 +19,6 @@ #include #include -int vsprintf_p(char *strDest, size_t destMax, const char *format, va_list argList); +int VsprintfP(char *strDest, size_t destMax, const char *format, va_list argList); #endif /* HILOG_OVERRIDE_VSPRINTF_P_H */ \ No newline at end of file -- Gitee From d5806322eadf1facc555c43c1d7e06aaecdcbc94 Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 06:11:35 +0000 Subject: [PATCH 09/10] update frameworks/libhilog/vsnprintf/vsprintf_p.c. Signed-off-by: liuyifei --- frameworks/libhilog/vsnprintf/vsprintf_p.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/libhilog/vsnprintf/vsprintf_p.c b/frameworks/libhilog/vsnprintf/vsprintf_p.c index 2a633ef..1df454f 100644 --- a/frameworks/libhilog/vsnprintf/vsprintf_p.c +++ b/frameworks/libhilog/vsnprintf/vsprintf_p.c @@ -17,7 +17,7 @@ #include -int vsprintf_p(char *strDest, size_t destMax, const char *format, va_list argList) +int VsprintfP(char *strDest, size_t destMax, const char *format, va_list argList) { return vsprintf_s(strDest, destMax, format, argList); } \ No newline at end of file -- Gitee From d1a5d529986f7e6dd1dc73c164e12eb180e2bfdb Mon Sep 17 00:00:00 2001 From: liuyifei Date: Tue, 20 Aug 2024 06:12:21 +0000 Subject: [PATCH 10/10] update frameworks/libhilog/vsnprintf/output_p.inl. Signed-off-by: liuyifei --- frameworks/libhilog/vsnprintf/output_p.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/libhilog/vsnprintf/output_p.inl b/frameworks/libhilog/vsnprintf/output_p.inl index 38922d9..06a14fc 100644 --- a/frameworks/libhilog/vsnprintf/output_p.inl +++ b/frameworks/libhilog/vsnprintf/output_p.inl @@ -67,7 +67,7 @@ static int SecIndirectSprintf(char *strDest, size_t destMax, const char *format, va_start(arglist, format); SECUREC_MASK_MSVC_CRT_WARNING - ret = vsprintf_p(strDest, destMax, format, arglist); + ret = VsprintfP(strDest, destMax, format, arglist); SECUREC_END_MASK_MSVC_CRT_WARNING va_end(arglist); (void)arglist; /* to clear e438 last value assigned not used , the compiler will optimize this code */ -- Gitee