Whamcloud - gitweb
parse.c (uuid_parse): Fix uuid parsing bug which didn't complain
authorTheodore Ts'o <tytso@mit.edu>
Tue, 16 Jul 2002 03:49:57 +0000 (23:49 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 16 Jul 2002 03:49:57 +0000 (23:49 -0400)
for certain types of invalid input text.  (Addresses
Debian bug #152891).

tst_uuid.c: Add test cases for invalid text strings passed to
uuid_parse.

lib/uuid/ChangeLog
lib/uuid/Makefile.in
lib/uuid/parse.c
lib/uuid/tst_uuid.c

index 42b91d8..3030246 100644 (file)
@@ -1,3 +1,12 @@
+2002-07-15  Theodore Ts'o  <tytso@mit.edu>
+
+       * parse.c (uuid_parse): Fix uuid parsing bug which didn't complain
+               for certain types of invalid input text.  (Addresses
+               Debian bug #152891).
+
+       * tst_uuid.c: Add test cases for invalid text strings passed to
+               uuid_parse.
+
 2002-03-08  Theodore Tso  <tytso@mit.edu>
 
        * Release of E2fsprogs 1.27
index 2c20e89..5f2d423 100644 (file)
@@ -88,7 +88,7 @@ tst_uuid.o: $(srcdir)/tst_uuid.c
        $(CC) $(ALL_CFLAGS) -c $(srcdir)/tst_uuid.c -o tst_uuid.o
 
 tst_uuid: tst_uuid.o $(DEPLIBUUID)
-       $(CC) $(ALL_LDFLAGS) -o tst_uuid tst_uuid.o $(LIBUUID)
+       $(CC) $(ALL_LDFLAGS) -o tst_uuid tst_uuid.o $(OBJS)
 
 uuid_time: $(srcdir)/uuid_time.c $(DEPLIBUUID)
        $(CC) $(ALL_CFLAGS) -DDEBUG -o uuid_time $(srcdir)/uuid_time.c \
index 13d5297..f97f13e 100644 (file)
@@ -27,9 +27,12 @@ int uuid_parse(const char *in, uuid_t uu)
                return -1;
        for (i=0, cp = in; i <= 36; i++,cp++) {
                if ((i == 8) || (i == 13) || (i == 18) ||
-                   (i == 23))
+                   (i == 23)) {
                        if (*cp == '-')
                                continue;
+                       else
+                               return -1;
+               }
                if (i== 36)
                        if (*cp == 0)
                                continue;
index 1785c88..f1f56f1 100644 (file)
 
 #include "uuid.h"
 
+static int test_uuid(const char * uuid, int isValid)
+{
+       static const char * validStr[2] = {"invalid", "valid"};
+       uuid_t uuidBits;
+       int parsedOk;
+
+       parsedOk = uuid_parse(uuid, uuidBits) == 0;
+       
+       printf("%s is %s", uuid, validStr[isValid]);
+       if (parsedOk != isValid) {
+               printf(" but uuid_parse says %s\n", validStr[parsedOk]);
+               return 1;
+       }
+       printf(", OK\n");
+       return 0;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -107,6 +124,18 @@ main(int argc, char **argv)
                printf("UUID copy and compare failed!\n");
                failed++;
        }
+       failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981b", 1);
+       failed += test_uuid("84949CC5-4701-4A84-895B-354C584A981B", 1);
+       failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981bc", 0);
+       failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981", 0);
+       failed += test_uuid("84949cc5x4701-4a84-895b-354c584a981b", 0);
+       failed += test_uuid("84949cc504701-4a84-895b-354c584a981b", 0);
+       failed += test_uuid("84949cc5-470104a84-895b-354c584a981b", 0);
+       failed += test_uuid("84949cc5-4701-4a840895b-354c584a981b", 0);
+       failed += test_uuid("84949cc5-4701-4a84-895b0354c584a981b", 0);
+       failed += test_uuid("g4949cc5-4701-4a84-895b-354c584a981b", 0);
+       failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981g", 0);
+       
        if (failed) {
                printf("%d failures.\n", failed);
                exit(1);