Bug 28189

Summary: [PATCH] fix for detecting empty CVS commit log message
Product: Base System Reporter: Mark Valentine <mark>
Component: gnuAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Mark Valentine 2001-06-16 04:20:04 UTC
	CVS attempts to detect an empty or unchanged log message from a commit
	log editing session, but misses a case where someone tries to abort a
	commit by deleting all but the CVS: lines before quitting the editor
	(it does detect the case where the leading blank line inserted by cvs
	is left in; note that the latest CVS sources don't appear to insert
	this blank line).

	The patch below detects this case, which I know has caught many people
	out over the years, but I'd always put down to the effects of a very
	simple detection algorithm rather than a bug (until I finally looked
	at the code just now, trying to be more clever than I'd had it down
	for).

	With this fix, all of the following ways of aborting a commit work:

	 a) quit the edit without saving the temp file
	 b) delete all lines in the file before saving and quitting
	 c) delete all non-CVS: prefix lines before saving and quitting
	 d) delete all non-CVS: prefix lines but for a single blank line
	    before saving and quitting

	That is, the file must be either untouched after the edit (mtime),
	or must be empty or contain a single newline apart from any CVS:
	prefixed lines.  You can do whatever you want with the CVS: lines,
	it's what's left once these are stripped which counts.

	Specifically, the patch fixes case (c).

Fix: A version of this fix against the current CVS sources has been submitted
to bug-cvs@gnu.org.
How-To-Repeat: 	Delete all lines _not_ beginning with ``CVS:'' before quitting the
	editor when creating a cvs commit log message; watch your commit go
	through with an empty log message.
Comment 1 Mark Valentine 2001-06-20 22:22:26 UTC
Here's a new patch incorporating the official fix which was checked into the
cvs cvs(!) tree; it also fixes a related memory leak.

ChangeLog entry as follows:

2001-06-20  Derek Price  <dprice@collab.net>

	* logmsg.c (do_editor): Abort in the case that the file has only
	comment lines.
	(Original patch from Mark Valentine <mark@thuvia.demon.co.uk>.)

	* logmsg.c (do_editor): Fix rare memory leak.

Index: contrib/cvs/src/logmsg.c
===================================================================
RCS file: /usr/cvs/src/contrib/cvs/src/logmsg.c,v
retrieving revision 1.7
diff -u -r1.7 logmsg.c
--- contrib/cvs/src/logmsg.c	2000/10/02 06:43:56	1.7
+++ contrib/cvs/src/logmsg.c	2001/06/20 17:08:31
@@ -307,7 +307,7 @@
 	/* On NT, we might read less than st_size bytes, but we won't
 	   read more.  So this works.  */
 	*messagep = (char *) xmalloc (post_stbuf.st_size + 1);
- 	*messagep[0] = '\0';
+ 	(*messagep)[0] = '\0';
     }
 
     line = NULL;
@@ -340,8 +340,14 @@
 
     if (pre_stbuf.st_mtime == post_stbuf.st_mtime ||
 	*messagep == NULL ||
+	(*messagep)[0] == '\0' ||
 	strcmp (*messagep, "\n") == 0)
     {
+	if (*messagep)
+	{
+	    free (*messagep);
+	    *messagep = NULL;
+	}
 	for (;;)
 	{
 	    (void) printf ("\nLog message unchanged or not specified\n");

-- 
Mark Valentine, Thuvia Labs <mark@thuvia.co.uk>       <http://www.thuvia.co.uk>
"Tigers will do ANYTHING for a tuna fish sandwich."       Mark Valentine uses
"We're kind of stupid that way."   *munch* *munch*        and endorses FreeBSD
  -- <http://www.calvinandhobbes.com>                  <http://www.freebsd.org>
Comment 2 Jeroen Ruigrok van der Werven freebsd_committer freebsd_triage 2001-07-31 17:24:28 UTC
State Changed
From-To: open->analyzed

I am currently raising the issue to import cvs 1.11.1p1, don't know 
yet if this release contains this fix.  Will look tonight.
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2008-06-21 03:14:42 UTC
State Changed
From-To: analyzed->closed

Apparently fixed in all supported versions of FreeBSD.