cvs-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Cvs-cvs] ccvs/src ChangeLog server.c


From: Derek Robert Price
Subject: [Cvs-cvs] ccvs/src ChangeLog server.c
Date: Fri, 15 Sep 2006 12:26:00 +0000

CVSROOT:        /cvsroot/cvs
Module name:    ccvs
Changes by:     Derek Robert Price <dprice>     06/09/15 12:25:59

Modified files:
        src            : ChangeLog server.c 

Log message:
        Clean up repetitive server error handling code.
        * server.c (pending_msg, push_pending_error, push_pending_warning): New
        functions.
        (alloc_pending, alloc_pending_warning): Remove these functions.
        (*): Update all callers.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/ccvs/src/ChangeLog?cvsroot=cvs&r1=1.3497&r2=1.3498
http://cvs.savannah.gnu.org/viewcvs/ccvs/src/server.c?cvsroot=cvs&r1=1.470&r2=1.471

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/ChangeLog,v
retrieving revision 1.3497
retrieving revision 1.3498
diff -u -b -r1.3497 -r1.3498
--- ChangeLog   14 Sep 2006 15:33:41 -0000      1.3497
+++ ChangeLog   15 Sep 2006 12:25:59 -0000      1.3498
@@ -1,3 +1,11 @@
+2006-09-15  Derek Price  <address@hidden>
+
+       Clean up repetitive server error handling code.
+       * server.c (pending_msg, push_pending_error, push_pending_warning): New
+       functions.
+       (alloc_pending, alloc_pending_warning): Remove these functions.
+       (*): Update all callers.
+
 2006-09-14  Derek Price  <address@hidden>
 
        * sanity.sh (server3, client2): New tests.

Index: server.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/server.c,v
retrieving revision 1.470
retrieving revision 1.471
diff -u -b -r1.470 -r1.471
--- server.c    12 Aug 2006 17:16:01 -0000      1.470
+++ server.c    15 Sep 2006 12:25:59 -0000      1.471
@@ -24,6 +24,7 @@
 #include "getnline.h"
 #include "setenv.h"
 #include "vasprintf.h"
+#include "vasnprintf.h"
 #include "wait.h"
 
 /* CVS headers.  */
@@ -459,14 +460,24 @@
 
 
 
+/* Error number being saved for a break in the protocol.  */
 static int pending_error;
-/*
- * Malloc'd text for pending error.  Each line must start with "E ".  The
- * last line should not end with a newline.
+
+/* Potentially dynamically allocated text for pending error.  Each line must
+ * start with "E ".  The last line should not end with a newline.
  */
 static char *pending_error_text;
+
+/* So that messages might be printed when memory is low, the pending_error
+ * functions try to use this buffer before allocating the above.
+ */
+static char stat_pe_buf[256];
+
+/* Warning messages being saved up for a break in the protocol.  */
 static char *pending_warning_text;
 
+
+
 /* If an error is pending, print it and return 1.  If not, return 0.
    Also prints pending warnings, but this does not affect the return value.
    Must be called only in contexts where it is OK to send output.  */
@@ -505,6 +516,7 @@
        buf_flush (buf_to_net, 0);
 
        pending_error = 0;
+       if (pending_error_text != stat_pe_buf)
        free (pending_error_text);
        pending_error_text = NULL;
        return 1;
@@ -519,46 +531,71 @@
 # define error_pending() (pending_error || pending_error_text)
 # define warning_pending() (pending_warning_text)
 
-/* Allocate SIZE bytes for pending_error_text and return nonzero
-   if we could do it.  */
-static inline int
-alloc_pending_internal (char **dest, size_t size)
+
+
+/* Print to a string, setting pending_error to ENOMEM if allocation fails.  */
+static inline char *
+pending_msg (char *trybuf, size_t length, const char *message, va_list args)
 {
-    *dest = malloc (size);
-    if (!*dest)
-    {
-       pending_error = ENOMEM;
-       return 0;
-    }
-    return 1;
+    char *out;
+
+    /* Expand the message the user passed us.  */
+    out = vasnprintf (trybuf, &length, message, args);
+    if (!out) pending_error = ENOMEM;
+    return out;
 }
 
 
 
-/* Allocate SIZE bytes for pending_error_text and return nonzero
-   if we could do it.  */
-static int
-alloc_pending (size_t size)
+/* Using "push" in the name here is a little misleading.  Only one error is
+ * stored and there is no stack involved, but pushing errors onto a stack
+ * and sending them all when ready would be a nicer interface.
+ */
+static void
+push_pending_error (int errnum, const char *message, ...)
 {
-    if (error_pending ())
-       /* Probably alloc_pending callers will have already checked for
-          this case.  But we might as well handle it if they don't, I
-          guess.  */
-       return 0;
-    return alloc_pending_internal (&pending_error_text, size);
+    /* Only store one error.  */
+    if (error_pending ()) return;
+
+    if (errnum) pending_error = errnum;
+
+    if (message)
+    {
+       va_list args;
+       va_start (args, message);
+       pending_error_text = pending_msg (stat_pe_buf, sizeof stat_pe_buf,
+                                         message, args);
+       va_end (args);
+    }
+
+    return;
 }
 
 
 
-/* Allocate SIZE bytes for pending_error_text and return nonzero
-   if we could do it.  */
-static int
-alloc_pending_warning (size_t size)
+/* Using "push" in the name here is a little misleading.  Only one warning is
+ * stored and there is no stack involved, but pushing errors onto a stack
+ * and sending them all when ready would be a nicer interface.
+ */
+static void
+push_pending_warning (const char *message, ...)
 {
-    if (warning_pending ())
-       /* Warnings can be lost here.  */
-       return 0;
-    return alloc_pending_internal (&pending_warning_text, size);
+    va_list args;
+
+    /* I don't see a need to try so hard not to lose warnings, so no static
+     * buffer.
+     */
+
+    assert (message);
+
+    /* Only store one warning.  */
+    if (warning_pending ()) return;
+
+    va_start (args, message);
+    pending_warning_text = pending_msg (NULL, 0, message, args);
+    va_end (args);
+
+    return;
 }
 
 
@@ -802,9 +839,7 @@
 
     if (!ISABSOLUTE (arg))
     {
-       if (alloc_pending (80 + strlen (arg)))
-           sprintf (pending_error_text,
-                    "E Root %s must be an absolute pathname", arg);
+       push_pending_error (0, "E Root %s must be an absolute pathname", arg);
        return;
     }
 
@@ -817,9 +852,9 @@
        any reason why such a feature is needed.  */
     if (current_parsed_root != NULL)
     {
-       if (alloc_pending (80 + strlen (arg)))
-           sprintf (pending_error_text,
-                    "E Protocol error: Duplicate Root request, for %s", arg);
+       push_pending_error (0,
+                           "E Protocol error: Duplicate Root request, for %s",
+                           arg);
        return;
     }
 
@@ -830,9 +865,7 @@
 # endif
        )
     {
-       if (alloc_pending (80 + strlen (arg)))
-           sprintf (pending_error_text,
-                    "E Bad root %s", arg);
+       push_pending_error (0, "E Bad root %s", arg);
        return;
     }
 
@@ -847,13 +880,11 @@
     {
        if (strcmp (Pserver_Repos, current_parsed_root->directory) != 0)
        {
-           if (alloc_pending (80 + strlen (Pserver_Repos)
-                              + strlen (current_parsed_root->directory)))
                /* The explicitness is to aid people who are writing clients.
                   I don't see how this information could help an
                   attacker.  */
-               sprintf (pending_error_text, "\
-E Protocol error: Root says \"%s\" but pserver says \"%s\"",
+           push_pending_error (0,
+"E Protocol error: Root says \"%s\" but pserver says \"%s\"",
                         current_parsed_root->directory, Pserver_Repos);
            return;
        }
@@ -901,9 +932,7 @@
         */
        if (!ISABSOLUTE (get_cvs_tmp_dir ()))
        {
-           if (alloc_pending (80 + strlen (get_cvs_tmp_dir ())))
-               sprintf (pending_error_text,
-                        "E Value of %s for TMPDIR is not absolute",
+           push_pending_error (0, "E Value of %s for TMPDIR is not absolute",
                         get_cvs_tmp_dir ());
 
            /* FIXME: we would like this error to be persistent, that
@@ -960,33 +989,19 @@
                p[1] = '\0';
            }
            if (status)
-           {
-               if (alloc_pending (80 + strlen (server_temp_dir)))
-                   sprintf (pending_error_text,
+               push_pending_error (status,
                            "E can't create temporary directory %s",
                            server_temp_dir);
-               pending_error = status;
-           }
 #ifndef CHMOD_BROKEN
            else if (chmod (server_temp_dir, S_IRWXU) < 0)
-           {
-               int save_errno = errno;
-               if (alloc_pending (80 + strlen (server_temp_dir)))
-                   sprintf (pending_error_text,
+               push_pending_error (errno,
 "E cannot change permissions on temporary directory %s",
                             server_temp_dir);
-               pending_error = save_errno;
-           }
 #endif
            else if (CVS_CHDIR (server_temp_dir) < 0)
-           {
-               int save_errno = errno;
-               if (alloc_pending (80 + strlen (server_temp_dir)))
-                   sprintf (pending_error_text,
-"E cannot change to temporary directory %s",
+               push_pending_error (errno,
+                                   "E cannot change to temporary directory %s",
                             server_temp_dir);
-               pending_error = save_errno;
-           }
        }
     }
 
@@ -1011,11 +1026,11 @@
            forced = true;
        }
 
-       if (forced && !quiet
-           && alloc_pending_warning (120 + strlen (program_name)))
-           sprintf (pending_warning_text,
+       if (forced && !quiet)
+           push_pending_warning (
 "E %s server: Forcing compression level %d (allowed: %d <= z <= %d).",
-                    program_name, gzip_level, config->MinCompressionLevel,
+                                 program_name, gzip_level,
+                                 config->MinCompressionLevel,
                     config->MaxCompressionLevel);
     }
 
@@ -1029,12 +1044,7 @@
     }
     (void) sprintf (path, "%s/%s", current_parsed_root->directory, CVSROOTADM);
     if (!isaccessible (path, R_OK | X_OK))
-    {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (path)))
-           sprintf (pending_error_text, "E Cannot access %s", path);
-       pending_error = save_errno;
-    }
+       push_pending_error (errno, "E Cannot access %s", path);
     free (path);
 
     setenv (CVSROOT_ENV, current_parsed_root->directory, 1);
@@ -1096,9 +1106,7 @@
      */
     if (!ISABSOLUTE (repos))
     {
-       if (alloc_pending (repos_len + 80))
-           sprintf (pending_error_text, "\
-E protocol error: %s is not absolute", repos);
+       push_pending_error (0, "E protocol error: %s is not absolute", repos);
        return 1;
     }
 
@@ -1106,11 +1114,8 @@
        || strncmp (current_parsed_root->directory, repos, root_len) != 0)
     {
     not_within:
-       if (alloc_pending (strlen (current_parsed_root->directory)
-                          + strlen (repos)
-                          + 80))
-           sprintf (pending_error_text, "\
-E protocol error: directory '%s' not within root '%s'",
+       push_pending_error (0,
+"E protocol error: directory '%s' not within root '%s'",
                     repos, current_parsed_root->directory);
        return 1;
     }
@@ -1134,10 +1139,8 @@
 {
     if (strchr (file, '/') != NULL)
     {
-       if (alloc_pending (strlen (file)
-                          + 80))
-           sprintf (pending_error_text, "\
-E protocol error: directory '%s' not within current directory",
+       push_pending_error (0,
+"E protocol error: directory '%s' not within current directory",
                     file);
        return 1;
     }
@@ -1204,17 +1207,14 @@
        except they need to report errors differently.  */
     if (ISABSOLUTE (dir))
     {
-       if (alloc_pending (80 + strlen (dir)))
-           sprintf ( pending_error_text,
-                     "E absolute pathnames invalid for server (specified 
`%s')",
+       push_pending_error (0,
+"E absolute pathnames invalid for server (specified `%s')",
                      dir);
        return;
     }
     if (pathname_levels (dir) > max_dotdot_limit)
     {
-       if (alloc_pending (80 + strlen (dir)))
-           sprintf (pending_error_text,
-                    "E protocol error: `%s' has too many ..", dir);
+       push_pending_error (0, "E protocol error: `%s' has too many ..", dir);
        return;
     }
 
@@ -1227,9 +1227,9 @@
     if (dir_len > 0
        && dir[dir_len - 1] == '/')
     {
-       if (alloc_pending (80 + dir_len))
-           sprintf (pending_error_text,
-                    "E protocol error: invalid directory syntax in %s", dir);
+       push_pending_error (0,
+"E protocol error: invalid directory syntax in %s",
+                           dir);
        return;
     }
 
@@ -1258,9 +1258,7 @@
     if (status != 0
        && status != EEXIST)
     {
-       if (alloc_pending (80 + strlen (gDirname)))
-           sprintf (pending_error_text, "E cannot mkdir %s", gDirname);
-       pending_error = status;
+       push_pending_error (status, "E cannot mkdir %s", gDirname);
        return;
     }
 
@@ -1273,18 +1271,13 @@
     status = create_adm_p (server_temp_dir, dir);
     if (status != 0)
     {
-       if (alloc_pending (80 + strlen (gDirname)))
-           sprintf (pending_error_text, "E cannot create_adm_p %s", gDirname);
-       pending_error = status;
+       push_pending_error (status, "E cannot create_adm_p %s", gDirname);
        return;
     }
 
-    if ( CVS_CHDIR (gDirname) < 0)
+    if (CVS_CHDIR (gDirname) < 0)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (gDirname)))
-           sprintf (pending_error_text, "E cannot change to %s", gDirname);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot change to %s", gDirname);
        return;
     }
     /*
@@ -1293,11 +1286,7 @@
      */
     if ((CVS_MKDIR (CVSADM, 0777) < 0) && (errno != EEXIST))
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (gDirname) + strlen (CVSADM)))
-           sprintf (pending_error_text,
-                    "E cannot mkdir %s/%s", gDirname, CVSADM);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot mkdir %s/%s", gDirname, CVSADM);
        return;
     }
 
@@ -1309,20 +1298,14 @@
     f = CVS_FOPEN (CVSADM_REP, "w");
     if (f == NULL)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (gDirname) + strlen (CVSADM_REP)))
-           sprintf (pending_error_text,
-                    "E cannot open %s/%s", gDirname, CVSADM_REP);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot open %s/%s", gDirname,
+                           CVSADM_REP);
        return;
     }
     if (fprintf (f, "%s", repos) < 0)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (gDirname) + strlen (CVSADM_REP)))
-           sprintf (pending_error_text,
-                    "E error writing %s/%s", gDirname, CVSADM_REP);
-       pending_error = save_errno;
+       push_pending_error (errno, "E error writing %s/%s", gDirname,
+                           CVSADM_REP);
        fclose (f);
        return;
     }
@@ -1336,32 +1319,23 @@
     {
        if (fprintf (f, "/.") < 0)
        {
-           int save_errno = errno;
-           if (alloc_pending (80 + strlen (gDirname) + strlen (CVSADM_REP)))
-               sprintf (pending_error_text,
-                        "E error writing %s/%s", gDirname, CVSADM_REP);
-           pending_error = save_errno;
+           push_pending_error (errno, "E error writing %s/%s",
+                               gDirname, CVSADM_REP);
            fclose (f);
            return;
        }
     }
     if (fprintf (f, "\n") < 0)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (gDirname) + strlen (CVSADM_REP)))
-           sprintf (pending_error_text,
-                    "E error writing %s/%s", gDirname, CVSADM_REP);
-       pending_error = save_errno;
+       push_pending_error (errno, "E error writing %s/%s", gDirname,
+                           CVSADM_REP);
        fclose (f);
        return;
     }
     if (fclose (f) == EOF)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (gDirname) + strlen (CVSADM_REP)))
-           sprintf (pending_error_text,
-                    "E error closing %s/%s", gDirname, CVSADM_REP);
-       pending_error = save_errno;
+       push_pending_error (errno, "E error closing %s/%s", gDirname,
+                           CVSADM_REP);
        return;
     }
     /* We open in append mode because we don't want to clobber an
@@ -1369,18 +1343,12 @@
     f = CVS_FOPEN (CVSADM_ENT, "a");
     if (f == NULL)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (CVSADM_ENT)))
-           sprintf (pending_error_text, "E cannot open %s", CVSADM_ENT);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot open %s", CVSADM_ENT);
        return;
     }
     if (fclose (f) == EOF)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (CVSADM_ENT)))
-           sprintf (pending_error_text, "E cannot close %s", CVSADM_ENT);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot close %s", CVSADM_ENT);
        return;
     }
 }
@@ -1394,9 +1362,7 @@
     assert (!proxy_log);
 # endif /* PROXY_SUPPORT */
 
-    if (alloc_pending (80))
-       strcpy (pending_error_text,
-               "E Repository request is obsolete; aborted");
+    push_pending_error (0, "E Repository request is obsolete; aborted");
     return;
 }
 
@@ -1489,18 +1455,12 @@
     f = CVS_FOPEN (CVSADM_ENTSTAT, "w+");
     if (f == NULL)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (CVSADM_ENTSTAT)))
-           sprintf (pending_error_text, "E cannot open %s", CVSADM_ENTSTAT);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot open %s", CVSADM_ENTSTAT);
        return;
     }
     if (fclose (f) == EOF)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (CVSADM_ENTSTAT)))
-           sprintf (pending_error_text, "E cannot close %s", CVSADM_ENTSTAT);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot close %s", CVSADM_ENTSTAT);
        return;
     }
 }
@@ -1521,27 +1481,18 @@
     f = CVS_FOPEN (CVSADM_TAG, "w+");
     if (f == NULL)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (CVSADM_TAG)))
-           sprintf (pending_error_text, "E cannot open %s", CVSADM_TAG);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot open %s", CVSADM_TAG);
        return;
     }
     if (fprintf (f, "%s\n", arg) < 0)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (CVSADM_TAG)))
-           sprintf (pending_error_text, "E cannot write to %s", CVSADM_TAG);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot write to %s", CVSADM_TAG);
        (void) fclose (f);
        return;
     }
     if (fclose (f) == EOF)
     {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (CVSADM_TAG)))
-           sprintf (pending_error_text, "E cannot close %s", CVSADM_TAG);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot close %s", CVSADM_TAG);
        return;
     }
 }
@@ -1601,10 +1552,7 @@
            nwrote = write (file, data, nread);
            if (nwrote < 0)
            {
-               int save_errno = errno;
-               if (alloc_pending (40))
-                   strcpy (pending_error_text, "E unable to write");
-               pending_error = save_errno;
+               push_pending_error (errno, "E unable to write");
 
                /* Read and discard the file data.  */
                while (size > 0)
@@ -1640,10 +1588,7 @@
     fd = CVS_OPEN (arg, O_WRONLY | O_CREAT | O_TRUNC, 0600);
     if (fd < 0)
     {
-       int save_errno = errno;
-       if (alloc_pending (40 + strlen (arg)))
-           sprintf (pending_error_text, "E cannot open %s", arg);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot open %s", arg);
        return;
     }
 
@@ -1712,9 +1657,7 @@
 
        if (gunzip_and_write (fd, file, (unsigned char *) filebuf, size))
        {
-           if (alloc_pending (80))
-               sprintf (pending_error_text,
-                        "E aborting due to compression error");
+           push_pending_error (0, "E aborting due to compression error");
        }
        free (filebuf);
     }
@@ -1736,10 +1679,7 @@
  out:
     if (close (fd) < 0 && !error_pending ())
     {
-       int save_errno = errno;
-       if (alloc_pending (40 + strlen (arg)))
-           sprintf (pending_error_text, "E cannot close %s", arg);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot close %s", arg);
        return;
     }
 }
@@ -1800,9 +1740,7 @@
                /* We didn't find the record separator or it is followed by
                 * the end of the string, so just exit.
                 */
-               if (alloc_pending (80))
-                   sprintf (pending_error_text,
-                            "E Malformed Entry encountered.");
+               push_pending_error (errno, "E Malformed Entry encountered.");
                return;
            }
            /* If the time field is not currently empty, then one of
@@ -1844,9 +1782,8 @@
 
            if (kopt != NULL)
            {
-               if (alloc_pending (strlen (name) + 80))
-                   sprintf (pending_error_text,
-                            "E protocol error: both Kopt and Entry for %s",
+               push_pending_error (0,
+"E protocol error: both Kopt and Entry for %s",
                             arg);
                free (kopt);
                kopt = NULL;
@@ -1905,11 +1842,7 @@
     fd = CVS_OPEN (sigfile_name, O_WRONLY | O_CREAT | O_TRUNC, 0600);
     if (fd < 0)
     {
-       int save_errno = errno;
-       if (alloc_pending (40 + strlen (sigfile_name)))
-           sprintf (pending_error_text, "E cannot open `%s'",
-                    sigfile_name);
-       pending_error = save_errno;
+       push_pending_error (errno, "E cannot open `%s'", sigfile_name);
        err = true;
        goto done;
     }
@@ -1926,9 +1859,8 @@
 
            if (rc == -2)
                pending_error = ENOMEM;
-           else if (alloc_pending (80))
-               sprintf (pending_error_text,
-                        "E error reading signature buffer.");
+           else
+               push_pending_error (0, "E error reading signature buffer.");
            pending_error = rc;
            err = true;
            goto done;
@@ -1936,12 +1868,9 @@
 
        if (write (fd, sig_data, got) < 0)
        {
-           int save_errno = errno;
-           if (alloc_pending (80 + strlen (sigfile_name)))
-               sprintf (pending_error_text,
-                        "E error writing temporary signature file `%s'.",
+           push_pending_error (errno,
+"E error writing temporary signature file `%s'.",
                         sigfile_name);
-           pending_error = save_errno;
            err = true;
            goto done;
         }
@@ -1951,10 +1880,7 @@
     if (fd >= 0
        && close (fd) < 0)
     {
-       if (!error_pending ()
-           && alloc_pending_warning (80 + strlen (sigfile_name)))
-           sprintf (pending_warning_text,
-                    "E error closing temporary signature file `%s'.",
+       push_pending_warning ("E error closing temporary signature file `%s'.",
                     sigfile_name);
        err = true;
     }
@@ -2046,10 +1972,9 @@
        read_size = atoi (size_text);
     free (size_text);
 
-    if (read_size < 0 && alloc_pending (80))
+    if (read_size < 0)
     {
-       sprintf (pending_error_text,
-                "E client sent invalid (negative) file size");
+       push_pending_error (0, "E client sent invalid (negative) file size");
        return;
     }
     else
@@ -2110,10 +2035,7 @@
        t.modtime = t.actime = checkin_time;
        if (utime (arg, &t) < 0)
        {
-           int save_errno = errno;
-           if (alloc_pending (80 + strlen (arg)))
-               sprintf (pending_error_text, "E cannot utime %s", arg);
-           pending_error = save_errno;
+           push_pending_error (errno, "E cannot utime %s", arg);
            free (mode_text);
            return;
        }
@@ -2125,10 +2047,7 @@
        free (mode_text);
        if (status)
        {
-           if (alloc_pending (40 + strlen (arg)))
-               sprintf (pending_error_text,
-                        "E cannot change mode for %s", arg);
-           pending_error = status;
+           push_pending_error (status, "E cannot change mode for %s", arg);
            return;
        }
     }
@@ -2164,8 +2083,7 @@
 
     if (sig_buf)
     {
-       if (alloc_pending (80))
-           sprintf (pending_error_text,
+       push_pending_error (0,
 "E Multiple Signature requests received for a single file.");
     }
     else
@@ -2174,9 +2092,7 @@
     status = next_signature (buf_from_net, sig_buf);
     if (status)
     {
-       if (alloc_pending (80))
-           sprintf (pending_error_text,
-                    "E Malformed Signature encountered.");
+       push_pending_error (0, "E Malformed Signature encountered.");
     }
     return;
 }
@@ -2229,9 +2145,7 @@
                /* We didn't find the record separator or it is followed by
                 * the end of the string, so just exit.
                 */
-               if (alloc_pending (80))
-                   sprintf (pending_error_text,
-                            "E Malformed Entry encountered.");
+               push_pending_error (0, "E Malformed Entry encountered.");
                return;
            }
            /* If the time field is not currently empty, then one of
@@ -2341,9 +2255,7 @@
     {
        if (!cp || *cp != '/')
        {
-           if (alloc_pending (80))
-               sprintf (pending_error_text,
-                        "E protocol error: Malformed Entry");
+           push_pending_error (0, "E protocol error: Malformed Entry");
            return;
        }
        cp = strchr (cp + 1, '/');
@@ -2383,9 +2295,8 @@
 
     if (kopt != NULL)
     {
-       if (alloc_pending (80 + strlen (arg)))
-           sprintf (pending_error_text,
-                    "E protocol error: duplicate Kopt request: %s", arg);
+       push_pending_error (0, "E protocol error: duplicate Kopt request: %s",
+                           arg);
        return;
     }
 
@@ -2396,9 +2307,8 @@
        other than via exit(), fprintf(), and such.  */
     if (strlen (arg) > 10)
     {
-       if (alloc_pending (80 + strlen (arg)))
-           sprintf (pending_error_text,
-                    "E protocol error: invalid Kopt request: %s", arg);
+       push_pending_error (0, "E protocol error: invalid Kopt request: %s",
+                           arg);
        return;
     }
 
@@ -2427,17 +2337,15 @@
 
     if (checkin_time_valid)
     {
-       if (alloc_pending (80 + strlen (arg)))
-           sprintf (pending_error_text,
-                    "E protocol error: duplicate Checkin-time request: %s",
+       push_pending_error (0,
+"E protocol error: duplicate Checkin-time request: %s",
                     arg);
        return;
     }
 
     if (!get_date (&t, arg, NULL))
     {
-       if (alloc_pending (80 + strlen (arg)))
-           sprintf (pending_error_text, "E cannot parse date %s", arg);
+       push_pending_error (0, "E cannot parse date %s", arg);
        return;
     }
 
@@ -2469,25 +2377,14 @@
           server_write_entries for each such file.  */
        f = CVS_FOPEN (CVSADM_ENT, "a");
        if (f == NULL)
-       {
-           int save_errno = errno;
-           if (alloc_pending (80 + strlen (CVSADM_ENT)))
-               sprintf (pending_error_text, "E cannot open %s", CVSADM_ENT);
-           pending_error = save_errno;
-       }
+           push_pending_error (errno, "E cannot open %s", CVSADM_ENT);
     }
     for (p = entries; p != NULL;)
     {
        if (!error_pending ())
        {
            if (fprintf (f, "%s\n", p->entry) < 0)
-           {
-               int save_errno = errno;
-               if (alloc_pending (80 + strlen(CVSADM_ENT)))
-                   sprintf (pending_error_text,
-                            "E cannot write to %s", CVSADM_ENT);
-               pending_error = save_errno;
-           }
+               push_pending_error (errno, "E cannot write to %s", CVSADM_ENT);
        }
        free (p->entry);
        q = p->next;
@@ -2496,12 +2393,7 @@
     }
     entries = NULL;
     if (f != NULL && fclose (f) == EOF && !error_pending ())
-    {
-       int save_errno = errno;
-       if (alloc_pending (80 + strlen (CVSADM_ENT)))
-           sprintf (pending_error_text, "E cannot close %s", CVSADM_ENT);
-       pending_error = save_errno;
-    }
+       push_pending_error (errno, "E cannot close %s", CVSADM_ENT);
 }
 
 
@@ -2938,8 +2830,7 @@
        if (!proxy_log)
        {
 # endif /* PROXY_SUPPORT */
-           if (alloc_pending (160) + strlen (program_name))
-               sprintf (pending_error_text, 
+           push_pending_error (0, 
 "E This CVS server does not support disconnected `%s edit'.  For now, remove 
all `%s' files in your workspace and try your command again.",
                         program_name, CVSADM_NOTIFY);
        return;
@@ -3053,10 +2944,7 @@
     }
     return;
   error:
-    pending_error = 0;
-    if (alloc_pending (80))
-       strcpy (pending_error_text,
-               "E Protocol error; misformed Notify request");
+    push_pending_error (0, "E Protocol error; misformed Notify request");
     if (data != NULL)
        free (data);
     if (new != NULL)
@@ -3172,9 +3060,7 @@
 
     if (argument_count >= 10000)
     {
-       if (alloc_pending (80))
-           sprintf (pending_error_text, 
-                    "E Protocol error: too many arguments");
+       push_pending_error (0, "E Protocol error: too many arguments");
        return;
     }
 
@@ -3213,8 +3099,7 @@
     
     if (argument_count <= 1) 
     {
-       if (alloc_pending (80))
-           sprintf (pending_error_text,
+       push_pending_error (0,
 "E Protocol error: called argumentx without prior call to argument");
        return;
     }
@@ -3246,10 +3131,7 @@
     if (arg[0] != '-' || arg[1] == '\0' || arg[2] != '\0')
     {
     error_return:
-       if (alloc_pending (strlen (arg) + 80))
-           sprintf (pending_error_text,
-                    "E Protocol error: bad global option %s",
-                    arg);
+       push_pending_error (0, "E Protocol error: bad global option %s", arg);
        return;
     }
     switch (arg[1])
@@ -3423,9 +3305,7 @@
 
     if (gDirname == NULL)
     {
-       if (alloc_pending (80))
-           sprintf (pending_error_text,
-"E Protocol error: `Directory' missing");
+       push_pending_error (0, "E Protocol error: `Directory' missing");
        return;
     }
 
@@ -3735,11 +3615,10 @@
            }
        }
 # else /* !PROXY_SUPPORT */
-       if (lookup_command_attribute (cmd_name)
-                   & CVS_CMD_MODIFIES_REPOSITORY
-           && alloc_pending (120))
-           sprintf (pending_error_text, 
-"E You need a CVS client that supports the `Redirect' response for write 
requests to this server.");
+       if (lookup_command_attribute (cmd_name) & CVS_CMD_MODIFIES_REPOSITORY)
+           push_pending_error (0, 
+"E You need a CVS client that supports the `Redirect' response for\n"
+"E write requests to this server.");
        return;
 # endif /* PROXY_SUPPORT */
     }
@@ -5028,21 +4907,18 @@
 
     if (!ISABSOLUTE (arg))
     {
-       if (alloc_pending (80 + strlen (arg)))
-           sprintf (pending_error_text,
-                    "E init %s must be an absolute pathname", arg);
+       push_pending_error (0, "E init %s must be an absolute pathname", arg);
     }
 # ifdef AUTH_SERVER_SUPPORT
     else if (Pserver_Repos != NULL)
     {
        if (strcmp (Pserver_Repos, arg) != 0)
        {
-           if (alloc_pending (80 + strlen (Pserver_Repos) + strlen (arg)))
                /* The explicitness is to aid people who are writing clients.
                   I don't see how this information could help an
                   attacker.  */
-               sprintf (pending_error_text, "\
-E Protocol error: init says \"%s\" but pserver says \"%s\"",
+           push_pending_error (0,
+"E Protocol error: init says \"%s\" but pserver says \"%s\"",
                         arg, Pserver_Repos);
        }
     }
@@ -5745,9 +5621,8 @@
        forced = true;
     }
 
-    if (forced && !quiet
-       && alloc_pending_warning (120 + strlen (program_name)))
-       sprintf (pending_warning_text,
+    if (forced && !quiet)
+       push_pending_warning (
 "E %s server: Forcing compression level %d (allowed: %d <= z <= %d).",
                 program_name, level, config->MinCompressionLevel,
                 config->MaxCompressionLevel);
@@ -5776,9 +5651,8 @@
        forced = true;
     }
 
-    if (forced && !quiet
-       && alloc_pending_warning (120 + strlen (program_name)))
-       sprintf (pending_warning_text,
+    if (forced && !quiet)
+       push_pending_warning (
 "E %s server: Forcing compression level %d (allowed: %d <= z <= %d).",
                 program_name, level, config->MinCompressionLevel,
                 config->MaxCompressionLevel);
@@ -6101,10 +5975,8 @@
 
     referrer = parse_cvsroot (arg);
 
-    if (!referrer
-       && alloc_pending (80 + strlen (arg)))
-       sprintf (pending_error_text,
-                "E Protocol error: Invalid Referrer: `%s'",
+    if (!referrer)
+       push_pending_error (0, "E Protocol error: Invalid Referrer: `%s'",
                 arg);
 }
 
@@ -6709,9 +6581,8 @@
                if (!(rq->flags & RQ_ROOTLESS)
                    && current_parsed_root == NULL)
                {
-                   if (alloc_pending (80))
-                       sprintf (pending_error_text,
-                                "E Protocol error: Root request missing");
+                   push_pending_error (0,
+"E Protocol error: Root request missing");
                }
                else
                {
@@ -6722,8 +6593,7 @@
                         * level has been configured, and no compression has
                         * been requested by the client.
                         */
-                       if (alloc_pending (80 + strlen (program_name)))
-                           sprintf (pending_error_text,
+                       push_pending_error (0,
 "E %s [server aborted]: Compression must be used with this server.",
                                     program_name);
                    }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]