From 69bab4cc6ee68ab98b6f207f6ab80352250f6b97 Mon Sep 17 00:00:00 2001 From: Peter Tripician Date: Thu, 22 Jan 2009 15:15:55 +0000 Subject: [PATCH] util-volparse-20090122 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. --- src/util/afsutil.h | 10 +++++++++- src/util/volparse.c | 27 +++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/util/afsutil.h b/src/util/afsutil.h index 413f2f18f..473abd4fd 100644 --- a/src/util/afsutil.h +++ b/src/util/afsutil.h @@ -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 diff --git a/src/util/volparse.c b/src/util/volparse.c index 1b69509ab..21a1f206b 100644 --- a/src/util/volparse.c +++ b/src/util/volparse.c @@ -9,7 +9,6 @@ #include #include - RCSID ("$Header$"); @@ -18,6 +17,11 @@ RCSID #include #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; -- 2.39.5