asn1: ber_write_OID_String() to be more picky about supplied OID
authorKamen Mazdrashki <kamenim@samba.org>
Wed, 20 Oct 2010 10:45:59 +0000 (13:45 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Thu, 21 Oct 2010 22:48:58 +0000 (01:48 +0300)
Now function will check for invalid OID handling cases where:
 - sub-identifier has invalid characters (non-digit)
 - 'dot' separator found on unexpected place. For instance
    '.' at start or end of the OID. Two '.' in a row.

lib/util/asn1.c

index 2a71f2f79def486810dbd9ab0254cf6afc191f9a..21d4bd43088d6a2dbb5f56d76cf9e6eb760c50c8 100644 (file)
@@ -221,10 +221,12 @@ bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
        char *newp;
        int i;
 
+       if (!isdigit(*p)) return false;
        v = strtoul(p, &newp, 10);
        if (newp[0] != '.') return false;
        p = newp + 1;
 
+       if (!isdigit(*p)) return false;
        v2 = strtoul(p, &newp, 10);
        if (newp[0] != '.') return false;
        p = newp + 1;
@@ -237,9 +239,12 @@ bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
 
        i = 1;
        while (*p) {
+               if (!isdigit(*p)) return false;
                v = strtoul(p, &newp, 10);
                if (newp[0] == '.') {
                        p = newp + 1;
+                       /* check for empty last component */
+                       if (!*p) return false;
                } else if (newp[0] == '\0') {
                        p = newp;
                } else {