Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Aug 2008 22:31:50 GMT
From:      Stacey Son <sson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 147187 for review
Message-ID:  <200808112231.m7BMVopx092489@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147187

Change 147187 by sson@sson_amd64 on 2008/08/11 22:31:01

	More strcpy() -> strncpy() and strcat() -> strncat() changes.	

Affected files ...

.. //depot/projects/trustedbsd/openbsm/NEWS#5 edit
.. //depot/projects/trustedbsd/openbsm/bin/auditd/auditd.c#33 edit
.. //depot/projects/trustedbsd/openbsm/bin/auditreduce/auditreduce.c#25 edit

Differences ...

==== //depot/projects/trustedbsd/openbsm/NEWS#5 (text+ko) ====

@@ -12,7 +12,7 @@
   versions of the system includes in a kernel source tree, and will use the
   OpenBSM build infrastructure with an unmodified OpenBSM distribution,
   allowing the customized system includes to be used with the OpenBSM build.
-  Submitted by stacey Son.
+  Submitted by Stacey Son.
 
 OpenBSM 1.1 alpha 1
 
@@ -337,4 +337,4 @@
   to support reloading of kernel event table.
 - Allow comments in /etc/security configuration files.
 
-$P4: //depot/projects/trustedbsd/openbsm/NEWS#4 $
+$P4: //depot/projects/trustedbsd/openbsm/NEWS#5 $

==== //depot/projects/trustedbsd/openbsm/bin/auditd/auditd.c#33 (text+ko) ====

@@ -26,7 +26,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/auditd.c#32 $
+ * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/auditd.c#33 $
  */
 
 #include <sys/types.h>
@@ -152,16 +152,20 @@
 	char *fn;
 	char *curdir;
 	const char *sep = "/";
+	size_t len;
 
 	curdir = dirent->dirname;
 	syslog(LOG_DEBUG, "dir = %s", dirent->dirname);
 
-	fn = malloc(strlen(curdir) + strlen(sep) + (2 * POSTFIX_LEN) + 1);
+	len = strlen(curdir) + strlen(sep) + (2 * POSTFIX_LEN) + 1;
+	fn = malloc(len);
 	if (fn == NULL)
 		return (NULL);
-	strcpy(fn, curdir);
-	strcat(fn, sep);
-	strcat(fn, name);
+	strncpy(fn, curdir, len);
+	len -= strlen(curdir);
+	strncat(fn, sep, len);
+	len -= strlen(sep);
+	strncat(fn, name, len);
 	return (fn);
 }
 
@@ -173,17 +177,19 @@
 {
 	char *ptr;
 	char *oldname;
+	size_t len;
 
 	if (lastfile != NULL) {
-		oldname = (char *)malloc(strlen(lastfile) + 1);
+		len = strlen(lastfile) + 1;
+		oldname = (char *)malloc(len);
 		if (oldname == NULL)
 			return (-1);
-		strcpy(oldname, lastfile);
+		strncpy(oldname, lastfile, len);
 
 		/* Rename the last file -- append timestamp. */
 		if ((ptr = strstr(lastfile, NOT_TERMINATED)) != NULL) {
 			*ptr = '.';
-			strcpy(ptr+1, TS);
+			strncpy(ptr+1, TS, POSTFIX_LEN);
 			if (rename(oldname, lastfile) != 0)
 				syslog(LOG_ERR,
 				    "Could not rename %s to %s: %m", oldname,
@@ -249,8 +255,8 @@
 	if (getTSstr(TS, POSTFIX_LEN) != 0)
 		return (-1);
 
-	strcpy(timestr, TS);
-	strcat(timestr, NOT_TERMINATED);
+	strncpy(timestr, TS, POSTFIX_LEN);
+	strncat(timestr, NOT_TERMINATED, POSTFIX_LEN);
 
 #ifdef AUDIT_REVIEW_GROUP
 	/*
@@ -355,7 +361,7 @@
 			free(dirent);
 			return (-1);
 		}
-		strcpy(dirent->dirname, cur_dir);
+		strncpy(dirent->dirname, cur_dir, MAXNAMLEN);
 		TAILQ_INSERT_TAIL(&dir_q, dirent, dirs);
 	}
 

==== //depot/projects/trustedbsd/openbsm/bin/auditreduce/auditreduce.c#25 (text+ko) ====

@@ -26,7 +26,7 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditreduce/auditreduce.c#24 $
+ * $P4: //depot/projects/trustedbsd/openbsm/bin/auditreduce/auditreduce.c#25 $
  */
 
 /* 
@@ -111,7 +111,7 @@
 	for (nstrs = 0, i = 0; i < len; i++) {
 		if (copy[i] == ',' && i > 0) {
 			if (copy[i - 1] == '\\')
-				strcpy(&copy[i - 1], &copy[i]);
+				strncpy(&copy[i - 1], &copy[i], len);
 			else {
 				nstrs++;
 				copy[i] = '\0';



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808112231.m7BMVopx092489>