Consistently allocate device and iface variables on the heap.
This fixes a segfault when no Device has been specified and tinc exits, and it would try to free() a static string. Thanks to Borg for spottin.
This commit is contained in:
parent
f81cea3bdc
commit
b069da90d6
7 changed files with 26 additions and 23 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "xalloc.h"
|
||||||
|
|
||||||
#define DEFAULT_DEVICE "/dev/tun0"
|
#define DEFAULT_DEVICE "/dev/tun0"
|
||||||
|
|
||||||
|
@ -37,9 +38,9 @@ typedef enum device_type {
|
||||||
} device_type_t;
|
} device_type_t;
|
||||||
|
|
||||||
int device_fd = -1;
|
int device_fd = -1;
|
||||||
char *device;
|
char *device = NULL;
|
||||||
char *iface;
|
char *iface = NULL;
|
||||||
char *device_info;
|
static char *device_info = NULL;
|
||||||
static int device_total_in = 0;
|
static int device_total_in = 0;
|
||||||
static int device_total_out = 0;
|
static int device_total_out = 0;
|
||||||
#if defined(HAVE_OPENBSD) || defined(HAVE_FREEBSD)
|
#if defined(HAVE_OPENBSD) || defined(HAVE_FREEBSD)
|
||||||
|
@ -54,10 +55,10 @@ bool setup_device(void) {
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||||
device = DEFAULT_DEVICE;
|
device = xstrdup(DEFAULT_DEVICE);
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
||||||
iface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
|
iface = xstrdup(rindex(device, '/') ? rindex(device, '/') + 1 : device);
|
||||||
|
|
||||||
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
|
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
|
||||||
logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
|
logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
|
||||||
|
|
|
@ -38,7 +38,7 @@ int device_fd = -1;
|
||||||
static HANDLE device_handle = INVALID_HANDLE_VALUE;
|
static HANDLE device_handle = INVALID_HANDLE_VALUE;
|
||||||
char *device = NULL;
|
char *device = NULL;
|
||||||
char *iface = NULL;
|
char *iface = NULL;
|
||||||
char *device_info = NULL;
|
static char *device_info = NULL;
|
||||||
|
|
||||||
static int device_total_in = 0;
|
static int device_total_in = 0;
|
||||||
static int device_total_out = 0;
|
static int device_total_out = 0;
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "xalloc.h"
|
||||||
|
|
||||||
typedef enum device_type_t {
|
typedef enum device_type_t {
|
||||||
DEVICE_TYPE_ETHERTAP,
|
DEVICE_TYPE_ETHERTAP,
|
||||||
|
@ -45,8 +46,8 @@ int device_fd = -1;
|
||||||
static device_type_t device_type;
|
static device_type_t device_type;
|
||||||
char *device;
|
char *device;
|
||||||
char *iface;
|
char *iface;
|
||||||
char ifrname[IFNAMSIZ];
|
static char ifrname[IFNAMSIZ];
|
||||||
char *device_info;
|
static char *device_info;
|
||||||
|
|
||||||
static int device_total_in = 0;
|
static int device_total_in = 0;
|
||||||
static int device_total_out = 0;
|
static int device_total_out = 0;
|
||||||
|
@ -58,13 +59,13 @@ bool setup_device(void)
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||||
device = DEFAULT_DEVICE;
|
device = xstrdup(DEFAULT_DEVICE);
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
||||||
#ifdef HAVE_LINUX_IF_TUN_H
|
#ifdef HAVE_LINUX_IF_TUN_H
|
||||||
iface = netname;
|
iface = xstrdup(netname);
|
||||||
#else
|
#else
|
||||||
iface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
|
iface = xstrdup(rindex(device, '/') ? rindex(device, '/') + 1 : device);
|
||||||
#endif
|
#endif
|
||||||
device_fd = open(device, O_RDWR | O_NONBLOCK);
|
device_fd = open(device, O_RDWR | O_NONBLOCK);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ int device_fd = 0;
|
||||||
static HANDLE device_handle = INVALID_HANDLE_VALUE;
|
static HANDLE device_handle = INVALID_HANDLE_VALUE;
|
||||||
char *device = NULL;
|
char *device = NULL;
|
||||||
char *iface = NULL;
|
char *iface = NULL;
|
||||||
char *device_info = NULL;
|
static char *device_info = NULL;
|
||||||
|
|
||||||
static int device_total_in = 0;
|
static int device_total_in = 0;
|
||||||
static int device_total_out = 0;
|
static int device_total_out = 0;
|
||||||
|
@ -52,7 +52,7 @@ static struct packetbuf {
|
||||||
|
|
||||||
static int nbufs = 64;
|
static int nbufs = 64;
|
||||||
|
|
||||||
DWORD WINAPI tapreader(void *bla) {
|
static DWORD WINAPI tapreader(void *bla) {
|
||||||
int sock, err, status;
|
int sock, err, status;
|
||||||
struct addrinfo *ai;
|
struct addrinfo *ai;
|
||||||
struct addrinfo hint = {
|
struct addrinfo hint = {
|
||||||
|
|
|
@ -29,12 +29,13 @@
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "route.h"
|
#include "route.h"
|
||||||
|
#include "xalloc.h"
|
||||||
|
|
||||||
int device_fd = -1;
|
int device_fd = -1;
|
||||||
char *device;
|
char *device;
|
||||||
char *iface;
|
char *iface;
|
||||||
char ifrname[IFNAMSIZ];
|
static char ifrname[IFNAMSIZ];
|
||||||
char *device_info;
|
static char *device_info;
|
||||||
|
|
||||||
static int device_total_in = 0;
|
static int device_total_in = 0;
|
||||||
static int device_total_out = 0;
|
static int device_total_out = 0;
|
||||||
|
@ -46,12 +47,11 @@ bool setup_device(void)
|
||||||
|
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
if(!get_config_string
|
if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
|
||||||
(lookup_config(config_tree, "Interface"), &iface))
|
iface = xstrdup("eth0");
|
||||||
iface = "eth0";
|
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||||
device = iface;
|
device = xstrdup(iface);
|
||||||
|
|
||||||
device_info = _("raw socket");
|
device_info = _("raw socket");
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,14 @@
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "xalloc.h"
|
||||||
|
|
||||||
#define DEFAULT_DEVICE "/dev/tun"
|
#define DEFAULT_DEVICE "/dev/tun"
|
||||||
|
|
||||||
int device_fd = -1;
|
int device_fd = -1;
|
||||||
char *device = NULL;
|
char *device = NULL;
|
||||||
char *iface = NULL;
|
char *iface = NULL;
|
||||||
char *device_info = NULL;
|
static char *device_info = NULL;
|
||||||
|
|
||||||
static int device_total_in = 0;
|
static int device_total_in = 0;
|
||||||
static int device_total_out = 0;
|
static int device_total_out = 0;
|
||||||
|
@ -51,7 +52,7 @@ bool setup_device(void)
|
||||||
cp();
|
cp();
|
||||||
|
|
||||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||||
device = DEFAULT_DEVICE;
|
device = xstrdup(DEFAULT_DEVICE);
|
||||||
|
|
||||||
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
|
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
|
||||||
logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
|
logger(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
|
||||||
|
|
|
@ -36,9 +36,9 @@ static int request_fd = -1;
|
||||||
static int data_fd = -1;
|
static int data_fd = -1;
|
||||||
static int write_fd = -1;
|
static int write_fd = -1;
|
||||||
static int state = 0;
|
static int state = 0;
|
||||||
char *device;
|
char *device = NULL;
|
||||||
char *iface = NULL;
|
char *iface = NULL;
|
||||||
char *device_info;
|
static char *device_info;
|
||||||
|
|
||||||
extern char *identname;
|
extern char *identname;
|
||||||
extern bool running;
|
extern bool running;
|
||||||
|
|
Loading…
Reference in a new issue