[Asterisk-code-review] Compiler fixes for gcc 10 (asterisk[13])

George Joseph asteriskteam at digium.com
Wed Jun 10 13:56:05 CDT 2020


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14457 )

Change subject: Compiler fixes for gcc 10
......................................................................

Compiler fixes for gcc 10

This patch fixes a few compile warnings/errors that now occur when using gcc
10+.

Also, the Makefile.rules check to turn off partial inlining in gcc versions
greater or equal to 8.2.1 had a bug where it only it only checked against
versions with at least 3 numbers (ex: 8.2.1 vs 10). This patch now ensures
any version above the specified version is correctly compared.

Change-Id: I54718496eb0c3ce5bd6d427cd279a29e8d2825f9
---
M Makefile.rules
M addons/ooh323c/src/decode.c
M addons/ooh323c/src/ooSocket.c
M addons/ooh323c/src/oochannels.c
M apps/app_stack.c
M apps/app_voicemail.c
M include/asterisk/app.h
M main/http.c
M main/message.c
M main/pbx.c
M main/pbx_variables.c
M main/stasis.c
M pbx/pbx_dundi.c
M res/parking/parking_bridge_features.c
M res/res_pjsip_registrar.c
M tests/test_locale.c
M utils/astman.c
M utils/db1-ast/hash/ndbm.c
M utils/extconf.c
M utils/muted.c
20 files changed, 114 insertions(+), 84 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/Makefile.rules b/Makefile.rules
index c45d9d0..6173701 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -60,6 +60,7 @@
 endif
 
 OPTIMIZE?=-O3
+
 ifneq ($(findstring darwin,$(OSARCH)),)
   ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
     # Snow Leopard/Lion has an issue with this optimization flag on large files (like chan_sip)
@@ -67,15 +68,15 @@
   endif
 endif
 
-# gcc version 8.2.1 and above must have partial-inlining disabled to avoid documented bug.
-# We must handle cross-compiling and clang so make sure the compiler version string has "gcc"
-# somewhere in it before testing the version.
-CC_VERS_STRING=$(shell $(CC) --version | grep -i gcc)
-ifneq ($(CC_VERS_STRING),)
-GCC_VER_GTE821:=$(shell expr `echo '$(CC_VERS_STRING)' | cut -d ' ' -f 3 | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/'` \>= 80201)
-ifeq ($(GCC_VER_GTE821),1)
-    OPTIMIZE+=-fno-partial-inlining
-endif
+ifeq ($(CC),gcc)
+    # gcc version 8.2.1 and above must have partial-inlining disabled in order
+    # to avoid a documented bug. Sort to make the lowest version number come
+    # first. If it's the specified version then the current gcc version is equal
+    # to or greater, so add the custom optimization rule.
+    gcc_versions=$(shell printf "%s\n" $$(gcc -dumpversion) 8.2.1 | sort -n)
+    ifeq ($(firstword $(gcc_versions)),8.2.1)
+        OPTIMIZE+=-fno-partial-inlining
+	endif
 endif
 
 ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_CODE_COVERAGE),no)
diff --git a/addons/ooh323c/src/decode.c b/addons/ooh323c/src/decode.c
index 3ce74bf..d0579c6 100644
--- a/addons/ooh323c/src/decode.c
+++ b/addons/ooh323c/src/decode.c
@@ -737,6 +737,10 @@
          nbits -= 8;
       }
 
+      if (nbits <= 0) {
+         return ASN_OK;
+      }
+
       /* Copy last partial byte */
 
       if (nbits >= rshift) {
@@ -752,7 +756,7 @@
 
          pctxt->buffer.bitOffset = 8 - nbitsInLastOctet;
       }
-      else if (nbits > 0) {  /* nbits < rshift */
+      else {  /* nbits > 0 && nbits < rshift */
          pbuffer[i] =
             pctxt->buffer.data[pctxt->buffer.byteIndex] << lshift;
          pctxt->buffer.bitOffset = rshift - nbits;
@@ -832,8 +836,8 @@
 
 int decodeSemiConsInteger (OOCTXT* pctxt, ASN1INT* pvalue, ASN1INT lower)
 {
-   signed char b;
-   unsigned char ub;
+   signed char b = 0;
+   unsigned char ub = 0;
    ASN1UINT nbytes;
    int stat;
 
diff --git a/addons/ooh323c/src/ooSocket.c b/addons/ooh323c/src/ooSocket.c
index 31c3732..75095f6 100644
--- a/addons/ooh323c/src/ooSocket.c
+++ b/addons/ooh323c/src/ooSocket.c
@@ -391,7 +391,7 @@
 
    if (destAddr != 0) {
       if ((host = ast_sockaddr_stringify_addr(&addr)) != NULL)
-      	strncpy(destAddr, host, strlen(host));
+       memcpy(destAddr, host, strlen(host) + 1);
    }
    if (destPort != 0)
       *destPort =  ast_sockaddr_port(&addr);
diff --git a/addons/ooh323c/src/oochannels.c b/addons/ooh323c/src/oochannels.c
index f7dd7c5..e5f1290 100644
--- a/addons/ooh323c/src/oochannels.c
+++ b/addons/ooh323c/src/oochannels.c
@@ -454,7 +454,7 @@
                  call->callToken);
 
    if (remoteIP[0]) {
-	strncpy(call->remoteIP, remoteIP, strlen(remoteIP));
+	memcpy(call->remoteIP, remoteIP, strlen(remoteIP) + 1);
    }
 
    ast_mutex_unlock(&call->Lock);
diff --git a/apps/app_stack.c b/apps/app_stack.c
index cc5c487..46c0d9c 100644
--- a/apps/app_stack.c
+++ b/apps/app_stack.c
@@ -315,13 +315,14 @@
 static struct gosub_stack_frame *gosub_allocate_frame(const char *context, const char *extension, int priority, int in_subroutine, unsigned char arguments)
 {
 	struct gosub_stack_frame *new = NULL;
-	int len_extension = strlen(extension), len_context = strlen(context);
+	int len_extension = strlen(extension) + 1;
+	int len_context = strlen(context) + 1;
 
-	if ((new = ast_calloc(1, sizeof(*new) + 2 + len_extension + len_context))) {
+	if ((new = ast_calloc(1, sizeof(*new) + len_extension + len_context))) {
 		AST_LIST_HEAD_INIT_NOLOCK(&new->varshead);
-		strcpy(new->extension, extension);
-		new->context = new->extension + len_extension + 1;
-		strcpy(new->context, context);
+		ast_copy_string(new->extension, extension, len_extension);
+		new->context = new->extension + len_extension;
+		ast_copy_string(new->context, context, len_context);
 		new->priority = priority;
 		new->in_subroutine = in_subroutine ? 1 : 0;
 		new->arguments = arguments;
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 9f58088..e7e0a5c 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -1217,10 +1217,12 @@
 
 static int inprocess_count(const char *context, const char *mailbox, int delta)
 {
-	struct inprocess *i, *arg = ast_alloca(sizeof(*arg) + strlen(context) + strlen(mailbox) + 2);
-	arg->context = arg->mailbox + strlen(mailbox) + 1;
-	strcpy(arg->mailbox, mailbox); /* SAFE */
-	strcpy(arg->context, context); /* SAFE */
+	int context_len = strlen(context) + 1;
+	int mailbox_len = strlen(mailbox) + 1;
+	struct inprocess *i, *arg = ast_alloca(sizeof(*arg) + context_len + mailbox_len);
+	arg->context = arg->mailbox + mailbox_len;
+	ast_copy_string(arg->mailbox, mailbox, mailbox_len); /* SAFE */
+	ast_copy_string(arg->context, context, context_len); /* SAFE */
 	ao2_lock(inprocess_container);
 	if ((i = ao2_find(inprocess_container, arg, 0))) {
 		int ret = ast_atomic_fetchadd_int(&i->count, delta);
@@ -1231,13 +1233,13 @@
 	if (delta < 0) {
 		ast_log(LOG_WARNING, "BUG: ref count decrement on non-existing object???\n");
 	}
-	if (!(i = ao2_alloc(sizeof(*i) + strlen(context) + strlen(mailbox) + 2, NULL))) {
+	if (!(i = ao2_alloc(sizeof(*i) + context_len + mailbox_len, NULL))) {
 		ao2_unlock(inprocess_container);
 		return 0;
 	}
-	i->context = i->mailbox + strlen(mailbox) + 1;
-	strcpy(i->mailbox, mailbox); /* SAFE */
-	strcpy(i->context, context); /* SAFE */
+	i->context = i->mailbox + mailbox_len;
+	ast_copy_string(i->mailbox, mailbox, mailbox_len); /* SAFE */
+	ast_copy_string(i->context, context, context_len); /* SAFE */
 	i->count = delta;
 	ao2_link(inprocess_container, i);
 	ao2_unlock(inprocess_container);
@@ -13377,13 +13379,15 @@
 	unsigned int len;
 	struct mwi_sub *mwi_sub;
 	struct mwi_sub_task *p = datap;
+	size_t context_len;
 
 	len = sizeof(*mwi_sub) + 1;
 	if (!ast_strlen_zero(p->mailbox))
 		len += strlen(p->mailbox);
 
+	context_len = strlen(p->context) + 1; /* Allow for seperator */
 	if (!ast_strlen_zero(p->context))
-		len += strlen(p->context) + 1; /* Allow for seperator */
+		len += context_len;
 
 	if (!(mwi_sub = ast_calloc(1, len)))
 		return -1;
@@ -13394,7 +13398,7 @@
 
 	if (!ast_strlen_zero(p->context)) {
 		strcat(mwi_sub->mailbox, "@");
-		strcat(mwi_sub->mailbox, p->context);
+		ast_copy_string(mwi_sub->mailbox, p->context, context_len);
 	}
 
 	AST_RWLIST_WRLOCK(&mwi_subs);
@@ -13808,8 +13812,8 @@
 	}
 	mapping->alias = mapping->buf;
 	mapping->mailbox = mapping->buf + from_len;
-	strcpy(mapping->alias, alias); /* Safe */
-	strcpy(mapping->mailbox, mailbox); /* Safe */
+	ast_copy_string(mapping->alias, alias, from_len); /* Safe */
+	ast_copy_string(mapping->mailbox, mailbox, to_len); /* Safe */
 
 	return mapping;
 }
diff --git a/include/asterisk/app.h b/include/asterisk/app.h
index df3990f..1f751fc 100644
--- a/include/asterisk/app.h
+++ b/include/asterisk/app.h
@@ -1231,11 +1231,14 @@
   \note This defines a structure type, but does not declare an instance
   of the structure. That must be done separately.
  */
+
 #define AST_DEFINE_APP_ARGS_TYPE(type, arglist) \
 	struct type { \
 		unsigned int argc; \
-		char *argv[0]; \
-		arglist \
+		union { \
+			char *argv[sizeof(struct {arglist}) / sizeof(char *)]; \
+			struct {arglist}; \
+		}; \
 	}
 
 /*!
diff --git a/main/http.c b/main/http.c
index 0600bfa..c3ba95f 100644
--- a/main/http.c
+++ b/main/http.c
@@ -2049,6 +2049,7 @@
 	struct http_uri_redirect *redirect, *cur;
 	unsigned int target_len;
 	unsigned int total_len;
+	size_t dest_len;
 
 	dest = ast_strdupa(value);
 	dest = ast_skip_blanks(dest);
@@ -2062,14 +2063,15 @@
 	}
 
 	target_len = strlen(target) + 1;
-	total_len = sizeof(*redirect) + target_len + strlen(dest) + 1;
+	dest_len = strlen(dest) + 1;
+	total_len = sizeof(*redirect) + target_len + dest_len;
 
 	if (!(redirect = ast_calloc(1, total_len))) {
 		return;
 	}
 	redirect->dest = redirect->target + target_len;
 	strcpy(redirect->target, target);
-	strcpy(redirect->dest, dest);
+	ast_copy_string(redirect->dest, dest, dest_len);
 
 	AST_RWLIST_WRLOCK(&uri_redirects);
 
diff --git a/main/message.c b/main/message.c
index 128f4d9..b3d739e 100644
--- a/main/message.c
+++ b/main/message.c
@@ -1419,7 +1419,7 @@
 	/* Set the ones we have and increment the offset */
 	for (i=0; i < count; i++) {
 		len = (strlen(attributes[i].value) + 1);
-		strcpy(msg->buf + current_offset, attributes[i].value); /* Safe */
+		ast_copy_string(msg->buf + current_offset, attributes[i].value, len); /* Safe */
 		msg->attribute_value_offsets[attributes[i].type] = current_offset;
 		current_offset += len;
 	}
diff --git a/main/pbx.c b/main/pbx.c
index 17708a1..a22d307 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -6396,6 +6396,8 @@
 	i = ao2_iterator_init(hints, AO2_ITERATOR_DONTLOCK);
 	for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
 		if (ao2_container_count(hint->callbacks)) {
+			size_t exten_len;
+
 			ao2_lock(hint);
 			if (!hint->exten) {
 				/* The extension has already been destroyed. (Should never happen here) */
@@ -6403,7 +6405,8 @@
 				continue;
 			}
 
-			length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2
+			exten_len = strlen(hint->exten->exten) + 1;
+			length = exten_len + strlen(hint->exten->parent->name) + 1
 				+ sizeof(*saved_hint);
 			if (!(saved_hint = ast_calloc(1, length))) {
 				ao2_unlock(hint);
@@ -6423,7 +6426,7 @@
 			saved_hint->context = saved_hint->data;
 			strcpy(saved_hint->data, hint->exten->parent->name);
 			saved_hint->exten = saved_hint->data + strlen(saved_hint->context) + 1;
-			strcpy(saved_hint->exten, hint->exten->exten);
+			ast_copy_string(saved_hint->exten, hint->exten->exten, exten_len);
 			if (hint->last_presence_subtype) {
 				saved_hint->last_presence_subtype = ast_strdup(hint->last_presence_subtype);
 			}
diff --git a/main/pbx_variables.c b/main/pbx_variables.c
index 88c4ec1..3dfaf63 100644
--- a/main/pbx_variables.c
+++ b/main/pbx_variables.c
@@ -213,14 +213,10 @@
 	}
 
 	if (length >= 0 && length < lr) {	/* truncate if necessary */
-		char *tmp = ast_str_buffer(value);
-		tmp[length] = '\0';
-		ast_str_update(value);
+		ast_str_truncate(value, length);
 	} else if (length < 0) {
 		if (lr > -length) { /* After we remove from the front and from the rear, is there anything left? */
-			char *tmp = ast_str_buffer(value);
-			tmp[lr + length] = '\0';
-			ast_str_update(value);
+			ast_str_truncate(value, lr + length);
 		} else {
 			ast_str_reset(value);
 		}
diff --git a/main/stasis.c b/main/stasis.c
index c9b71cf..07d470a 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -1476,9 +1476,10 @@
 static struct stasis_subscription_change *subscription_change_alloc(struct stasis_topic *topic, const char *uniqueid, const char *description)
 {
 	size_t description_len = strlen(description) + 1;
+	size_t uniqueid_len = strlen(uniqueid) + 1;
 	struct stasis_subscription_change *change;
 
-	change = ao2_alloc_options(sizeof(*change) + description_len + strlen(uniqueid) + 1,
+	change = ao2_alloc_options(sizeof(*change) + description_len + uniqueid_len,
 		subscription_change_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
 	if (!change) {
 		return NULL;
@@ -1486,7 +1487,7 @@
 
 	strcpy(change->description, description); /* SAFE */
 	change->uniqueid = change->description + description_len;
-	strcpy(change->uniqueid, uniqueid); /* SAFE */
+	ast_copy_string(change->uniqueid, uniqueid, uniqueid_len); /* SAFE */
 	ao2_ref(topic, +1);
 	change->topic = topic;
 
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index f3951a7..1fa3b58 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -721,7 +721,7 @@
 {
 	struct dundi_query_state *st = data;
 	struct dundi_ie_data ied;
-	struct dundi_hint_metadata hmd;
+	struct dundi_hint_metadata hmd = {0};
 	char eid_str[20];
 
 	ast_debug(1, "Whee, precaching '%s@%s' for '%s'\n", st->called_number, st->called_context,
@@ -3894,7 +3894,6 @@
 
 static void reschedule_precache(const char *number, const char *context, int expiration)
 {
-	int len;
 	struct dundi_precache_queue *qe, *prev;
 
 	AST_LIST_LOCK(&pcq);
@@ -3906,16 +3905,16 @@
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
 	if (!qe) {
-		len = sizeof(*qe);
-		len += strlen(number) + 1;
-		len += strlen(context) + 1;
-		if (!(qe = ast_calloc(1, len))) {
+		int len = sizeof(*qe);
+		int num_len = strlen(number) + 1;
+		int context_len = strlen(context) + 1;
+		if (!(qe = ast_calloc(1, len + num_len + context_len))) {
 			AST_LIST_UNLOCK(&pcq);
 			return;
 		}
 		strcpy(qe->number, number);
-		qe->context = qe->number + strlen(number) + 1;
-		strcpy(qe->context, context);
+		qe->context = qe->number + num_len + 1;
+		ast_copy_string(qe->context, context, context_len);
 	}
 	time(&qe->expiration);
 	qe->expiration += expiration;
diff --git a/res/parking/parking_bridge_features.c b/res/parking/parking_bridge_features.c
index 5a013ea..69b437b 100644
--- a/res/parking/parking_bridge_features.c
+++ b/res/parking/parking_bridge_features.c
@@ -161,7 +161,8 @@
 	struct parked_subscription_data *subscription_data;
 
 	char *parker_uuid = ast_strdupa(ast_channel_uniqueid(chan));
-	size_t parker_uuid_size = strlen(parker_uuid) + 1;
+	size_t parker_uuid_size;
+	size_t parkee_uuid_size;
 
 	/* If there is already a subscription, get rid of it. */
 	wipe_subscription_datastore(chan);
@@ -175,8 +176,11 @@
 		return -1;
 	}
 
+	parker_uuid_size = strlen(parker_uuid) + 1;
+	parkee_uuid_size = strlen(parkee_uuid) + 1;
+
 	if (!(subscription_data = ast_calloc(1, sizeof(*subscription_data) + parker_uuid_size +
-			strlen(parkee_uuid) + 1))) {
+			parkee_uuid_size))) {
 		ast_datastore_free(datastore);
 		ast_free(parked_datastore);
 		return -1;
@@ -189,8 +193,7 @@
 
 	subscription_data->hangup_after = hangup_after;
 	subscription_data->parkee_uuid = subscription_data->parker_uuid + parker_uuid_size;
-	strcpy(subscription_data->parkee_uuid, parkee_uuid);
-	strcpy(subscription_data->parker_uuid, parker_uuid);
+	ast_copy_string(subscription_data->parkee_uuid, parkee_uuid, parkee_uuid_size);
 
 	if (!(parked_datastore->parked_subscription = stasis_subscribe_pool(ast_parking_topic(), parker_update_cb, subscription_data))) {
 		return -1;
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index 75db9f1..820e8e7 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -423,12 +423,13 @@
 	aor_size = aor_name ? strlen(aor_name) : 0;
 	if (contact->prune_on_boot && type != CONTACT_DELETE_SHUTDOWN && aor_size) {
 		const char *contact_name = ast_sorcery_object_get_id(contact);
+		size_t contact_name_len = strlen(contact_name) + 1;
 		struct contact_transport_monitor *monitor = ast_alloca(
-			sizeof(*monitor) + 2 + aor_size + strlen(contact_name));
+			sizeof(*monitor) + 1 + aor_size + contact_name_len);
 
 		strcpy(monitor->aor_name, aor_name); /* Safe */
 		monitor->contact_name = monitor->aor_name + aor_size + 1;
-		strcpy(monitor->contact_name, contact_name); /* Safe */
+		ast_copy_string(monitor->contact_name, contact_name, contact_name_len); /* Safe */
 
 		if (transport) {
 			ast_sip_transport_monitor_unregister(transport,
@@ -775,6 +776,7 @@
 			}
 
 			if (prune_on_boot) {
+				size_t contact_name_len;
 				const char *contact_name;
 				struct contact_transport_monitor *monitor;
 
@@ -783,12 +785,13 @@
 				 * the contact won't be valid anymore if that happens.
 				 */
 				contact_name = ast_sorcery_object_get_id(contact);
-				monitor = ao2_alloc(sizeof(*monitor) + 2 + strlen(aor_name)
-					+ strlen(contact_name), NULL);
+				contact_name_len = strlen(contact_name) + 1;
+				monitor = ao2_alloc(sizeof(*monitor) + 1 + strlen(aor_name)
+					+ contact_name_len, NULL);
 				if (monitor) {
 					strcpy(monitor->aor_name, aor_name);/* Safe */
 					monitor->contact_name = monitor->aor_name + strlen(aor_name) + 1;
-					strcpy(monitor->contact_name, contact_name);/* Safe */
+					ast_copy_string(monitor->contact_name, contact_name, contact_name_len);/* Safe */
 
 					ast_sip_transport_monitor_register_replace(rdata->tp_info.transport,
 						register_contact_transport_shutdown_cb, monitor, contact_transport_monitor_matcher);
diff --git a/tests/test_locale.c b/tests/test_locale.c
index 811fa12..c270b91 100644
--- a/tests/test_locale.c
+++ b/tests/test_locale.c
@@ -100,6 +100,7 @@
 	ast_strftime(origlocalformat, sizeof(origlocalformat), "%c", &atm);
 
 	while ((dent = readdir(localedir))) {
+		size_t locallen;
 		size_t namelen;
 
 		if (dent->d_name[0] == '.') {
@@ -109,14 +110,17 @@
 		setlocale(LC_ALL, dent->d_name);
 		ast_strftime(localformat, sizeof(localformat), "%c", &atm);
 
+		locallen = strlen(localformat) + 1;
+		namelen = strlen(dent->d_name) + 1;
+
 		/* Store values */
-		if (!(tl = ast_calloc(1, sizeof(*tl) + strlen(localformat) + (namelen = strlen(dent->d_name)) + 2))) {
+		if (!(tl = ast_calloc(1, sizeof(*tl) + locallen + namelen))) {
 			continue;
 		}
 
-		strcpy(tl->name, dent->d_name); /* SAFE */
-		tl->localformat = tl->name + namelen + 1;
-		strcpy(tl->localformat, localformat); /* SAFE */
+		ast_copy_string(tl->name, dent->d_name, namelen); /* SAFE */
+		tl->localformat = tl->name + namelen;
+		ast_copy_string(tl->localformat, localformat, locallen); /* SAFE */
 
 		AST_LIST_INSERT_TAIL(&locales, tl, list);
 
diff --git a/utils/astman.c b/utils/astman.c
index ec06868..e1274b5 100644
--- a/utils/astman.c
+++ b/utils/astman.c
@@ -550,7 +550,7 @@
 
 	chan = newtListboxGetCurrent(c);
 	if (chan) {
-		strncpy(channame, chan->name, sizeof(channame) - 1);
+		snprintf(channame, sizeof(channame), "%s", chan->name);
 		snprintf(tmp, sizeof(tmp), "%s%s", tmp_prefix, channame);
 		if (get_user_input(tmp, dest, sizeof(dest)))
 			return;
diff --git a/utils/db1-ast/hash/ndbm.c b/utils/db1-ast/hash/ndbm.c
index 16202ed..3c63d48 100644
--- a/utils/db1-ast/hash/ndbm.c
+++ b/utils/db1-ast/hash/ndbm.c
@@ -79,8 +79,7 @@
 	info.cachesize = 0;
 	info.hash = NULL;
 	info.lorder = 0;
-	(void)strcpy(path, file); /* SAFE */
-	(void)strncat(path, DBM_SUFFIX, len - strlen(path) - 1);
+	snprintf(path, len, "%s%s", file, DBM_SUFFIX);
 	db = (DBM *)__hash_open(path, flags, mode, &info, 0);
 #ifndef	__GNUC__
 	free(path);
diff --git a/utils/extconf.c b/utils/extconf.c
index 63ec19d..639daaf 100644
--- a/utils/extconf.c
+++ b/utils/extconf.c
@@ -1312,14 +1312,16 @@
 {
 	struct ast_variable *variable;
 	int name_len = strlen(name) + 1;
+	size_t value_len = strlen(value) + 1;
+	size_t filename_len = strlen(filename) + 1;
 
-	if ((variable = ast_calloc(1, name_len + strlen(value) + 1 + strlen(filename) + 1 + sizeof(*variable)))) {
+	if ((variable = ast_calloc(1, name_len + value_len + filename_len + sizeof(*variable)))) {
 		variable->name = variable->stuff;
 		variable->value = variable->stuff + name_len;
-		variable->file = variable->value + strlen(value) + 1;
+		variable->file = variable->value + value_len;
 		strcpy(variable->name,name);
-		strcpy(variable->value,value);
-		strcpy(variable->file,filename);
+		ast_copy_string(variable->value, value, value_len);
+		ast_copy_string(variable->file, filename, filename_len);
 	}
 
 	return variable;
diff --git a/utils/muted.c b/utils/muted.c
index 2cdd7e2..eab7f20 100644
--- a/utils/muted.c
+++ b/utils/muted.c
@@ -163,12 +163,12 @@
 					fprintf(stderr, "host needs an argument (the host) at line %d\n", lineno);
 			} else if (!strcasecmp(buf, "user")) {
 				if (val && strlen(val))
-					strncpy(user, val, sizeof(user) - 1);
+					snprintf(user, sizeof(user), "%s", val);
 				else
 					fprintf(stderr, "user needs an argument (the user) at line %d\n", lineno);
 			} else if (!strcasecmp(buf, "pass")) {
 				if (val && strlen(val))
-					strncpy(pass, val, sizeof(pass) - 1);
+					snprintf(pass, sizeof(pass), "%s", val);
 				else
 					fprintf(stderr, "pass needs an argument (the password) at line %d\n", lineno);
 			} else if (!strcasecmp(buf, "smoothfade")) {
@@ -639,24 +639,29 @@
 		return -1;
 	}
 	if (!strncasecmp(resp, "Event: ", strlen("Event: "))) {
-		strncpy(event, resp + strlen("Event: "), sizeof(event) - 1);
+		int event_len = -1;
+		int channel_len = -1;
+		int newname_len = -1;
+		int oldname_len = -1;
+
+		event_len = snprintf(event, sizeof(event), "%s", resp + strlen("Event: "));
 		/* Consume the rest of the non-event */
 		while((resp = get_line()) && strlen(resp)) {
 			if (!strncasecmp(resp, "Channel: ", strlen("Channel: ")))
-				strncpy(channel, resp + strlen("Channel: "), sizeof(channel) - 1);
+				channel_len = snprintf(channel, sizeof(channel), "%s", resp + strlen("Channel: "));
 			if (!strncasecmp(resp, "Newname: ", strlen("Newname: ")))
-				strncpy(newname, resp + strlen("Newname: "), sizeof(newname) - 1);
+				newname_len = snprintf(newname, sizeof(newname), "%s", resp + strlen("Newname: "));
 			if (!strncasecmp(resp, "Oldname: ", strlen("Oldname: ")))
-				strncpy(oldname, resp + strlen("Oldname: "), sizeof(oldname) - 1);
+				oldname_len = snprintf(oldname, sizeof(oldname), "%s", resp + strlen("Oldname: "));
 		}
-		if (strlen(channel)) {
-			if (!strcasecmp(event, "Hangup"))
+		if (channel_len == strlen(channel)) {
+			if (event_len == strlen(event) && !strcasecmp(event, "Hangup"))
 				hangup_chan(channel);
 			else
 				offhook_chan(channel);
 		}
-		if (strlen(newname) && strlen(oldname)) {
-			if (!strcasecmp(event, "Rename")) {
+		if (newname_len == strlen(newname) && oldname_len == strlen(oldname)) {
+			if (event_len == strlen(event) && !strcasecmp(event, "Rename")) {
 				hangup_chan(oldname);
 				offhook_chan(newname);
 			}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14457
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I54718496eb0c3ce5bd6d427cd279a29e8d2825f9
Gerrit-Change-Number: 14457
Gerrit-PatchSet: 3
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200610/50597a3c/attachment-0001.html>


More information about the asterisk-code-review mailing list