Fix compilation warnings and little leak

This commit is contained in:
emanuele-f 2019-05-21 22:53:55 +02:00
parent bc904cfbcc
commit 04226c09c8
6 changed files with 28 additions and 10 deletions

7
edge.c
View File

@ -100,7 +100,8 @@ static int scan_address(char * ip_addr, size_t addr_size,
else
{
/* colon is not present */
strncpy(ip_addr, s, addr_size);
strncpy(ip_addr, s, addr_size-1);
ip_addr[addr_size-1] = '\0';
}
return retval;
@ -191,6 +192,7 @@ static int setOption(int optkey, char *optargument, n2n_priv_config_t *ec, n2n_e
{
memset(conf->community_name, 0, N2N_COMMUNITY_SIZE);
strncpy((char *)conf->community_name, optargument, N2N_COMMUNITY_SIZE);
conf->community_name[N2N_COMMUNITY_SIZE-1] = '\0';
break;
}
@ -226,6 +228,7 @@ static int setOption(int optkey, char *optargument, n2n_priv_config_t *ec, n2n_e
case 'm' : /* TUNTAP MAC address */
{
strncpy(ec->device_mac,optargument,N2N_MACNAMSIZ);
ec->device_mac[N2N_MACNAMSIZ-1] = '\0';
break;
}
@ -274,6 +277,7 @@ static int setOption(int optkey, char *optargument, n2n_priv_config_t *ec, n2n_e
case 'd': /* TUNTAP name */
{
strncpy(ec->tuntap_dev_name, optargument, N2N_IFNAMSIZ);
ec->tuntap_dev_name[N2N_IFNAMSIZ-1] = '\0';
break;
}
#endif
@ -302,6 +306,7 @@ static int setOption(int optkey, char *optargument, n2n_priv_config_t *ec, n2n_e
traceEvent(TRACE_WARNING, "Multiple subnet masks supplied");
}
strncpy(ec->netmask, optargument, N2N_NETMASK_STR_SIZE);
ec->netmask[N2N_NETMASK_STR_SIZE - 1] = '\0';
ec->got_s = 1;
break;
}

View File

@ -119,6 +119,17 @@ struct n2n_edge {
/* ************************************** */
static const char* transop_str(enum n2n_transform tr) {
switch(tr) {
case N2N_TRANSFORM_ID_NULL: return("null");
case N2N_TRANSFORM_ID_TWOFISH: return("twofish");
case N2N_TRANSFORM_ID_AESCBC: return("AES-CBC");
default: return("invalid");
};
}
/* ************************************** */
/** Initialise an edge to defaults.
*
* This also initialises the NULL transform operation opstruct.
@ -577,7 +588,7 @@ static ssize_t sendto_sock(int fd, const void * buf,
/** Send a REGISTER_SUPER packet to the current supernode. */
static void send_register_super(n2n_edge_t * eee,
const n2n_sock_t * supernode) {
uint8_t pktbuf[N2N_PKT_BUF_SIZE];
uint8_t pktbuf[N2N_PKT_BUF_SIZE] = {0};
size_t idx;
/* ssize_t sent; */
n2n_common_t cmn;
@ -832,8 +843,9 @@ static int handle_PACKET(n2n_edge_t * eee,
}
else
{
traceEvent(TRACE_ERROR, "invalid transop ID: %u, expected %u",
rx_transop_id, eee->conf.transop_id);
traceEvent(TRACE_ERROR, "invalid transop ID: expected %s(%u), got %s(%u)",
transop_str(eee->conf.transop_id), eee->conf.transop_id,
transop_str(rx_transop_id), rx_transop_id);
}
}
@ -1604,7 +1616,7 @@ void edge_term(n2n_edge_t * eee) {
clear_peer_list(&(eee->known_peers));
eee->transop.deinit(&eee->transop);
memset(eee, 0, sizeof(*eee));
free(eee);
}
/* ************************************** */

3
sn.c
View File

@ -435,7 +435,8 @@ static int load_allowed_n2n_communities(char *path) {
s = (struct n2n_allowed_communities*)malloc(sizeof(struct n2n_allowed_communities));
if(s != NULL) {
strncpy((char*)s->community, line, N2N_COMMUNITY_SIZE);
strncpy((char*)s->community, line, N2N_COMMUNITY_SIZE-1);
s->community[N2N_COMMUNITY_SIZE-1] = '\0';
HASH_ADD_STR(allowed_communities, community, s);
num_communities++;
traceEvent(TRACE_INFO, "Added allowed community '%s' [total: %u]",

View File

@ -144,8 +144,7 @@ static int transop_encode_aes( n2n_trans_op_t * arg,
* Using two calls to rand() because RAND_MAX is usually < 64bit
* (e.g. linux) and sometimes < 32bit (e.g. Windows).
*/
((uint32_t*)&iv_seed)[0] = rand();
((uint32_t*)&iv_seed)[1] = rand();
iv_seed = ((((uint64_t)rand() & 0xFFFFFFFF)) << 32) | rand();
encode_buf(outbuf, &idx, &iv_seed, sizeof(iv_seed));
/* Encrypt the assembly contents and write the ciphertext after the SA. */

View File

@ -84,7 +84,8 @@ int tuntap_open(tuntap_dev *device,
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP|IFF_NO_PI; /* Want a TAP device for layer 2 frames. */
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
strncpy(ifr.ifr_name, dev, IFNAMSIZ-1);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
rc = ioctl(device->fd, TUNSETIFF, (void *)&ifr);
if(rc < 0) {

2
wire.c
View File

@ -228,7 +228,7 @@ int decode_sock( n2n_sock_t * sock,
size_t * idx )
{
size_t * idx0=idx;
uint16_t f;
uint16_t f=0;
decode_uint16( &f, base, rem, idx );