From: thib Date: Fri, 19 Jul 2002 19:32:39 +0000 (+0000) Subject: security change : more robust code about strn{cpy|cat} X-Git-Tag: ver1564~78 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7cf8a778d5fdb2c7e2f2eae6618f3c67cda441ec;p=fcron security change : more robust code about strn{cpy|cat} --- diff --git a/fcrondyn.c b/fcrondyn.c index 8badab8..cdf9c28 100644 --- a/fcrondyn.c +++ b/fcrondyn.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fcrondyn.c,v 1.3 2002-03-31 15:03:46 thib Exp $ */ + /* $Id: fcrondyn.c,v 1.4 2002-07-19 19:32:53 thib Exp $ */ /* fcrondyn : interact dynamically with running fcron process : * - list jobs, with their status, next time of execution, etc @@ -35,7 +35,7 @@ #include "allow.h" #include "read_string.h" -char rcs_info[] = "$Id: fcrondyn.c,v 1.3 2002-03-31 15:03:46 thib Exp $"; +char rcs_info[] = "$Id: fcrondyn.c,v 1.4 2002-07-19 19:32:53 thib Exp $"; void info(void); void usage(void); @@ -386,7 +386,8 @@ connect_fcron(void) addr.sun_family = AF_UNIX; if ( (len = strlen(fifofile)) > sizeof(addr.sun_path) ) die("Error : fifo file path too long (max is %d)", sizeof(addr.sun_path)); - strncpy(addr.sun_path, fifofile, sizeof(addr.sun_path)); + strncpy(addr.sun_path, fifofile, sizeof(addr.sun_path) - 1); + addr.sun_path[sizeof(addr.sun_path)-1] = '\0'; if ( connect(fd, (struct sockaddr *) &addr, sizeof(addr.sun_family) + len) < 0 ) die_e("Cannot connect() to fcron (check if fcron is running)"); diff --git a/fileconf.c b/fileconf.c index 5bb261a..0f55563 100644 --- a/fileconf.c +++ b/fileconf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fileconf.c,v 1.58 2002-02-25 18:42:00 thib Exp $ */ + /* $Id: fileconf.c,v 1.59 2002-07-19 19:36:42 thib Exp $ */ #include "fcrontab.h" @@ -1058,9 +1058,9 @@ check_username(char *ptr, CF *cf, CL *cl) /* check to see if next word is a username */ /* we don't allow quotes, to be able to distinguish a user name from - * a command line (where quotes are allowed */ + * a command line (where quotes are allowed) */ while ( isalnum( (int) ptr[indx]) ) indx++; - if (indx > USER_NAME_LEN) indx = USER_NAME_LEN; + if (indx >= USER_NAME_LEN) indx = USER_NAME_LEN - 1; strncpy(username, ptr, indx); username[indx] = '\0'; diff --git a/log.c b/log.c index d4d0097..8eaae89 100644 --- a/log.c +++ b/log.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: log.c,v 1.12 2002-02-25 18:38:38 thib Exp $ */ + /* $Id: log.c,v 1.13 2002-07-19 19:32:39 thib Exp $ */ /* This code is inspired by Anacron's sources of Itai Tzur */ @@ -69,7 +69,7 @@ make_msg(char *fmt, va_list args) * returns when the buffer overflows. Hmmm... */ len = vsnprintf(msg, MAX_MSG + 1, fmt, args); if (len >= MAX_MSG) - strcpy(msg + (MAX_MSG + 1) - sizeof(truncated), truncated); + strcpy(msg + (MAX_MSG - 1) - sizeof(truncated), truncated); return msg; } diff --git a/socket.c b/socket.c index 0c29765..92e69e9 100644 --- a/socket.c +++ b/socket.c @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: socket.c,v 1.2 2002-03-31 15:06:19 thib Exp $ */ + /* $Id: socket.c,v 1.3 2002-07-19 19:40:57 thib Exp $ */ /* This file contains all fcron's code (server) to handle communication with fcrondyn */ @@ -64,7 +64,8 @@ init_socket(void) error("Error : fifo file path too long (max is %d)", sizeof(addr.sun_path)); goto err; } - strncpy(addr.sun_path, fifofile, sizeof(addr.sun_path)); + strncpy(addr.sun_path, fifofile, sizeof(addr.sun_path) - 1); + addr.sun_path[sizeof(addr.sun_path) -1 ] = '\0'; unlink(fifofile); if (bind(listen_fd, (struct sockaddr *) &addr, sizeof(addr.sun_family)+len) != 0) { diff --git a/temp_file.c b/temp_file.c index 78666ba..5ce5ac4 100644 --- a/temp_file.c +++ b/temp_file.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: temp_file.c,v 1.1 2002-02-25 18:44:37 thib Exp $ */ + /* $Id: temp_file.c,v 1.2 2002-07-19 19:40:10 thib Exp $ */ #include "global.h" #include "temp_file.h" @@ -38,7 +38,8 @@ temp_file(char **name) int fd; #ifdef HAVE_MKSTEMP char name_local[PATH_LEN] = ""; - strcpy(name_local, tmp_path); + strncpy(name_local, tmp_path, sizeof(name_local) - 1); + name_local[sizeof(name_local)-1] = '\0'; strcat(name_local, "fcr-XXXXXX"); if ( (fd = mkstemp(name_local)) == -1 ) die_e("Can't find a unique temporary filename");