// And we try to read the ones that end with ".conf"
if(l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) {
- snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name);
+ if(snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name) >= sizeof(fname)) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Pathname too long: %s/%s", dname, ep->d_name);
+ return false;
+ }
+
x = read_config_file(config_tree, fname, true);
}
}
strncpy(sa_un.sun_path, unixsocketname, sizeof(sa_un.sun_path));
+ sa_un.sun_path[sizeof(sa_un.sun_path) - 1] = 0;
+
if(connect(unix_fd, (struct sockaddr *)&sa_un, sizeof(sa_un)) >= 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "UNIX socket %s is still in use!", unixsocketname);
return false;
char invname[PATH_MAX];
struct stat st;
- snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name);
+
+ if(snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) {
+ fprintf(stderr, "Filename too long: %s" SLASH "%s\n", filename, ent->d_name);
+ continue;
+ }
if(!stat(invname, &st)) {
if(deadline < st.st_mtime) {
line[strlen(line) - 1] = 0;
char newbase[PATH_MAX];
- snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line);
+
+ if(snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line) >= sizeof(newbase)) {
+ fprintf(stderr, "Filename too long: " CONFDIR SLASH "tinc" SLASH "%s\n", line);
+ goto ask_netname;
+ }
if(rename(confbase, newbase)) {
fprintf(stderr, "Error trying to rename %s to %s: %s\n", confbase, newbase, strerror(errno));
if(iface) {
strncpy(ifr.ifr_name, iface, IFNAMSIZ);
+ ifr.ifr_name[IFNAMSIZ - 1] = 0;
}
if(!ioctl(device_fd, TUNSETIFF, &ifr)) {
strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
+ ifrname[IFNAMSIZ - 1] = 0;
free(iface);
iface = xstrdup(ifrname);
} else {
loghandle = RegisterEventSource(NULL, logident);
if(!loghandle) {
- fprintf(stderr, "Could not open log handle!");
+ fprintf(stderr, "Could not open log handle!\n");
logmode = LOGMODE_NULL;
}
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
+ ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0;
if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr))) {
closesocket(nfd);
#endif
strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
+ ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0;
if(ioctl(device_fd, SIOCGIFINDEX, &ifr)) {
close(device_fd);
char buf[PATH_MAX];
char buf2[PATH_MAX];
+ask_filename:
+
/* Check stdin and stdout */
if(ask && tty) {
/* Ask for a file and/or directory name. */
#endif
/* The directory is a relative path or a filename. */
getcwd(directory, sizeof(directory));
- snprintf(buf2, sizeof(buf2), "%s" SLASH "%s", directory, filename);
+
+ if(snprintf(buf2, sizeof(buf2), "%s" SLASH "%s", directory, filename) >= sizeof(buf2)) {
+ fprintf(stderr, "Filename too long: %s" SLASH "%s\n", directory, filename);
+
+ if(ask && tty) {
+ goto ask_filename;
+ } else {
+ return NULL;
+ }
+ }
+
filename = buf2;
}
strncpy(sa.sun_path, unixsocketname, sizeof(sa.sun_path));
+ sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
+
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if(fd < 0) {
}
char fname[PATH_MAX];
- snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ent->d_name);
+
+ if(snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ent->d_name) >= sizeof(fname)) {
+ fprintf(stderr, "Filename too long: %s" SLASH "%s\n", dname, ent->d_name);
+ continue;
+ }
+
FILE *f = fopen(fname, "r");
if(!f) {
FILE *tf = NULL;
if(action >= -1) {
- snprintf(tmpfile, sizeof(tmpfile), "%s.config.tmp", filename);
+ if(snprintf(tmpfile, sizeof(tmpfile), "%s.config.tmp", filename) >= sizeof(tmpfile)) {
+ fprintf(stderr, "Filename too long: %s.config.tmp\n", filename);
+ return 1;
+ }
+
tf = fopen(tmpfile, "w");
if(!tf) {
fclose(out);
}
- snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name);
+ if(snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name) >= sizeof(filename)) {
+ fprintf(stderr, "Filename too long: %s" SLASH "%s\n", hosts_dir, name);
+ return 1;
+ }
if(!force && !access(filename, F_OK)) {
fprintf(stderr, "Host configuration file %s already exists, skipping.\n", filename);
static struct WSAData wsa_state;
if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
- fprintf(stderr, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
+ fprintf(stderr, "System call `%s' failed: %s\n", "WSAStartup", winerror(GetLastError()));
return false;
}
listen_sun.sun_family = AF_UNIX;
strncpy(listen_sun.sun_path, device, sizeof(listen_sun.sun_path));
+ listen_sun.sun_path[sizeof(listen_sun.sun_path) - 1] = 0;
if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof(listen_sun)) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind %s to %s: %s", device_info, device, strerror(errno));
#else
-#if MINIUPNPC_API_VERSION > 15
+#if MINIUPNPC_API_VERSION > 17
#warning "The version of libminiupnpc you're building against seems to be too recent. Expect trouble."
#endif