Home GnuPG

Fix buffer overflow in ksba_oid_to_str.
f715b9e156dfUnpublished

Unpublished Commit · Learn More

Not On Permanent Ref: This commit is not an ancestor of any permanent ref.

Description

Fix buffer overflow in ksba_oid_to_str.

* src/oid.c (ksba_oid_to_str): Fix unsigned underflow.
* tests/Makefile.am (noinst_PROGRAMS): Move t-oid to ..
(TESTS): here.
* tests/t-oid.c (test_oid_to_str): New.
(main): Run the new tests by default.  The former functionality
requires the use of one of the new options.

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 <wk@gnupg.org>

Details

Provenance
wernerAuthored on Nov 25 2014, 11:47 AM
Parents
rK6692de139862: Strip CRs while building the oid translation table.
Branches
Unknown
Tags
Unknown

Event Timeline

Werner Koch <wk@gnupg.org> committed rKf715b9e156df: Fix buffer overflow in ksba_oid_to_str. (authored by Werner Koch <wk@gnupg.org>).Nov 25 2014, 11:47 AM