From 70d2e8f10a96f751d0c8245c5f9583dc4e20804e Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Thu, 9 Jul 2020 12:18:05 +0300 Subject: [PATCH] qrouting: Fix Coverity paranoid warning Even if the buffer can never be overflown here thanks to the CHAR(64) DB schema restriction, if the user were to change the DB schema by hand and extend the column to 65+ chars, it would crash OpenSIPS, so the warning makes some sense. Fixes CID #211387 --- modules/qrouting/qr_load.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/qrouting/qr_load.c b/modules/qrouting/qr_load.c index 1f0958e4b5e..ed2d19739e7 100644 --- a/modules/qrouting/qr_load.c +++ b/modules/qrouting/qr_load.c @@ -50,10 +50,15 @@ str qr_profiles_table = str_init("qr_profiles"); static inline void add_profile(qr_profile_t *prof, const int *int_vals, char * const *str_vals, const double *double_vals) { - int i; + int i, len; prof->id = int_vals[INT_VALS_ID]; - strncpy(prof->name, str_vals[STR_VALS_PROFILE_NAME], QR_NAME_COL_SZ + 1); + + len = strlen(str_vals[STR_VALS_PROFILE_NAME]); + if (len > QR_NAME_COL_SZ) + len = QR_NAME_COL_SZ; + memcpy(prof->name, str_vals[STR_VALS_PROFILE_NAME], len); + prof->name[len] = '\0'; prof->asr1 = double_vals[DBL_VALS_WARN_ASR]; prof->ccr1 = double_vals[DBL_VALS_WARN_CCR];