Browse Source

Fix compilation warnings and little leak

pull/110/head
emanuele-f 6 years ago
parent
commit
04226c09c8
  1. 7
      edge.c
  2. 20
      edge_utils.c
  3. 3
      sn.c
  4. 3
      transform_aes.c
  5. 3
      tuntap_linux.c
  6. 2
      wire.c

7
edge.c

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

20
edge_utils.c

@ -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. /** Initialise an edge to defaults.
* *
* This also initialises the NULL transform operation opstruct. * 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. */ /** Send a REGISTER_SUPER packet to the current supernode. */
static void send_register_super(n2n_edge_t * eee, static void send_register_super(n2n_edge_t * eee,
const n2n_sock_t * supernode) { const n2n_sock_t * supernode) {
uint8_t pktbuf[N2N_PKT_BUF_SIZE]; uint8_t pktbuf[N2N_PKT_BUF_SIZE] = {0};
size_t idx; size_t idx;
/* ssize_t sent; */ /* ssize_t sent; */
n2n_common_t cmn; n2n_common_t cmn;
@ -832,8 +843,9 @@ static int handle_PACKET(n2n_edge_t * eee,
} }
else else
{ {
traceEvent(TRACE_ERROR, "invalid transop ID: %u, expected %u", traceEvent(TRACE_ERROR, "invalid transop ID: expected %s(%u), got %s(%u)",
rx_transop_id, eee->conf.transop_id); 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)); clear_peer_list(&(eee->known_peers));
eee->transop.deinit(&eee->transop); eee->transop.deinit(&eee->transop);
memset(eee, 0, sizeof(*eee)); free(eee);
} }
/* ************************************** */ /* ************************************** */

3
sn.c

@ -435,7 +435,8 @@ static int load_allowed_n2n_communities(char *path) {
s = (struct n2n_allowed_communities*)malloc(sizeof(struct n2n_allowed_communities)); s = (struct n2n_allowed_communities*)malloc(sizeof(struct n2n_allowed_communities));
if(s != NULL) { 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); HASH_ADD_STR(allowed_communities, community, s);
num_communities++; num_communities++;
traceEvent(TRACE_INFO, "Added allowed community '%s' [total: %u]", traceEvent(TRACE_INFO, "Added allowed community '%s' [total: %u]",

3
transform_aes.c

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

3
tuntap_linux.c

@ -84,7 +84,8 @@ int tuntap_open(tuntap_dev *device,
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP|IFF_NO_PI; /* Want a TAP device for layer 2 frames. */ 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); rc = ioctl(device->fd, TUNSETIFF, (void *)&ifr);
if(rc < 0) { if(rc < 0) {

2
wire.c

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

Loading…
Cancel
Save