changeset 37:d0f4b0c3f807

A couple of commits towards 2.2.3.
author ng0@n0.is
date Wed, 15 May 2019 16:22:42 +0000
parents 7be480bacd59
children e612861479df
files CHANGELOG GNUmakefile Makefile TODO cache.c cap.c cbtcommon/hash.c cvsps.c cvsps_types.h util.c
diffstat 10 files changed, 181 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Wed May 15 15:57:59 2019 +0000
+++ b/CHANGELOG	Wed May 15 16:22:42 2019 +0000
@@ -1,3 +1,11 @@
+2.2.3
+- Moved documentation to mdoc format.
+- changed (some) strcpy usage to strlcpy.
+- Added -V switch to display version.
+- Cleaned up -h / undefined output
+- clang-format'ed the sources.
+- Semantic Versioning
+
 2.2b2
 - Added patches from various sources of 2.2b1 cvsps forks:
   - Add missing .TP in cvsps.1 <Emanuele Giaquinta>
--- a/GNUmakefile	Wed May 15 15:57:59 2019 +0000
+++ b/GNUmakefile	Wed May 15 16:22:42 2019 +0000
@@ -1,8 +1,9 @@
 MAJOR=2
-MINOR=2b2
+MINOR=2
+PATCH=3
 CC?=clang
 CFLAGS?=-g -O2 -Wall
-CPPFLAGS+=-I. -DVERSION=\"$(MAJOR).$(MINOR)\"
+CPPFLAGS+=-I. -DVERSION=\"$(MAJOR).$(MINOR).$(PATCH)\"
 LDLIBS+=-lz
 PREFIX?=/usr/local
 MANPREFIX?=${PREFIX}/share/man
@@ -13,6 +14,7 @@
 	cbtcommon/text_util.o\
 	cbtcommon/sio.o\
 	cbtcommon/tcpsocket.o\
+	compats.o\
 	cvsps.o\
 	cache.o\
 	util.o\
--- a/Makefile	Wed May 15 15:57:59 2019 +0000
+++ b/Makefile	Wed May 15 16:22:42 2019 +0000
@@ -1,5 +1,7 @@
+.include "Makefile.configure"
+
 PROG=		cvsps
-SRCS+=		cvsps.c \
+SRCS+=		compats.c cvsps.c \
 		cache.c util.c stats.c cap.c \
 		cvs_direct.c list_sort.c
 .PATH:		${.CURDIR}/cbtcommon
@@ -8,9 +10,10 @@
 		tcpsocket.c
 
 MAJOR=		2
-MINOR=		2b2
+MINOR=		2
+PATCH=		3
 
-DFLAGS=		-DVERSION=\"$(MAJOR).$(MINOR)\"
+DFLAGS=		-DVERSION=\"$(MAJOR).$(MINOR).$(PATCH)\"
 
 CPPFLAGS+=	-I${.CURDIR} -I.
 CPPFLAGS+=	${DFLAGS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TODO	Wed May 15 16:22:42 2019 +0000
@@ -0,0 +1,16 @@
+Once this is done the project will be "parked".
+Only if absolutely necessary commits happen after
+this list is moved to "DONE". Patches are still
+taken.
+
+TODO
+----
+* fix strict prototypes
+* more errx()
+* stcpy -> strlcpy
+* more memory safety
+* discarded qualifier warnings
+* update man page
+
+DONE
+----
--- a/cache.c	Wed May 15 15:57:59 2019 +0000
+++ b/cache.c	Wed May 15 16:22:42 2019 +0000
@@ -1,5 +1,6 @@
 /*
  * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
+ * Copyright 2019 ng0 <ng0@n0.is>
  * See COPYING file for license information
  */
 
@@ -11,6 +12,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <time.h>
+#include <err.h>
 
 #include <cbtcommon/hash.h>
 #include <cbtcommon/debug.h>
@@ -51,8 +53,11 @@
                 return NULL;
 
         /* Generate the full path */
-        strcpy (root, root_path);
-        strcpy (repository, repository_path);
+        if (strlcpy (root, root_path, sizeof (root)) >= sizeof (root))
+                errx (1, "input is too long");
+        if (strlcpy (repository, repository_path, sizeof (repository)) >=
+            sizeof (repository))
+                errx (1, "input is too long");
 
         strrep (root, '/', '#');
         strrep (repository, '/', '#');
@@ -69,15 +74,15 @@
                           "****WARNING**** Obsolete CVS/cvsps.cache file found.\n");
                         fprintf (
                           stderr,
-                          "                New file will be re-written in ~/%s/\n",
+                          "****WARNING**** New file will be re-written in ~/%s/\n",
                           CVSPS_PREFIX);
                         fprintf (stderr,
-                                 "                Old file will be ignored.\n");
+                                 "****WARNING**** Old file will be ignored.\n");
                         fprintf (
                           stderr,
-                          "                Please manually remove the old file.\n");
+                          "****WARNING**** Please manually remove the old file.\n");
                         fprintf (stderr,
-                                 "                Continuing in 5 seconds.\n");
+                                 "****WARNING**** Continuing in 5 seconds.\n");
                         sleep (5);
                         fclose (fp);
                         fp = NULL;
@@ -167,8 +172,8 @@
                                 len -= 6;
                                 f = create_cvsfile ();
                                 f->filename = xstrdup (buff + 6);
-                                f->filename[len - 1] =
-                                  0; /* Remove the \n at the end of line */
+                                /* Remove the \n at the end of line */
+                                f->filename[len - 1] = 0;
                                 debug (DEBUG_STATUS,
                                        "read cache filename '%s'",
                                        f->filename);
@@ -311,7 +316,9 @@
                 case CACHE_NEED_PS_BRANCH_ADD:
                         if (strncmp (buff, "branch_add:", 11) == 0)
                         {
-                                /* remove prefix "branch_add: " and LF from len
+                                /*
+                                 * remove prefix "branch_add: " and
+                                 * LF from len
                                  */
                                 len -= 12;
                                 branch_add = atoi (buff + 12);
@@ -410,7 +417,8 @@
         const char *s;
         char *p = buff;
 
-        strcpy (buff, p_buff);
+        if (strlcpy (buff, p_buff, sizeof (buff)) >= sizeof (buff))
+                errx (1, "input is too long");
 
         while ((s = strsep (&p, ";")))
         {
@@ -430,13 +438,17 @@
                 switch (state)
                 {
                 case CR_FILENAME:
-                        strcpy (filename, c);
+                        if (strlcpy (filename, c, sizeof (filename)) >=
+                            sizeof (filename))
+                                errx (1, "input is too long");
                         break;
                 case CR_PRE_REV:
-                        strcpy (pre, c);
+                        if (strlcpy (pre, c, sizeof (pre)) >= sizeof (pre))
+                                errx (1, "input is too long");
                         break;
                 case CR_POST_REV:
-                        strcpy (post, c);
+                        if (strlcpy (post, c, sizeof (post)) >= sizeof (post))
+                                errx (1, "input is too long");
                         break;
                 case CR_DEAD:
                         dead = atoi (c);
--- a/cap.c	Wed May 15 15:57:59 2019 +0000
+++ b/cap.c	Wed May 15 16:22:42 2019 +0000
@@ -1,11 +1,13 @@
 /*
  * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
+ * Copyright 2019 ng0 <ng0@n0.is>
  * See COPYING file for license information
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <err.h>
 
 #include <cbtcommon/debug.h>
 #include <cbtcommon/text_util.h>
@@ -59,8 +61,14 @@
 {
         FILE *cvsfp;
 
-        strcpy (client_version, "(UNKNOWN CLIENT)");
-        strcpy (server_version, "(UNKNOWN SERVER)");
+        if (strlcpy (client_version,
+                     "(UNKNOWN CLIENT)",
+                     sizeof (client_version)) >= sizeof (client_version))
+                errx (1, "input is too long");
+        if (strlcpy (server_version,
+                     "(UNKNOWN SERVER)",
+                     sizeof (server_version)) >= sizeof (server_version))
+                errx (1, "input is too long");
 
         if (! (cvsfp = popen ("cvs version 2>/dev/null", "r")))
         {
--- a/cbtcommon/hash.c	Wed May 15 15:57:59 2019 +0000
+++ b/cbtcommon/hash.c	Wed May 15 16:22:42 2019 +0000
@@ -1,11 +1,13 @@
 /*
  * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
+ * Copyright 2019 ng0 <ng0@n0.is>
  * See COPYING file for license information
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <err.h>
 
 #include "debug.h"
 #include "hash.h"
@@ -248,7 +250,11 @@
                         if (copy)
                         {
                                 entry->he_key = (char *) (entry + 1);
-                                strcpy (entry->he_key, key);
+                                if (strlcpy (entry->he_key,
+                                             key,
+                                             sizeof (entry->he_key)) >=
+                                    sizeof (entry->he_key))
+                                        errx (1, "input is too long");
                         }
                         else
                         {
--- a/cvsps.c	Wed May 15 15:57:59 2019 +0000
+++ b/cvsps.c	Wed May 15 16:22:42 2019 +0000
@@ -32,6 +32,8 @@
 #include "cvs_direct.h"
 #include "list_sort.h"
 
+#include <err.h>
+
 RCSID ("$Id: cvsps.c,v 4.108 2005/06/05 22:52:43 david Exp $");
 
 #define CVS_LOG_BOUNDARY "----------------------------\n"
@@ -202,17 +204,12 @@
         if (diff_opts && ! cvs_direct && do_diff)
         {
                 debug (DEBUG_APPMSG1,
-                       "\nWARNING: diff options are not supported by 'cvs rdiff'");
-                debug (
-                  DEBUG_APPMSG1,
-                  "         which is usually used to create diffs.  'cvs diff'");
-                debug (DEBUG_APPMSG1,
-                       "         will be used instead, but the resulting patches ");
-                debug (DEBUG_APPMSG1,
-                       "         will need to be applied using the '-p0' option");
-                debug (DEBUG_APPMSG1,
-                       "         to patch(1) (in the working directory), ");
-                debug (DEBUG_APPMSG1, "         instead of '-p1'\n");
+                       "\nWARNING: diff options are not supported by 'cvs rdiff' "
+                       "which is usually used to create diffs.  'cvs diff' "
+                       "will be used instead, but the resulting patches "
+                       "will need to be applied using the '-p0' option "
+                       "to patch(1) (in the working directory), "
+                       "instead of '-p1'\n");
         }
 
         file_hash = create_hash_table (1023);
@@ -369,7 +366,9 @@
 
         cache_date = time (NULL);
 
-        /* FIXME: this is ugly, need to virtualize the accesses away from here
+        /*
+         * FIXME: this is ugly, need to virtualize
+         * the accesses away from here.
          */
         if (test_log_file)
                 cvsfp = fopen (test_log_file, "r");
@@ -381,10 +380,10 @@
 
         if (! cvsfp)
         {
-                debug (DEBUG_SYSERROR,
-                       "can't open cvs pipe using command %s",
-                       cmd);
-                exit (1);
+                /* SYSERROR */
+                errx (EXIT_FAILURE,
+                      "can't open cvs pipe using command %s",
+                      cmd);
         }
 
         for (;;)
@@ -432,7 +431,12 @@
                                 char new_rev[REV_STR_MAX];
                                 CvsFileRevision *rev;
 
-                                strcpy (new_rev, buff + 9);
+                                if (strlcpy (new_rev,
+                                             buff + 9,
+                                             sizeof (new_rev)) >=
+                                    sizeof (new_rev))
+                                        errx (EXIT_FAILURE,
+                                              "input is too long");
                                 chop (new_rev);
 
                                 /*
@@ -486,7 +490,12 @@
                                 strncpy (datebuff, buff + 6, sizeof (datebuff));
                                 datebuff[sizeof (datebuff) - 1] = 0;
 
-                                strcpy (authbuff, "unknown");
+                                if (strlcpy (authbuff,
+                                             "unknown",
+                                             sizeof (authbuff)) >=
+                                    sizeof (authbuff))
+                                        errx (EXIT_FAILURE,
+                                              "input is too long");
                                 p = strstr (buff, "author: ");
                                 if (p)
                                 {
@@ -501,8 +510,10 @@
                                         }
                                 }
 
-                                /* read the 'state' tag to see if this is a dead
-                                 * revision */
+                                /*
+                                 * read the 'state' tag to see if
+                                 * this is a dead revision
+                                 */
                                 p = strstr (buff, "state: ");
                                 if (p)
                                 {
@@ -562,7 +573,9 @@
                         }
                         else
                         {
-                                /* other "blahblah: information;" messages can
+                                /*
+                                 * other "blahblah: information;"
+                                 * messages can
                                  * follow the stuff we pay attention to
                                  */
                                 if (have_log || ! is_revision_metadata (buff))
@@ -617,19 +630,17 @@
 
         if (state == NEED_SYMS)
         {
-                debug (DEBUG_APPERROR,
-                       "Error: 'symbolic names' not found in log output.");
-                debug (DEBUG_APPERROR,
-                       "       Perhaps you should try running with --norc");
-                exit (1);
+                errx (EXIT_FAILURE,
+                      "Error: 'symbolic names' not found in log output. "
+                      "Perhaps you should try running with --norc.");
         }
 
         if (state != NEED_FILE)
         {
-                debug (DEBUG_APPERROR,
-                       "Error: Log file parsing error. (%d)  Use -v to debug",
-                       state);
-                exit (1);
+                errx (EXIT_FAILURE,
+                      "Error: Log file parsing error. "
+                      "(%d) Use -v to debug.",
+                      state);
         }
 
         if (test_log_file)
@@ -644,9 +655,9 @@
         {
                 if (pclose (cvsfp) < 0)
                 {
-                        debug (DEBUG_APPERROR,
-                               "cvs rlog command exited with error. aborting");
-                        exit (1);
+                        errx (EXIT_FAILURE,
+                              "cvs rlog command exited with error. "
+                              "aborting");
                 }
         }
 }
@@ -1059,19 +1070,18 @@
 
                         if (! e)
                         {
-                                debug (DEBUG_APPERROR,
-                                       "cannot determine CVSROOT");
-                                exit (1);
+                                errx (EXIT_FAILURE, "cannot determine CVSROOT");
                         }
 
-                        strcpy (root_path, e);
+                        if (strlcpy (root_path, e, sizeof (root_path)) >=
+                            sizeof (root_path))
+                                errx (EXIT_FAILURE, "input is too long");
                 }
                 else
                 {
                         if (! fgets (root_path, PATH_MAX, fp))
                         {
-                                debug (DEBUG_APPERROR, "Error reading CVSROOT");
-                                exit (1);
+                                errx (EXIT_FAILURE, "Error reading CVSROOT");
                         }
 
                         fclose (fp);
@@ -1084,7 +1094,8 @@
                 }
         }
 
-        /* Determine the repository path, precedence:
+        /* 
+         * Determine the repository path, precedence:
          * 1) command line
          * 2) working directory
          */
@@ -1093,14 +1104,12 @@
         {
                 if (! (fp = fopen ("CVS/Repository", "r")))
                 {
-                        debug (DEBUG_SYSERROR, "Can't open CVS/Repository");
-                        exit (1);
+                        errx (EXIT_FAILURE, "Cannot open CVS/Repository");
                 }
 
                 if (! fgets (repository_path, PATH_MAX, fp))
                 {
-                        debug (DEBUG_APPERROR, "Error reading repository path");
-                        exit (1);
+                        errx (EXIT_FAILURE, "Error reading repository path");
                 }
 
                 chop (repository_path);
@@ -1115,7 +1124,8 @@
         else
                 p++;
 
-        /* some CVS have the CVSROOT string as part of the repository
+        /* 
+         * some CVS have the CVSROOT string as part of the repository
          * string (initial substring).  remove it.
          */
         len = strlen (p);
@@ -1126,7 +1136,8 @@
                 memmove (repository_path, repository_path + len + 1, rlen + 1);
         }
 
-        /* the 'strip_path' will be used whenever the CVS server gives us a
+        /* 
+         * the 'strip_path' will be used whenever the CVS server gives us a
          * path to an 'rcs file'.  the strip_path portion of these paths is
          * stripped off, leaving us with the working file.
          *
@@ -1165,7 +1176,8 @@
 
         if (strncmp (fn, strip_path, strip_path_len) != 0)
         {
-                /* if the very first file fails the strip path,
+                /* 
+                 * if the very first file fails the strip path,
                  * then maybe we need to try for an alternate.
                  * this will happen if symlinks are being used
                  * on the server.  our best guess is to look
@@ -1583,8 +1595,11 @@
 
         funk = fnk_descr[ps->funk_factor];
 
-        /* this '---...' is different from the 28 hyphens that separate cvs log
-         * output */
+        /*
+         * this '---...' is different from
+         * the 28 hyphens that separate cvs log
+         * output
+         */
         printf ("---------------------\n");
         printf ("PatchSet %d %s\n", ps->psid, funk);
         printf ("Date: %d/%02d/%02d %02d:%02d:%02d\n",
@@ -1736,10 +1751,12 @@
                                 int ret =
                                   compare_rev_strings (psm1->post_rev->rev,
                                                        psm2->post_rev->rev);
-                                // debug(DEBUG_APPMSG1, "file: %s comparing %s
-                                // %s = %d", psm1->file->filename,
-                                // psm1->post_rev->rev, psm2->post_rev->rev,
-                                // ret);
+                                /*
+                                 * debug(DEBUG_APPMSG1, "file: %s comparing %s
+                                 * %s = %d", psm1->file->filename,
+                                 * psm1->post_rev->rev, psm2->post_rev->rev,
+                                 * ret);
+                                 */
                                 return ret;
                         }
                 }
@@ -1808,9 +1825,8 @@
         }
         else
         {
-                debug (DEBUG_APPERROR,
-                       "how can we have both patchsets pre-existing?");
-                exit (1);
+                errx (EXIT_FAILURE,
+                      "how can we have both patchsets pre-existing?");
         }
 
         if (min < d && d < max)
@@ -2115,10 +2131,10 @@
                          */
                         if (stat < 0 || stat > check_ret || WIFSIGNALED (ret))
                         {
-                                debug (DEBUG_APPERROR,
-                                       "system command returned non-zero exit status: %d: aborting",
-                                       stat);
-                                exit (1);
+                                errx (1,
+                                      "system command returned non-zero "
+                                      "exit status: %d: aborting",
+                                      stat);
                         }
                 }
         }
@@ -2129,8 +2145,9 @@
 {
         char *p;
 
-        /* The "revision" log line can include extra information
-         * including who is locking the file --- strip that out.
+        /*
+         * The "revision" log line can include extra information
+         * including who is locking the file, strip that out.
          */
 
         p = rev_str;
@@ -2199,12 +2216,7 @@
 
                 /* determine the branch this revision was committed on */
                 if (! get_branch (branch_str, rev->rev))
-                {
-                        debug (DEBUG_APPERROR,
-                               "invalid rev format %s",
-                               rev->rev);
-                        exit (1);
-                }
+                        errx (EXIT_FAILURE, "invalid rev format %s", rev->rev);
 
                 rev->branch =
                   (char *) get_hash_object (file->branches, branch_str);
@@ -2955,8 +2967,11 @@
                         d1 = branch_rev ? count_dots (branch_rev) : 1;
                 }
 
-                /* HACK: we sometimes pretend to derive from the import branch.
-                 * just don't do that.  this is the easiest way to prevent...
+                /*
+                 * HACK: we sometimes pretend to derive from the
+                 * import branch.
+                 * Just don't do that.
+                 * This is the easiest way to prevent...
                  */
                 d2 = (strcmp (rev->rev, "1.1.1.1") == 0)
                        ? 0
@@ -2965,8 +2980,10 @@
                 if (d2 > d1)
                         head_ps->ancestor_branch = rev->branch;
 
-                // printf("-----> %d ancestry %s %s %s\n", ps->psid, ps->branch,
-                // head_ps->ancestor_branch, rev->file->filename);
+                /*
+                 * printf("-----> %d ancestry %s %s %s\n", ps->psid, ps->branch,
+                 * head_ps->ancestor_branch, rev->file->filename);
+                 */
         }
 }
 
--- a/cvsps_types.h	Wed May 15 15:57:59 2019 +0000
+++ b/cvsps_types.h	Wed May 15 16:22:42 2019 +0000
@@ -62,11 +62,14 @@
 struct _CvsFile
 {
         char *filename;
-        struct hash_table
-          *revisions; /* rev_str to revision [CvsFileRevision*] */
-        struct hash_table *branches; /* branch to branch_sym [char*] */
-        struct hash_table *branches_sym; /* branch_sym to branch [char*] */
-        struct hash_table *symbols; /* tag to revision [CvsFileRevision*]     */
+        /* rev_str to revision [CvsFileRevision*] */
+        struct hash_table *revisions;
+        /* branch to branch_sym [char*] */
+        struct hash_table *branches;
+        /* branch_sym to branch [char*] */
+        struct hash_table *branches_sym;
+        /* tag to revision [CvsFileRevision*]     */
+        struct hash_table *symbols;
         /*
          * this is a hack. when we initially create entries in the symbol hash
          * we don't have the branch info, so the CvsFileRevisions get created
--- a/util.c	Wed May 15 15:57:59 2019 +0000
+++ b/util.c	Wed May 15 16:22:42 2019 +0000
@@ -18,6 +18,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <err.h>
 
 #include <cbtcommon/debug.h>
 
@@ -76,15 +77,13 @@
 
         if (! (home = getenv ("HOME")))
         {
-                debug (DEBUG_APPERROR, "HOME environment variable not set");
-                exit (1);
+                errx (1, "HOME environment variable not set");
         }
 
         if (snprintf (prefix, PATH_MAX, "%s/%s", home, CVSPS_PREFIX) >=
             PATH_MAX)
         {
-                debug (DEBUG_APPERROR, "prefix buffer overflow");
-                exit (1);
+                errx (1, "prefix buffer overflow");
         }
 
         /* Make sure the prefix directory exists */
@@ -119,8 +118,7 @@
         ret = strdup (str);
         if (! ret)
         {
-                debug (DEBUG_ERROR, "strdup failed");
-                exit (1);
+                errx (1, "strdup failed");
         }
 
         return ret;
@@ -337,8 +335,9 @@
 void
 strcpy_a (char *dst, const char *src, int n)
 {
-        /* place a 'sentinel' char in final place in buffer
-         * if strncpy expires the avail. space, this char.
+        /*
+         * place a 'sentinel' char in final place in buffer
+         * if strncpy expires the available space, this char
          * will no longer be \0
          */
         dst[n - 1] = 0;
@@ -346,7 +345,6 @@
 
         if (dst[n - 1] != 0)
         {
-                debug (DEBUG_APPERROR, "FATAL: internal buffer exhausted.");
-                exit (1);
+                errx (1, "FATAL: internal buffer exhausted.");
         }
 }