diff --git a/bundle.json b/bundle.json index 3bd0fbac035263bd0b71c9264ff732390f4fce5f..e0f6daba605fa5cf1b2838ec091d842e5757963b 100644 --- a/bundle.json +++ b/bundle.json @@ -21,6 +21,7 @@ "components": [], "third_party": [ "abseil-cpp", + "bounds_checking_function", "icu", "protobuf" ] diff --git a/cpp/BUILD.gn b/cpp/BUILD.gn index 4f4b577d777ea7f00e993f55be0e57244c63cc79..34635df3b071cdd4f0e92bc933e162f64012c4b2 100644 --- a/cpp/BUILD.gn +++ b/cpp/BUILD.gn @@ -22,6 +22,7 @@ group("build_module") { config("phonenumber_config") { include_dirs = [ "//third_party/abseil-cpp/abseil-cpp", + "//third_party/bounds_checking_function/include", "//third_party/icu/icu4c/source/common", "//third_party/icu/icu4c/source/i18n", "//third_party/icu/icu4c/source", @@ -79,6 +80,7 @@ ohos_shared_library("phonenumber_standard") { deps = [ "//third_party/abseil-cpp:absl_base", "//third_party/abseil-cpp:absl_strings", + "//third_party/bounds_checking_function:libsec_shared", "//third_party/icu/icu4c:shared_icui18n", "//third_party/icu/icu4c:shared_icuuc", "//third_party/protobuf:protobuf_lite", @@ -107,6 +109,7 @@ ohos_shared_library("geocoding") { "src/phonenumbers/phonenumber.pb.h", ] deps = [ + "//third_party/bounds_checking_function:libsec_shared", "//third_party/icu/icu4c:shared_icuuc", "//third_party/libphonenumber/cpp:phonenumber_standard", ] diff --git a/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc b/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc index b78ac99f6df41996a7c830fa7da7f39688f5fc5a..fe46b61aaf4f7d1cbcd69a8d5e5132ba8609eb56 100644 --- a/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc +++ b/cpp/src/phonenumbers/geocoding/geocoding_warpper.cc @@ -9,6 +9,7 @@ #include #include // NOLINT(build/include_order) #include +#include "securec.h" using icu::UnicodeString; using i18n::phonenumbers::PhoneNumber; @@ -16,7 +17,7 @@ using i18n::phonenumbers::PhoneNumberUtil; using i18n::phonenumbers::PhoneNumberOfflineGeocoder; using icu::Locale; -extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res) { +extern "C" int exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength = 128) { if(offlineGeocoder == NULL) { offlineGeocoder = new PhoneNumberOfflineGeocoder(); } @@ -29,9 +30,9 @@ extern "C" void exposeLocationName(const char* pNumber, const char* locale, char PhoneNumberUtil::ErrorType type = util->Parse(number, uLocale.getCountry(), &phoneNumber); if (type != PhoneNumberUtil::ErrorType::NO_PARSING_ERROR) { std::string empty = ""; - std::strcpy(res, empty.c_str()); + return strcpy_s(res, resLength, empty.c_str()); } std::string result = offlineGeocoder->GetDescriptionForNumber(phoneNumber, uLocale); - std::strcpy(res, result.c_str()); + return strcpy_s(res, resLength, result.c_str()); } diff --git a/cpp/src/phonenumbers/geocoding/geocoding_warpper.h b/cpp/src/phonenumbers/geocoding/geocoding_warpper.h index ca5141fb4391932c7e4607ba45c1ce2120b27907..b3d00ff8897440f672ccb37eb08c4e5f4d3b5b91 100644 --- a/cpp/src/phonenumbers/geocoding/geocoding_warpper.h +++ b/cpp/src/phonenumbers/geocoding/geocoding_warpper.h @@ -9,4 +9,4 @@ using i18n::phonenumbers::PhoneNumberOfflineGeocoder; PhoneNumberOfflineGeocoder* offlineGeocoder = NULL; i18n::phonenumbers::PhoneNumberUtil* util = NULL; -extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res); +extern "C" int exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength);