]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
DEVEL15-util-volparse-20090122
authorPeter Tripician <tripicia@cmf.nrl.navy.mil>
Thu, 22 Jan 2009 15:16:37 +0000 (15:16 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Thu, 22 Jan 2009 15:16:37 +0000 (15:16 +0000)
LICENSE IPL10
FIXES 84846

avoid some infinite loops on bad input

ensure that all partition ids are within the legal limit

provide prototypes for strlcat and strlcpy when the openafs
implementations are being used.

(cherry picked from commit 69bab4cc6ee68ab98b6f207f6ab80352250f6b97)

src/util/afsutil.h
src/util/volparse.c

index 413f2f18fc1529bfabf0e560437ce7e28bebf761..473abd4fd1b2f0ffa3471fdaf2255cfeb0277279 100644 (file)
@@ -115,12 +115,20 @@ afs_vsnprintf( /*@out@ */ char *p, size_t avail, const char *fmt,
 
 /* Abort on error, possibly trapping to debugger or dumping a trace. */
      void afs_NTAbort(void);
-#endif /* NT40 */
+#endif /* AFS_NT40_ENV */
 
      typedef char b32_string_t[8];
 /* b64_string_t is 8 bytes, in stds.h */
      typedef char lb64_string_t[12];
 
+#ifndef HAVE_STRLCAT
+extern size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
+
+#ifndef HAVE_STRLCPY
+extern size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif
+
 #ifndef UKERNEL
 #include "afs/ktime.h"
 #endif
index 1b69509abcda36e4c54f0b9740898ab3b7dc5ca2..21a1f206b02a1663c86363ea9daa5659802fab5e 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
-
 RCSID
     ("$Header$");
 
@@ -18,6 +17,11 @@ RCSID
 #include <stdlib.h>
 #endif
 
+#include "afsutil.h"
+
+/* maximum number of partitions - must match vol/voldefs.h */
+#define VOLMAXPARTS 255
+
 /**
  * map a partition id from any partition-style name.
  *
@@ -44,11 +48,11 @@ volutil_GetPartitionID(char *aname)
     if (tc >= '0' && tc <= '9') {
        temp = atoi(aname);
        /* this next check is to make the syntax less ambiguous when discriminating
-        * between volume numbers and partition IDs.  This less things like
-        * bos salvage do some reasonability checks its input w/o checking
+        * between volume numbers and partition IDs.  This lets things like
+        * bos salvage do some reasonability checks on its input w/o checking
         * to see if the partition is really on the server.
         */
-       if (temp < 0 || temp > 25)
+       if (temp < 0 || temp >= VOLMAXPARTS)
            return -1;
        else
            return temp;
@@ -76,7 +80,8 @@ volutil_GetPartitionID(char *aname)
            return -1;          /* wrongo */
        if (ascii[1] < 'a' || ascii[1] > 'z')
            return -1;          /* just as bad */
-       return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
+       temp = (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
+        return (temp >= VOLMAXPARTS ? -1 : temp);
     }
 }
 
@@ -102,7 +107,7 @@ volutil_PartitionName2_r(afs_int32 part, char *tbuffer, size_t buflen)
     char tempString[3];
     register int i;
 
-    if (part < 0 || part >= (26 * 26 + 26)) {
+    if (part < 0 || part >= VOLMAXPARTS) {
        return -2;
     }
 
@@ -229,7 +234,7 @@ util_GetInt32(register char *as, afs_int32 * aval)
     negative = 0;
 
     /* skip over leading spaces */
-    while ((tc = *as)) {
+    for (; tc = *as; as++) {
        if (tc != ' ' && tc != '\t')
            break;
     }
@@ -252,12 +257,11 @@ util_GetInt32(register char *as, afs_int32 * aval)
        base = 10;
 
     /* compute the # itself */
-    while ((tc = *as)) {
+    for (; tc = *as; as++) {
        if (!ismeta(tc, base))
            return -1;
        total *= base;
        total += getmeta(tc);
-       as++;
     }
 
     if (negative)
@@ -277,7 +281,7 @@ util_GetUInt32(register char *as, afs_uint32 * aval)
     total = 0;                 /* initialize things */
 
     /* skip over leading spaces */
-    while ((tc = *as)) {
+    for (; tc = *as; as++) {
        if (tc != ' ' && tc != '\t')
            break;
     }
@@ -294,12 +298,11 @@ util_GetUInt32(register char *as, afs_uint32 * aval)
        base = 10;
 
     /* compute the # itself */
-    while ((tc = *as)) {
+    for (;tc = *as; as++) {
        if (!ismeta(tc, base))
            return -1;
        total *= base;
        total += getmeta(tc);
-       as++;
     }
 
     *aval = total;