cvs-cvs
[Top][All Lists]
Advanced

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

[Cvs-cvs] ccvs/src ChangeLog client.c [cvs1-11-x-branch]


From: Derek Robert Price
Subject: [Cvs-cvs] ccvs/src ChangeLog client.c [cvs1-11-x-branch]
Date: Fri, 07 Apr 2006 17:16:04 +0000

CVSROOT:        /cvsroot/cvs
Module name:    ccvs
Branch:         cvs1-11-x-branch
Changes by:     Derek Robert Price <address@hidden>     06/04/07 17:16:04

Modified files:
        src            : ChangeLog client.c 

Log message:
        * client.c (strto_file_size): New function which checks for errors when
        parsing protocol input.
        (read_counted_file, update_entries, handle_mbinary): Use new function.
        Remove FIXME.
        (Thanks to a report from Brendan Harrison
        <address@hidden>.)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/cvs/ccvs/src/ChangeLog.diff?only_with_tag=cvs1-11-x-branch&tr1=1.2336.2.436&tr2=1.2336.2.437&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/cvs/ccvs/src/client.c.diff?only_with_tag=cvs1-11-x-branch&tr1=1.318.4.35&tr2=1.318.4.36&r1=text&r2=text

Patches:
Index: ccvs/src/ChangeLog
diff -u ccvs/src/ChangeLog:1.2336.2.436 ccvs/src/ChangeLog:1.2336.2.437
--- ccvs/src/ChangeLog:1.2336.2.436     Fri Apr  7 14:51:58 2006
+++ ccvs/src/ChangeLog  Fri Apr  7 17:16:04 2006
@@ -1,7 +1,9 @@
 2006-04-07  Derek Price  <address@hidden>
 
-       * client.c (read_counted_file, update_entries, handle_mbinary): Check
-       for errors when parsing protocol input.  Remove FIXME.
+       * client.c (strto_file_size): New function which checks for errors when
+       parsing protocol input.
+       (read_counted_file, update_entries, handle_mbinary): Use new function.
+       Remove FIXME.
        (Thanks to a report from Brendan Harrison
        <address@hidden>.)
 
Index: ccvs/src/client.c
diff -u ccvs/src/client.c:1.318.4.35 ccvs/src/client.c:1.318.4.36
--- ccvs/src/client.c:1.318.4.35        Fri Apr  7 14:51:58 2006
+++ ccvs/src/client.c   Fri Apr  7 17:16:04 2006
@@ -1457,7 +1457,44 @@
 {
     call_in_directory (args, copy_a_file, (char *)NULL);
 }
-
+
+
+
+/* Attempt to read a file size from a string.  Accepts base 8 (0N), base 16
+ * (0xN), or base 10.  Exits on error.
+ *
+ * RETURNS
+ *   The file size, in a size_t.
+ *
+ * FATAL ERRORS
+ *   1.  As strtoul().
+ *   2.  If the number read exceeds SIZE_MAX.
+ */
+static size_t
+strto_file_size (const char *s)
+{
+    unsigned long tmp;
+    char *endptr;
+
+    /* Read it.  */
+    errno = 0;
+    tmp = strtoul (s, &endptr, 0);
+
+    /* Check for errors.  */
+    if (errno || endptr == s)
+       error (1, errno, "Server sent invalid file size `%s'", s);
+    if (*endptr != '\0')
+       error (1, 0,
+              "Server sent trailing characters in file size `%s'",
+              endptr);
+    if (tmp > SIZE_MAX)
+       error (1, 0, "Server sent file size exceeding client max.");
+
+    /* Return it.  */
+    return (size_t)tmp;
+}
+
+
 
 static void read_counted_file PROTO ((char *, char *));
 
@@ -1490,22 +1527,7 @@
     if (size_string[0] == 'z')
        error (1, 0, "\
 protocol error: compressed files not supported for that operation");
-
-    {
-       long tmp;
-       char *endptr;
-       tmp = strtoul (size_string, &endptr, 0);
-       if (tmp == ULONG_MAX || endptr == size_string)
-           error (1, tmp == ULONG_MAX ? errno : 0,
-                  "Server sent invalid file size `%s'", size_string);
-       if (*endptr != '\0')
-           error (1, 0,
-                  "Server sent trailing characters in file size `%s'",
-                  endptr);
-       if (tmp > SIZE_MAX)
-           error (1, 0, "Server sent file size exceeding client max.");
-       size = (size_t)tmp;
-    }
+    size = strto_file_size (size_string);
     free (size_string);
 
     /* A more sophisticated implementation would use only a limited amount
@@ -1807,21 +1829,7 @@
            use_gzip = 0;
            s = size_string;
        }
-       {
-           long tmp;
-           char *endptr;
-           tmp = strtoul (s, &endptr, 0);
-           if (tmp == ULONG_MAX || endptr == s)
-               error (1, tmp == ULONG_MAX ? errno : 0,
-                      "Server sent invalid file size `%s'", size_string);
-           if (*endptr != '\0')
-               error (1, 0,
-                      "Server sent trailing characters in file size `%s'",
-                      endptr);
-           if (tmp > SIZE_MAX)
-               error (1, 0, "Server sent file size exceeding client max.");
-           size = (size_t)tmp;
-       }
+       size = strto_file_size (s);
        free (size_string);
 
        /* Note that checking this separately from writing the file is
@@ -3096,21 +3104,7 @@
 
     /* Get the size.  */
     read_line (&size_string);
-    {
-       long tmp;
-       char *endptr;
-       tmp = strtoul (size_string, &endptr, 0);
-       if (tmp == ULONG_MAX || endptr == size_string)
-           error (1, tmp == ULONG_MAX ? errno : 0,
-                  "Server sent invalid file size `%s'", size_string);
-       if (*endptr != '\0')
-           error (1, 0,
-                  "Server sent trailing characters in file size `%s'",
-                  endptr);
-       if (tmp > SIZE_MAX)
-           error (1, 0, "Server sent file size exceeding client max.");
-       size = (size_t)tmp;
-    }
+    size = strto_file_size (size_string);
     free (size_string);
 
     /* OK, now get all the data.  The algorithm here is that we read




reply via email to

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