diff --git a/directory_service.c b/directory_service.c index 95ab83d9..bbdc350f 100644 --- a/directory_service.c +++ b/directory_service.c @@ -42,8 +42,7 @@ static uint8_t allow_duplicates = 1; static struct item *create_item(const char *key){ struct item *ret=calloc(1,sizeof(struct item)); - strncpy(ret->key,key,sizeof(ret->key)); - ret->key[sizeof(ret->key) -1]=0; + buf_strncpy_nul(ret->key, key); return ret; } @@ -85,8 +84,8 @@ static int add_item(const char *key, const char *value){ *last_ptr = item = create_item(key); - strncpy(item->value,value,sizeof(item->value)); - item->value[sizeof(item->value) -1]=0; + buf_strncpy_nul(item->value, value); + // expire after 20 minutes item->expires = gettime_ms()+1200000; return 0; diff --git a/dna_helper.c b/dna_helper.c index 06f8ecfd..ac0129b7 100644 --- a/dna_helper.c +++ b/dna_helper.c @@ -617,8 +617,7 @@ dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char request_bufend = request_buffer + strbuf_len(b); request_source = source; request_port = source_port; - strncpy(request_did, did, sizeof request_did); - request_did[sizeof request_did - 1] = '\0'; + buf_strncpy_nul(request_did, did); } if (dna_helper_started) { sched_requests.poll.fd = dna_helper_stdin; diff --git a/overlay_interface.c b/overlay_interface.c index 76b27755..84c2f3be 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -579,7 +579,7 @@ overlay_interface_init(const char *name, bzero(interface, sizeof(overlay_interface)); interface->state=INTERFACE_STATE_DOWN; - strncpy(interface->name, name, sizeof interface->name); + buf_strncpy_nul(interface->name, name); set_destination_ref(&interface->destination, NULL); interface->destination = new_destination(interface); diff --git a/str.h b/str.h index 2112792b..33040a02 100644 --- a/str.h +++ b/str.h @@ -38,6 +38,7 @@ #define alloca_strdup(str) strcpy(alloca(strlen(str) + 1), (str)) #define alloca_strndup(str,len) strncpy_nul(alloca((len) + 1), (str), (len) + 1) +#define buf_strncpy_nul(buf,str) strncpy_nul((buf), (str), sizeof(buf)) /* Like strncpy(3) but ensures the string is nul terminated. * diff --git a/vomp.c b/vomp.c index aa8720d5..ffb017d9 100644 --- a/vomp.c +++ b/vomp.c @@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "str.h" #include "conf.h" #include "strbuf.h" -#include "strlcpy.h" #include "mdp_client.h" #include "overlay_address.h" #include "overlay_buffer.h" @@ -800,8 +799,8 @@ int vomp_dial(struct subscriber *local, struct subscriber *remote, const char *l 0); /* Copy local / remote phone numbers */ - strlcpy(call->local.did, local_did, sizeof(call->local.did)); - strlcpy(call->remote.did, remote_did, sizeof(call->remote.did)); + buf_strncpy_nul(call->local.did, local_did); + buf_strncpy_nul(call->remote.did, remote_did); vomp_update_local_state(call, VOMP_STATE_CALLPREP); // remember that we initiated this call, not the other party @@ -855,9 +854,9 @@ static int vomp_extract_remote_codec_list(struct vomp_call_state *call, struct o if (!call->initiated_call){ const char *p; if (ob_remaining(payload)>0 && (p=ob_get_str_ptr(payload))){ - strlcpy(call->remote.did, p, sizeof(call->remote.did)); + buf_strncpy_nul(call->remote.did, p); if (ob_remaining(payload)>0 && (p=ob_get_str_ptr(payload))) - strlcpy(call->local.did, p, sizeof(call->local.did)); + buf_strncpy_nul(call->local.did, p); } } return 0;