]> granicus.if.org Git - fcron/commitdiff
security change : more robust code about strn{cpy|cat}
authorthib <thib>
Fri, 19 Jul 2002 19:32:39 +0000 (19:32 +0000)
committerthib <thib>
Fri, 19 Jul 2002 19:32:39 +0000 (19:32 +0000)
fcrondyn.c
fileconf.c
log.c
socket.c
temp_file.c

index 8badab8f14c52b5e2a7630f66a587bbef8856122..cdf9c28b89b6515dfe7164faa7e0d6e138621c34 100644 (file)
@@ -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)");
index 5bb261a33258af33a1d739f56bf1e6960c8a8740..0f555634705b0973a72b63b517e34c55c6877417 100644 (file)
@@ -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 d4d00978f2ffcc8db7fd95614d8f18d8c0327c5e..8eaae895854b9ad311b3ad18245373536c16b4d6 100644 (file)
--- 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 <itzur@actcom.co.il> */
@@ -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;
 }
index 0c297652f9797d923670199f24fa16e7e19600f1..92e69e95236895dc43e859c8bee26d4f4dbbd7eb 100644 (file)
--- 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) {
index 78666ba9f96f197c256c2c641e7a649e0c37df2e..5ce5ac4c15f83926ecf91065861d591ae9d61ff6 100644 (file)
@@ -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");