]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
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 42b91d85d440b45764b02a8f6574d11ed74bd22a..3030246e2422fab4ed9ac9be68f27d86c9335076 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 2c20e89a1bfae6cbcbfded63399cb242cbd55fb8..5f2d423432c83e38c92deee316f32985f7767c4b 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 13d529733d4ad34a11c0bb2c0c5121bc44c25c17..f97f13ea4ba98b670d7d0279d2b4e3d772716c69 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 1785c88fd3e27ecff504f1494813dca0a8a3fba7..f1f56f16a07ab63ba5c8da727099c76ca2c4cbcd 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);