Home GnuPG

md: fix UBSAN warning

Description

md: fix UBSAN warning

* cipher/md.c (gcry_md_list): Define 'context' as array of
PROPERLY_ALIGNED_TYPE.
(md_enable, _gcry_md_reset, _gcry_md_close, md_final, md_set_key)
(prepare_macpads, md_read, md_extract): Access md context through
'gcry_md_list->context' pointer instead of 'gcry_md_list->context.c'.

This commit fixes error output seen with undefined behavior sanitizer:
md.c:980:28: runtime error: index 184 out of bounds for type 'char [1]'
md.c:991:28: runtime error: index 368 out of bounds for type 'char [1]'
md.c:713:44: runtime error: index 184 out of bounds for type 'char [1]'
md.c:830:42: runtime error: index 368 out of bounds for type 'char [1]'

Issue was reported in dev.gnupg.org task T3247 and Cryptofuzz.

  • GnuPG-bug-id: T3247
  • Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>

Details