diff options
author | Werner Koch <[email protected]> | 2014-11-25 10:58:56 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2014-11-25 10:58:56 +0000 |
commit | 8445ef24fc31e1fe0291e17f90f9f06b536e34da (patch) | |
tree | ecd31702f1ba7758b591534ced98733893f120fa /common/t-openpgp-oid.c | |
parent | build: Require libgpg-error 1.16. (diff) | |
download | gnupg-8445ef24fc31e1fe0291e17f90f9f06b536e34da.tar.gz gnupg-8445ef24fc31e1fe0291e17f90f9f06b536e34da.zip |
Fix buffer overflow in openpgp_oid_to_str.
* common/openpgp-oid.c (openpgp_oid_to_str): Fix unsigned underflow.
* common/t-openpgp-oid.c (BADOID): New.
(test_openpgp_oid_to_str): Add test cases.
--
The code has an obvious error by not considering invalid encoding for
arc-2. A first byte of 0x80 can be used to make a value of less then
80 and we then subtract 80 from that value as required by the OID
encoding rules. Due to the unsigned integer this results in a pretty
long value which won't fit anymore into the allocated buffer.
The fix is obvious. Also added a few simple test cases. Note that we
keep on using sprintf instead of snprintf because managing the
remaining length of the buffer would probably be more error prone than
assuring that the buffer is large enough. Getting rid of sprintf
altogether by using direct conversion along with membuf_t like code
might be possible.
Reported-by: Hanno Böck
Signed-off-by: Werner Koch <[email protected]>
Ported from libksba commit f715b9e156dfa99ae829fc694e5a0abd23ef97d7
Diffstat (limited to 'common/t-openpgp-oid.c')
-rw-r--r-- | common/t-openpgp-oid.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/common/t-openpgp-oid.c b/common/t-openpgp-oid.c index 79e5a7095..5cd778d72 100644 --- a/common/t-openpgp-oid.c +++ b/common/t-openpgp-oid.c @@ -32,6 +32,9 @@ } while(0) +#define BADOID "1.3.6.1.4.1.11591.2.12242973" + + static void test_openpgp_oid_from_str (void) { @@ -108,6 +111,12 @@ test_openpgp_oid_to_str (void) { "1.3.132.0.35", { 5, 0x2B, 0x81, 0x04, 0x00, 0x23 }}, + { BADOID, + { 9, 0x80, 0x02, 0x70, 0x50, 0x25, 0x46, 0xfd, 0x0c, 0xc0 }}, + + { BADOID, + { 1, 0x80 }}, + { NULL }}; gcry_mpi_t a; int idx; |