Replace a couple sprintf() with snprintf()
This commit is contained in:
parent
11dab6288d
commit
e58f6b0abb
4
auth.c
4
auth.c
@ -88,7 +88,7 @@ static int derive_key(struct vtun_host *host)
|
|||||||
|
|
||||||
static char *bf2cf(struct vtun_host *host)
|
static char *bf2cf(struct vtun_host *host)
|
||||||
{
|
{
|
||||||
static char str[20], * ptr = str;
|
static char str[32], * ptr = str;
|
||||||
|
|
||||||
*(ptr++) = '<';
|
*(ptr++) = '<';
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ static int cf2bf(char *str, struct vtun_host *host)
|
|||||||
char *ptr, *p;
|
char *ptr, *p;
|
||||||
int s;
|
int s;
|
||||||
|
|
||||||
if (strlen(str) >= 20) {
|
if (strlen(str) >= 32) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((ptr = strchr(str, '<'))) {
|
if ((ptr = strchr(str, '<'))) {
|
||||||
|
@ -42,12 +42,12 @@ int tap_open(char *dev)
|
|||||||
int i, fd;
|
int i, fd;
|
||||||
|
|
||||||
if( *dev ) {
|
if( *dev ) {
|
||||||
sprintf(tapname, "/dev/%s", dev);
|
snprintf(tapname, sizeof tapname, "/dev/%s", dev);
|
||||||
return open(tapname, O_RDWR);
|
return open(tapname, O_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0; i < 255; i++) {
|
for(i=0; i < 255; i++) {
|
||||||
sprintf(tapname, "/dev/tap%d", i);
|
snprintf(tapname, sizeof tapname, "/dev/tap%d", i);
|
||||||
/* Open device */
|
/* Open device */
|
||||||
if( (fd=open(tapname, O_RDWR)) > 0 ) {
|
if( (fd=open(tapname, O_RDWR)) > 0 ) {
|
||||||
sprintf(dev, "tap%d",i);
|
sprintf(dev, "tap%d",i);
|
||||||
|
@ -42,12 +42,12 @@ int tun_open(char *dev)
|
|||||||
int i, fd;
|
int i, fd;
|
||||||
|
|
||||||
if( *dev ) {
|
if( *dev ) {
|
||||||
sprintf(tunname, "/dev/%s", dev);
|
snprintf(tunname, sizeof tunname, "/dev/%s", dev);
|
||||||
return open(tunname, O_RDWR);
|
return open(tunname, O_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0; i < 255; i++){
|
for(i=0; i < 255; i++){
|
||||||
sprintf(tunname, "/dev/tun%d", i);
|
snprintf(tunname, sizeof tunname, "/dev/tun%d", i);
|
||||||
/* Open device */
|
/* Open device */
|
||||||
if( (fd=open(tunname, O_RDWR)) > 0 ){
|
if( (fd=open(tunname, O_RDWR)) > 0 ){
|
||||||
sprintf(dev, "tun%d", i);
|
sprintf(dev, "tun%d", i);
|
||||||
|
6
lib.c
6
lib.c
@ -98,7 +98,7 @@ void set_title(const char *fmt, ...)
|
|||||||
|
|
||||||
/* print the argument string */
|
/* print the argument string */
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsprintf(buf, fmt, ap);
|
vsnprintf(buf, sizeof buf, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if( strlen(buf) > title_size - 1)
|
if( strlen(buf) > title_size - 1)
|
||||||
@ -177,14 +177,14 @@ static char * subst_opt(char *str, struct vtun_sopt *opt)
|
|||||||
optr=opt->laddr;
|
optr=opt->laddr;
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
sprintf(buf,"%d",opt->lport);
|
snprintf(buf, sizeof buf, "%d",opt->lport);
|
||||||
optr=buf;
|
optr=buf;
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
optr=opt->raddr;
|
optr=opt->raddr;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
sprintf(buf,"%d",opt->rport);
|
snprintf(buf, sizeof buf, "%d",opt->rport);
|
||||||
optr=buf;
|
optr=buf;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
|
2
linkfd.c
2
linkfd.c
@ -411,7 +411,7 @@ int linkfd(struct vtun_host *host)
|
|||||||
sa.sa_handler=sig_usr1;
|
sa.sa_handler=sig_usr1;
|
||||||
sigaction(SIGUSR1,&sa,NULL);
|
sigaction(SIGUSR1,&sa,NULL);
|
||||||
|
|
||||||
sprintf(file,"%s/%.20s", VTUN_STAT_DIR, host->host);
|
snprintf(file, sizeof file, "%s/%.20s", VTUN_STAT_DIR, host->host);
|
||||||
if( (host->stat.file=fopen(file, "a")) ){
|
if( (host->stat.file=fopen(file, "a")) ){
|
||||||
setvbuf(host->stat.file, NULL, _IOLBF, 0);
|
setvbuf(host->stat.file, NULL, _IOLBF, 0);
|
||||||
} else
|
} else
|
||||||
|
8
lock.c
8
lock.c
@ -47,13 +47,13 @@ int create_lock(char * file)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
/* Create temp file */
|
/* Create temp file */
|
||||||
sprintf(tmp_file, "%s_%d_tmp\n", file, pid);
|
snprintf(tmp_file, sizeof tmp_file, "%s_%d_tmp\n", file, pid);
|
||||||
if( (fd = open(tmp_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0 ){
|
if( (fd = open(tmp_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0 ){
|
||||||
vtun_syslog(LOG_ERR, "Can't create temp lock file %s", file);
|
vtun_syslog(LOG_ERR, "Can't create temp lock file %s", file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = sprintf(str, "%d\n", pid);
|
pid = snprintf(str, sizeof str, "%d\n", pid);
|
||||||
if( write(fd, str, pid) == pid ){
|
if( write(fd, str, pid) == pid ){
|
||||||
/* Create lock file */
|
/* Create lock file */
|
||||||
if( link(tmp_file, file) < 0 ){
|
if( link(tmp_file, file) < 0 ){
|
||||||
@ -115,7 +115,7 @@ int lock_host(struct vtun_host * host)
|
|||||||
if( host->multi == VTUN_MULTI_ALLOW )
|
if( host->multi == VTUN_MULTI_ALLOW )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
sprintf(lock_file, "%s/%s", VTUN_LOCK_DIR, host->host);
|
snprintf(lock_file, sizeof lock_file, "%s/%s", VTUN_LOCK_DIR, host->host);
|
||||||
|
|
||||||
/* Check if lock already exists. */
|
/* Check if lock already exists. */
|
||||||
if( (pid = read_lock(lock_file)) > 0 ){
|
if( (pid = read_lock(lock_file)) > 0 ){
|
||||||
@ -156,7 +156,7 @@ void unlock_host(struct vtun_host *host)
|
|||||||
if( host->multi == VTUN_MULTI_ALLOW )
|
if( host->multi == VTUN_MULTI_ALLOW )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sprintf(lock_file, "%s/%s", VTUN_LOCK_DIR, host->host);
|
snprintf(lock_file, sizeof lock_file, "%s/%s", VTUN_LOCK_DIR, host->host);
|
||||||
|
|
||||||
if( unlink(lock_file) < 0 )
|
if( unlink(lock_file) < 0 )
|
||||||
vtun_syslog(LOG_ERR, "Unable to remove lock %s", lock_file);
|
vtun_syslog(LOG_ERR, "Unable to remove lock %s", lock_file);
|
||||||
|
Loading…
Reference in New Issue
Block a user