[Asterisk-code-review] Compiler fixes for gcc 10 (asterisk[16])
Kevin Harwell
asteriskteam at digium.com
Wed Jun 3 09:52:54 CDT 2020
Kevin Harwell has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14456 )
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 include/asterisk/strings.h
M main/dns_srv.c
M main/http.c
M main/logger.c
M main/message.c
M main/pbx.c
M main/pbx_variables.c
M main/stasis.c
M main/strings.c
M pbx/pbx_dundi.c
M res/parking/parking_bridge_features.c
M res/res_pjsip_registrar.c
M tests/test_locale.c
20 files changed, 104 insertions(+), 72 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/56/14456/1
diff --git a/Makefile.rules b/Makefile.rules
index 24ecf7f..934e44a 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -63,6 +63,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)
@@ -70,15 +71,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 55bb0ac..151c1cf 100644
--- a/addons/ooh323c/src/ooSocket.c
+++ b/addons/ooh323c/src/ooSocket.c
@@ -389,7 +389,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 ca7b09c..3add1f3 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 4560865..179694b 100644
--- a/apps/app_stack.c
+++ b/apps/app_stack.c
@@ -313,13 +313,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 0bd9a6b..ada7382 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -1234,10 +1234,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);
@@ -1248,13 +1250,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);
@@ -13350,13 +13352,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;
@@ -13367,7 +13371,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);
@@ -13856,8 +13860,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 4264556..91d06aa 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/include/asterisk/strings.h b/include/asterisk/strings.h
index c56a139..20d2505 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -1221,6 +1221,7 @@
for (; *str; ++str) {
*str = tolower(*str);
+ /* ast_log(LOG_VERBOSE, "#### return it = %c\n", *str); /\* 449dff997c29a247fe36000420fb0fcaf5542867 *\/ */
}
return str_orig;
diff --git a/main/dns_srv.c b/main/dns_srv.c
index e11c84e..4847f89 100644
--- a/main/dns_srv.c
+++ b/main/dns_srv.c
@@ -49,6 +49,7 @@
struct ast_dns_srv_record *srv;
int host_size;
char host[NI_MAXHOST] = "";
+ size_t host_len;
ptr = dns_find_record(data, size, query->result->answer, query->result->answer_size);
ast_assert(ptr != NULL);
@@ -89,7 +90,8 @@
return NULL;
}
- srv = ast_calloc(1, sizeof(*srv) + size + strlen(host) + 1);
+ host_len = strlen(host) + 1;
+ srv = ast_calloc(1, sizeof(*srv) + size + host_len);
if (!srv) {
return NULL;
}
@@ -99,7 +101,7 @@
srv->port = port;
srv->host = srv->data + size;
- strcpy((char *)srv->host, host); /* SAFE */
+ ast_copy_string((char *)srv->host, host, host_len); /* SAFE */
srv->generic.data_ptr = srv->data;
return (struct ast_dns_record *)srv;
diff --git a/main/http.c b/main/http.c
index 3088552..a0f15f4 100644
--- a/main/http.c
+++ b/main/http.c
@@ -2025,6 +2025,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);
@@ -2038,14 +2039,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/logger.c b/main/logger.c
index cf9357e..c66d820 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -2294,7 +2294,7 @@
va_list ap;
unsigned long indent = (unsigned long)ast_threadstorage_get_ptr(&trace_indent);
struct ast_str *fmt = ast_str_create(128);
- char *direction;
+ const char *direction = "";
if (!fmt) {
return;
diff --git a/main/message.c b/main/message.c
index dc81b4e..66d051c 100644
--- a/main/message.c
+++ b/main/message.c
@@ -1421,7 +1421,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 f7b813b..bbc6df9 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -6519,6 +6519,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) */
@@ -6526,7 +6528,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);
@@ -6546,7 +6549,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 c1463d0..e3c26f8 100644
--- a/main/pbx_variables.c
+++ b/main/pbx_variables.c
@@ -211,14 +211,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 9799ee6..ab6f42c 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -498,6 +498,7 @@
{
struct topic_proxy *proxy;
struct stasis_topic* topic_tmp;
+ size_t detail_len;
if (!topic || !name || !strlen(name) || !detail) {
return -1;
@@ -514,8 +515,10 @@
return -1;
}
+ detail_len = strlen(detail) + 1;
+
proxy = ao2_t_weakproxy_alloc(
- sizeof(*proxy) + strlen(name) + 1 + strlen(detail) + 1, NULL, name);
+ sizeof(*proxy) + strlen(name) + 1 + detail_len, NULL, name);
if (!proxy) {
ao2_unlock(topic_all);
@@ -527,7 +530,7 @@
proxy->detail = proxy->name + strlen(name) + 1;
strcpy(proxy->name, name); /* SAFE */
- strcpy(proxy->detail, detail); /* SAFE */
+ ast_copy_string(proxy->detail, detail, detail_len); /* SAFE */
proxy->creationtime = ast_tvnow();
/* We have exclusive access to proxy, no need for locking here. */
@@ -1620,9 +1623,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;
@@ -1630,7 +1634,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/main/strings.c b/main/strings.c
index 0cd4692..f41a81d 100644
--- a/main/strings.c
+++ b/main/strings.c
@@ -42,6 +42,8 @@
#include "asterisk/pbx.h"
#include "asterisk/vector.h"
+
+
/*!
* core handler for dynamic strings.
* This is not meant to be called directly, but rather through the
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index 1ab0676..a504171 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -722,7 +722,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,
@@ -3936,7 +3936,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);
@@ -3948,16 +3947,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 1278894..8c547aa 100644
--- a/res/parking/parking_bridge_features.c
+++ b/res/parking/parking_bridge_features.c
@@ -179,7 +179,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);
@@ -193,8 +194,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;
@@ -207,8 +211,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 172ecc8..523eb0a 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -422,12 +422,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,
@@ -774,6 +775,7 @@
}
if (prune_on_boot) {
+ size_t contact_name_len;
const char *contact_name;
struct contact_transport_monitor *monitor;
@@ -782,12 +784,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 99137c1..4fd6a34 100644
--- a/tests/test_locale.c
+++ b/tests/test_locale.c
@@ -98,6 +98,7 @@
ast_strftime(origlocalformat, sizeof(origlocalformat), "%c", &atm);
while ((dent = readdir(localedir))) {
+ size_t locallen;
size_t namelen;
if (dent->d_name[0] == '.') {
@@ -107,14 +108,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);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14456
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I54718496eb0c3ce5bd6d427cd279a29e8d2825f9
Gerrit-Change-Number: 14456
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200603/f6869353/attachment-0001.html>
More information about the asterisk-code-review
mailing list