CVS update [cvs1-11-x-branch]: /ccvs/src/

[email protected] 20 Apr 2005 20:40:51 -0000
Newsgroups gmane.comp.version-control.cvs.cvs
Message-ID <[email protected]>
Tag: cvs1-11-x-branch
User: dprice  
Date: 05/04/20 13:40:51

Modified:
 /ccvs/src/
  ChangeLog, rcs.c, sanity.sh

Log:
 * rcs.c (expand_keywords): Avoid buffer overflow.
 (Original patch from Stewart Brodie <[email protected]>.)
 
 * sanity.sh (rcs5): New tests for the above.

File Changes:

Directory: /ccvs/src/
=====================

File [changed]: ChangeLog
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/ChangeLog?r1=1.2336.2.360&r2=1.2336.2.361
Delta lines:  +7 -0
-------------------
--- ChangeLog	18 Apr 2005 17:36:45 -0000	1.2336.2.360
+++ ChangeLog	20 Apr 2005 20:40:42 -0000	1.2336.2.361
@@ -1,3 +1,10 @@
+2005-03-20  Derek Price  <[email protected]>
+
+	* rcs.c (expand_keywords): Avoid buffer overflow.
+	(Original patch from Stewart Brodie <[email protected]>.)
+
+	* sanity.sh (rcs5): New tests for the above.
+
 2005-03-17  Derek Price  <[email protected]>
 
 	* login.c (password_entry_parseline): Avoid using uninitialized

File [changed]: rcs.c
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/rcs.c?r1=1.262.4.36&r2=1.262.4.37
Delta lines:  +19 -0
--------------------
--- rcs.c	18 Apr 2005 17:36:45 -0000	1.262.4.36
+++ rcs.c	20 Apr 2005 20:40:42 -0000	1.262.4.37
@@ -3947,6 +3947,13 @@
 		if (*snl == '\n')
 		    ++cnl;
 
+	    /* If the log message did not end in a newline, increment
+	     * the newline count so we have space for the extra leader.
+	     * Failure to do so results in a buffer overrun.
+	     */
+	    if (loglen && snl[-1] != '\n')
+		++cnl;
+
 	    date = printable_date (ver->date);
 	    sub = xrealloc (sub,
 			    (sublen
@@ -3955,6 +3962,10 @@
 			     + strlen (date)
 			     + strlen (ver->author)
 			     + loglen
+			       /* Use CNL + 2 below:  One leader for each log
+				* line, plus the Revision/Author/Date line,
+				* plus a trailing blank line.
+				*/
 			     + (cnl + 2) * leader_len
 			     + 20));
 	    if (expand != KFLAG_V)
@@ -3994,6 +4005,14 @@
 			++slnl;
 		    memcpy (sub + sublen, sl, slnl - sl);
 		    sublen += slnl - sl;
+		    if (slnl == logend && slnl[-1] != '\n')
+		    {
+			/* There was no EOL at the end of the log message.  Add
+			 * one.
+			 */
+			sub[sublen] = '\n';
+			++sublen;
+		    }
 		    sl = slnl;
 		}
 	    }

File [changed]: sanity.sh
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/sanity.sh?r1=1.752.2.164&r2=1.752.2.165
Delta lines:  +52 -1
--------------------
--- sanity.sh	22 Feb 2005 16:08:11 -0000	1.752.2.164
+++ sanity.sh	20 Apr 2005 20:40:43 -0000	1.752.2.165
@@ -1108,7 +1108,8 @@
 	tests="${tests} serverpatch log log2 logopt ann ann-id"
 	# Repository Storage (RCS file format, CVS lock files, creating
 	# a repository without "cvs init", &c).
-	tests="${tests} crerepos rcs rcs2 rcs3 lockfiles backuprecover"
+	tests="${tests} crerepos rcs rcs2 rcs3 rcs5"
+	tests="$tests lockfiles backuprecover"
 	tests="${tests} sshstdio"
 	# More history browsing, &c.
 	tests="${tests} history"
@@ -20417,6 +20418,56 @@
           rm -rf ${CVSROOT_DIRNAME}/rcs4-dir
 	  ;;
 
+
+
+	rcs5)
+	  mkdir $CVSROOT_DIRNAME/rcs5
+	  cat <<\EOF >$CVSROOT_DIRNAME/rcs5/file1,v
+head 1.1;
+access;
+symbols;
+locks;
+expand kv;
+
+1.1 date 2007.03.20.04.03.02; author jeremiah; state Ext;  branches; next;
+
+desc
+@@
+
+1.1
+log
+@he always had very fine wine@
+text
+@line1
+/*
+EOF
+echo ' * Revision history: $''Log$' >>$CVSROOT_DIRNAME/rcs5/file1,v
+	  cat <<\EOF >>$CVSROOT_DIRNAME/rcs5/file1,v
+ */
+line5
+@
+EOF
+
+          mkdir rcs5
+          cd rcs5
+	  dotest rcs5-1 "$testcvs -Q co rcs5"
+	  dotest rcs5-2 "cat rcs5/file1" \
+"line1
+/\\*
+ \\* Revision history: "'\$'"Log: file1,v "'\$'"
+ \\* Revision history: Revision 1\.1  2007/03/20 04:03:02  jeremiah
+ \\* Revision history: he always had very fine wine
+ \\* Revision history:
+ \\*/
+line5"
+
+	  cd ..
+          rm -r rcs5
+          rm -rf $CVSROOT_DIRNAME/rcs5
+	  ;;
+
+
+
 	lockfiles)
 	  # Tests of CVS lock files.
 	  # TODO-maybe: Add a test where we arrange for a loginfo