mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Add buf_strncpy_nul(), use in place of strlcpy()
This commit is contained in:
parent
90e02141d1
commit
3ab7e04497
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
1
str.h
1
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.
|
||||
*
|
||||
|
9
vomp.c
9
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;
|
||||
|
Loading…
Reference in New Issue
Block a user