Subject: Re: bin/22276: cvs BROKEN in current-20030726-063809
To: David Laight <david@l8s.co.uk>
From: Simon Burge <simonb@wasabisystems.com>
List: netbsd-bugs
Date: 07/27/2003 00:39:46
On Sat, Jul 26, 2003 at 03:07:56PM +0100, David Laight wrote:
> > >Description:
> > 	After upgrading to current-20030726-063809 cvs hasn't been able to
> > 	do "cvs update ..." or "cvs co ..." from netbsd repositories.
> > 	Either cvs aborted the update due to it not being able to chdir to y
> > 	(the directory name) or it incurred a SIGSEGV.  When using the cvs
> > 	sources from 20030724 the problem goes away and thus the changes
> > 	from 20030725 come to mind as being the culprit.
> 
> I suspect the output of:
> 
> $ grep 'sizeof.*CVSADM' *
> 
> gives some hint as to what is awry.

Good catch!

The following mechanical change gets things working again.  I'll leave it
for Christos to integrate :-)

Simon.
--
Simon Burge                                   <simonb@wasabisystems.com>
NetBSD Development, Support and Service:   http://www.wasabisystems.com/


Index: client.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/client.c,v
retrieving revision 1.14
diff -d -p -u -r1.14 client.c
--- client.c	2003/07/25 20:37:31	1.14
+++ client.c	2003/07/26 14:35:59
@@ -2615,7 +2615,7 @@ do_deferred_progs ()
     }
     for (p = checkin_progs; p != NULL; )
     {
-	fname = xmalloc (strlen (p->dir) + sizeof CVSADM_CIPROG + 10);
+	fname = xmalloc (strlen (p->dir) + strlen (CVSADM_CIPROG) + 1 + 10);
 	sprintf (fname, "%s/%s", p->dir, CVSADM_CIPROG);
 	f = open_file (fname, "w");
 	if (fprintf (f, "%s\n", p->name) < 0)
@@ -2632,7 +2632,7 @@ do_deferred_progs ()
     checkin_progs = NULL;
     for (p = update_progs; p != NULL; )
     {
-	fname = xmalloc (strlen (p->dir) + sizeof CVSADM_UPROG + 10);
+	fname = xmalloc (strlen (p->dir) + strlen (CVSADM_UPROG) + 1 + 10);
 	sprintf (fname, "%s/%s", p->dir, CVSADM_UPROG);
 	f = open_file (fname, "w");
 	if (fprintf (f, "%s\n", p->name) < 0)
@@ -5373,7 +5373,7 @@ send_dirent_proc (callerdat, dir, reposi
      * This case will happen when checking out a module defined as
      * ``-a .''.
      */
-    cvsadm_name = xmalloc (strlen (dir) + sizeof (CVSADM) + 10);
+    cvsadm_name = xmalloc (strlen (dir) + strlen (CVSADM) + 1 + 10);
     sprintf (cvsadm_name, "%s/%s", dir, CVSADM);
     dir_exists = isdir (cvsadm_name);
     free (cvsadm_name);
Index: commit.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/commit.c,v
retrieving revision 1.6
diff -d -p -u -r1.6 commit.c
--- commit.c	2003/01/21 09:43:36	1.6
+++ commit.c	2003/07/26 14:36:01
@@ -1796,7 +1796,7 @@ finaladd (finfo, rev, tag, options)
     ret = Checkin ('A', finfo, rcs, rev, tag, options, saved_message);
     if (ret == 0)
     {
-	char *tmp = xmalloc (strlen (finfo->file) + sizeof (CVSADM)
+	char *tmp = xmalloc (strlen (finfo->file) + strlen (CVSADM) + 1
 			     + sizeof (CVSEXT_LOG) + 10);
 	(void) sprintf (tmp, "%s/%s%s", CVSADM, finfo->file, CVSEXT_LOG);
 	if (unlink_file (tmp) < 0
@@ -2005,7 +2005,7 @@ checkaddfile (file, repository, tag, opt
 	desc = NULL;
 	descalloc = 0;
 	desclen = 0;
-	fname = xmalloc (strlen (file) + sizeof (CVSADM)
+	fname = xmalloc (strlen (file) + strlen (CVSADM) + 1
 			 + sizeof (CVSEXT_LOG) + 10);
 	(void) sprintf (fname, "%s/%s%s", CVSADM, file, CVSEXT_LOG);
 	/* If the file does not exist, no big deal.  In particular, the
@@ -2069,7 +2069,7 @@ checkaddfile (file, repository, tag, opt
 	    FILE *fp;
 
 	    /* move the new file out of the way. */
-	    fname = xmalloc (strlen (file) + sizeof (CVSADM)
+	    fname = xmalloc (strlen (file) + strlen (CVSADM) + 1
 			     + sizeof (CVSPREFIX) + 10);
 	    (void) sprintf (fname, "%s/%s%s", CVSADM, CVSPREFIX, file);
 	    rename_file (file, fname);
Index: diff.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/diff.c,v
retrieving revision 1.1.1.3
diff -d -p -u -r1.1.1.3 diff.c
--- diff.c	2003/01/16 02:15:41	1.1.1.3
+++ diff.c	2003/07/26 14:36:02
@@ -651,7 +651,7 @@ diff_fileproc (callerdat, finfo)
     {
 	/* Backup the current version of the file to CVS/,,filename */
 	fname = xmalloc (strlen (finfo->file)
-			 + sizeof CVSADM
+			 + strlen (CVSADM) + 1
 			 + sizeof CVSPREFIX
 			 + 10);
 	sprintf(fname,"%s/%s%s",CVSADM, CVSPREFIX, finfo->file);
Index: edit.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/edit.c,v
retrieving revision 1.1.1.4
diff -d -p -u -r1.1.1.4 edit.c
--- edit.c	2003/01/16 02:15:41	1.1.1.4
+++ edit.c	2003/07/26 14:36:03
@@ -334,7 +334,7 @@ edit_fileproc (callerdat, finfo)
        trying to create the output file fails.  But copy_file isn't
        set up to facilitate that.  */
     mkdir_if_needed (CVSADM_BASE);
-    basefilename = xmalloc (10 + sizeof CVSADM_BASE + strlen (finfo->file));
+    basefilename = xmalloc (10 + strlen (CVSADM_BASE) + 1 + strlen (finfo->file));
     strcpy (basefilename, CVSADM_BASE);
     strcat (basefilename, "/");
     strcat (basefilename, finfo->file);
@@ -466,7 +466,7 @@ unedit_fileproc (callerdat, finfo)
     if (noexec)
 	return 0;
 
-    basefilename = xmalloc (10 + sizeof CVSADM_BASE + strlen (finfo->file));
+    basefilename = xmalloc (10 + strlen (CVSADM_BASE) + 1 + strlen (finfo->file));
     strcpy (basefilename, CVSADM_BASE);
     strcat (basefilename, "/");
     strcat (basefilename, finfo->file);
Index: entries.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/entries.c,v
retrieving revision 1.3
diff -d -p -u -r1.3 entries.c
--- entries.c	2003/07/25 20:37:31	1.3
+++ entries.c	2003/07/26 14:36:04
@@ -652,7 +652,7 @@ WriteTag (dir, tag, date, nonbranch, upd
 	return;
 
     tmp = xmalloc ((dir ? strlen (dir) : 0)
-		   + sizeof (CVSADM_TAG)
+		   + strlen (CVSADM_TAG) + 1
 		   + 10);
     if (dir == NULL)
 	(void) strcpy (tmp, CVSADM_TAG);
@@ -853,7 +853,7 @@ subdir_record (cmd, parent, dir)
 	else
 	{
 	    entfilename = xmalloc (strlen (parent)
-				   + sizeof CVSADM_ENTLOG
+				   + strlen (CVSADM_ENTLOG) + 1
 				   + 10);
 	    sprintf (entfilename, "%s/%s", parent, CVSADM_ENTLOG);
 	}
@@ -1023,11 +1023,11 @@ base_walk (code, finfo, rev)
        computation probably should be broken out into a separate function,
        as recurse.c does it too and places like Entries_Open should be
        doing it.  */
-    baserev_fullname = xmalloc (sizeof (CVSADM_BASEREV)
+    baserev_fullname = xmalloc (strlen (CVSADM_BASEREV) + 1
 				+ strlen (finfo->update_dir)
 				+ 2);
     baserev_fullname[0] = '\0';
-    baserevtmp_fullname = xmalloc (sizeof (CVSADM_BASEREVTMP)
+    baserevtmp_fullname = xmalloc (strlen (CVSADM_BASEREVTMP) + 1
 				   + strlen (finfo->update_dir)
 				   + 2);
     baserevtmp_fullname[0] = '\0';
Index: filesubr.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/filesubr.c,v
retrieving revision 1.2
diff -d -p -u -r1.2 filesubr.c
--- filesubr.c	2003/07/25 20:37:31	1.2
+++ filesubr.c	2003/07/26 14:36:05
@@ -478,6 +478,9 @@ deep_remove_dir (path)
     DIR		  *dirp;
     struct dirent *dp;
 
+#if 0 /* XXXsnark */
+printf("deep_remove_dir(%s)\n", path);
+#endif
     if (rmdir (path) != 0)
     {
 	if (errno == ENOTEMPTY
Index: find_names.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/find_names.c,v
retrieving revision 1.1.1.2
diff -d -p -u -r1.1.1.2 find_names.c
--- find_names.c	2002/11/28 04:54:28	1.1.1.2
+++ find_names.c	2003/07/26 14:36:05
@@ -394,7 +394,7 @@ find_dirs (dir, list, checkadm, entries)
 	    expand_string (&tmp,
 			   &tmp_size,
 			   (strlen (dir) + strlen (dp->d_name)
-			    + sizeof (CVSADM) + 10));
+			    + strlen (CVSADM) + 1 + 10));
 	    (void) sprintf (tmp, "%s/%s/%s", dir, dp->d_name, CVSADM);
 	    if (!isdir (tmp))
 		goto do_it_again;
Index: ignore.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/ignore.c,v
retrieving revision 1.2
diff -d -p -u -r1.2 ignore.c
--- ignore.c	2003/07/25 20:37:31	1.2
+++ ignore.c	2003/07/26 14:36:06
@@ -435,7 +435,7 @@ ignore_files (ilist, entries, update_dir
 		   this directory if there is a CVS subdirectory.
 		   This will normally be the case, but the user may
 		   have messed up the working directory somehow.  */
-		p = xmalloc (strlen (file) + sizeof CVSADM + 10);
+		p = xmalloc (strlen (file) + strlen (CVSADM) + 1 + 10);
 		sprintf (p, "%s/%s", file, CVSADM);
 		dir = isdir (p);
 		free (p);
@@ -469,7 +469,7 @@ ignore_files (ilist, entries, update_dir
 		{
 		    char *temp;
 
-		    temp = xmalloc (strlen (file) + sizeof (CVSADM) + 10);
+		    temp = xmalloc (strlen (file) + strlen (CVSADM) + 1 + 10);
 		    (void) sprintf (temp, "%s/%s", file, CVSADM);
 		    if (isdir (temp))
 		    {
Index: recurse.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/recurse.c,v
retrieving revision 1.5
diff -d -p -u -r1.5 recurse.c
--- recurse.c	2003/01/16 02:33:21	1.5
+++ recurse.c	2003/07/26 14:36:08
@@ -956,8 +956,8 @@ but CVS uses %s for its own purposes; sk
 	char *cvsadmdir;
 
 	cvsadmdir = xmalloc (strlen (dir)
-			     + sizeof (CVSADM_REP)
-			     + sizeof (CVSADM_ENT)
+			     + strlen (CVSADM_REP) + 1
+			     + strlen (CVSADM_ENT) + 1
 			     + 80);
 
 	strcpy (cvsadmdir, dir);
Index: remove.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/remove.c,v
retrieving revision 1.1.1.4
diff -d -p -u -r1.1.1.4 remove.c
--- remove.c	2003/01/16 02:15:46	1.1.1.4
+++ remove.c	2003/07/26 14:36:09
@@ -198,7 +198,7 @@ remove_fileproc (callerdat, finfo)
 	 * entries file.  */
 	Scratch_Entry (finfo->entries, finfo->file);
 	fname = xmalloc (strlen (finfo->file)
-			 + sizeof (CVSADM)
+			 + strlen (CVSADM) + 1
 			 + sizeof (CVSEXT_LOG)
 			 + 10);
 	(void) sprintf (fname, "%s/%s%s", CVSADM, finfo->file, CVSEXT_LOG);
Index: repos.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/repos.c,v
retrieving revision 1.1.1.3
diff -d -p -u -r1.1.1.3 repos.c
--- repos.c	2002/11/28 04:54:43	1.1.1.3
+++ repos.c	2003/07/26 14:36:09
@@ -38,7 +38,7 @@ Name_Repository (dir, update_dir)
 
     if (dir != NULL)
     {
-	tmp = xmalloc (strlen (dir) + sizeof (CVSADM_REP) + 10);
+	tmp = xmalloc (strlen (dir) + strlen (CVSADM_REP) + 1 + 10);
 	(void) sprintf (tmp, "%s/%s", dir, CVSADM_REP);
     }
     else
@@ -57,7 +57,7 @@ Name_Repository (dir, update_dir)
 
 	if (dir != NULL)
 	{
-	    cvsadm = xmalloc (strlen (dir) + sizeof (CVSADM) + 10);
+	    cvsadm = xmalloc (strlen (dir) + strlen (CVSADM) + 1 + 10);
 	    (void) sprintf (cvsadm, "%s/%s", dir, CVSADM);
 	}
 	else
Index: root.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/root.c,v
retrieving revision 1.1.1.4
diff -d -p -u -r1.1.1.4 root.c
--- root.c	2003/01/16 02:15:47	1.1.1.4
+++ root.c	2003/07/26 14:36:09
@@ -42,9 +42,9 @@ Name_Root (dir, update_dir)
 
     if (dir != NULL)
     {
-	cvsadm = xmalloc (strlen (dir) + sizeof (CVSADM) + 10);
+	cvsadm = xmalloc (strlen (dir) + strlen (CVSADM) + 1 + 10);
 	(void) sprintf (cvsadm, "%s/%s", dir, CVSADM);
-	tmp = xmalloc (strlen (dir) + sizeof (CVSADM_ROOT) + 10);
+	tmp = xmalloc (strlen (dir) + strlen (CVSADM_ROOT) + 1 + 10);
 	(void) sprintf (tmp, "%s/%s", dir, CVSADM_ROOT);
     }
     else
@@ -153,7 +153,7 @@ Create_Root (dir, rootdir)
     {
         if (dir != NULL)
 	{
-	    tmp = xmalloc (strlen (dir) + sizeof (CVSADM_ROOT) + 10);
+	    tmp = xmalloc (strlen (dir) + strlen (CVSADM_ROOT) + 1 + 10);
 	    (void) sprintf (tmp, "%s/%s", dir, CVSADM_ROOT);
 	}
         else
Index: update.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/cvs/src/update.c,v
retrieving revision 1.6
diff -d -p -u -r1.6 update.c
--- update.c	2003/01/16 02:33:23	1.6
+++ update.c	2003/07/26 14:36:12
@@ -1010,7 +1010,7 @@ update_dirent_proc (callerdat, dir, repo
 	{
 	    char *tmp;
 
-	    tmp = xmalloc (strlen (dir) + sizeof (CVSADM_ENTSTAT) + 10);
+	    tmp = xmalloc (strlen (dir) + strlen (CVSADM_ENTSTAT) + 1 + 10);
 	    (void) sprintf (tmp, "%s/%s", dir, CVSADM_ENTSTAT);
 	    if (unlink_file (tmp) < 0 && ! existence_error (errno))
 		error (1, errno, "cannot remove file %s", tmp);
@@ -1306,7 +1306,7 @@ checkout_file (finfo, vers_ts, adding, m
 	)
     {
 	backup = xmalloc (strlen (finfo->file)
-			  + sizeof (CVSADM)
+			  + strlen (CVSADM) + 1
 			  + sizeof (CVSPREFIX)
 			  + 10);
 	(void) sprintf (backup, "%s/%s%s", CVSADM, CVSPREFIX, finfo->file);
@@ -1671,7 +1671,7 @@ patch_file (finfo, vers_ts, docheckout, 
     }
 
     backup = xmalloc (strlen (finfo->file)
-		      + sizeof (CVSADM)
+		      + strlen (CVSADM) + 1
 		      + sizeof (CVSPREFIX)
 		      + 10);
     (void) sprintf (backup, "%s/%s%s", CVSADM, CVSPREFIX, finfo->file);
@@ -1685,12 +1685,12 @@ patch_file (finfo, vers_ts, docheckout, 
     }
 
     file1 = xmalloc (strlen (finfo->file)
-		     + sizeof (CVSADM)
+		     + strlen (CVSADM) + 1
 		     + sizeof (CVSPREFIX)
 		     + 10);
     (void) sprintf (file1, "%s/%s%s-1", CVSADM, CVSPREFIX, finfo->file);
     file2 = xmalloc (strlen (finfo->file)
-		     + sizeof (CVSADM)
+		     + strlen (CVSADM) + 1
 		     + sizeof (CVSPREFIX)
 		     + 10);
     (void) sprintf (file2, "%s/%s%s-2", CVSADM, CVSPREFIX, finfo->file);