diff options
author | James Morris <james.l.morris@oracle.com> | 2017-12-09 14:39:48 +1100 |
---|---|---|
committer | James Morris <james.l.morris@oracle.com> | 2017-12-09 14:39:48 +1100 |
commit | 4ded3bec65a07343258ed8fd9d46483f032d866f (patch) | |
tree | ecb134c1ac71a1c4ca59b50d4d097de7c3939cbf /lib/oid_registry.c | |
parent | f335195adf043168ee69d78ea72ac3e30f0c57ce (diff) | |
parent | 54c1fb39fe0495f846539ab765925b008f86801c (diff) | |
download | linux-4ded3bec65a07343258ed8fd9d46483f032d866f.tar.bz2 |
Merge tag 'keys-fixes-20171208' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs into keys-for-linus
Assorted fixes for keyrings, ASN.1, X.509 and PKCS#7.
Diffstat (limited to 'lib/oid_registry.c')
-rw-r--r-- | lib/oid_registry.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/oid_registry.c b/lib/oid_registry.c index 41b9e50711a7..0bcac6ccb1b2 100644 --- a/lib/oid_registry.c +++ b/lib/oid_registry.c @@ -116,14 +116,14 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize) int count; if (v >= end) - return -EBADMSG; + goto bad; n = *v++; ret = count = snprintf(buffer, bufsize, "%u.%u", n / 40, n % 40); + if (count >= bufsize) + return -ENOBUFS; buffer += count; bufsize -= count; - if (bufsize == 0) - return -ENOBUFS; while (v < end) { num = 0; @@ -134,20 +134,24 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize) num = n & 0x7f; do { if (v >= end) - return -EBADMSG; + goto bad; n = *v++; num <<= 7; num |= n & 0x7f; } while (n & 0x80); } ret += count = snprintf(buffer, bufsize, ".%lu", num); - buffer += count; - if (bufsize <= count) + if (count >= bufsize) return -ENOBUFS; + buffer += count; bufsize -= count; } return ret; + +bad: + snprintf(buffer, bufsize, "(bad)"); + return -EBADMSG; } EXPORT_SYMBOL_GPL(sprint_oid); |