diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2014-09-04 20:39:34 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2014-09-04 21:06:55 +0200 |
commit | 90444a9e3de77c4ddebeb4ee2be4ef32fa642dc4 (patch) | |
tree | 63a06b195a6d1a7e5c480374324da2f9aa2736ca | |
parent | b0a0688340e20a682c3602eb6d591077a23d38b9 (diff) | |
download | gnutls-90444a9e3de77c4ddebeb4ee2be4ef32fa642dc4.tar.gz |
when setting a DN properly handle spaces and escaped commas
-rw-r--r-- | lib/x509/x509_dn.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/x509/x509_dn.c b/lib/x509/x509_dn.c index 0131de04ad..03cdc7e8ec 100644 --- a/lib/x509/x509_dn.c +++ b/lib/x509/x509_dn.c @@ -39,8 +39,10 @@ int dn_attr_crt_set(set_dn_func f, void *crt, const gnutls_datum_t * name, const gnutls_datum_t * val) { char _oid[MAX_OID_SIZE]; + gnutls_datum_t tmp; const char *oid; int ret; + unsigned i; if (name->size == 0 || val->size == 0) return gnutls_assert_val(GNUTLS_E_PARSING_ERROR); @@ -73,7 +75,23 @@ int dn_attr_crt_set(set_dn_func f, void *crt, const gnutls_datum_t * name, if (val->data[0] == '#') return gnutls_assert_val(GNUTLS_E_PARSING_ERROR); - ret = f(crt, oid, 0, val->data, val->size); + ret = _gnutls_set_datum(&tmp, val->data, val->size); + if (ret < 0) + return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR); + + if (val->size > 1) { + /* remove \\, */ + for (i=1;i<tmp.size-1;i++) { + if (tmp.data[i] == '\\' && tmp.data[i+1] == ',') { + memmove(&tmp.data[i], &tmp.data[i+1], tmp.size-i-1); + tmp.size--; + } + } + } + + ret = f(crt, oid, 0, tmp.data, tmp.size); + gnutls_free(tmp.data); + if (ret < 0) return gnutls_assert_val(ret); @@ -109,12 +127,17 @@ static int read_attr_and_val(const char **ptr, /* Read value */ val->data = (void *) p; - while (*p != 0 && !c_isspace(*p) - && (*p != ',' || (*p == ',' && *(p - 1) == '\\')) - && *p != '\n') + while (*p != 0 && (*p != ',' || (*p == ',' && *(p - 1) == '\\')) + && *p != '\n') { p++; + } val->size = p - (val->data); + /* remove spaces from the end */ + while(val->size > 0 && c_isspace(val->data[val->size-1])) { + val->size--; + } + if (val->size == 0 || name->size == 0) return gnutls_assert_val(GNUTLS_E_PARSING_ERROR); |