git: kern: Fix -Wstringop-overflow warnings in md5c.c

Aaron LI aly at crater.dragonflybsd.org
Tue Oct 13 04:50:41 PDT 2026


commit 8a4138a8cdf9c5c209e41b5f4778e7eefac1b647
Author: Aaron LI <aly at aaronly.me>
Date:   Tue Oct 13 13:29:32 2026 +0800

    kern: Fix -Wstringop-overflow warnings in md5c.c
    
    GCC 12.5 generated the following warings for __kern__MD5Transform(). The
    reasons was the passed parameter '&context->A' had size 4 (type uint32_t),
    but the function would access 16 bytes (state[0..3]).  The code used a
    hack that the MD5_CTX struct defines A,B,C,D as continous members.
    
    ```
    /usr/src/sys/kern/md5c.c: In function 'MD5Update':
    /usr/src/sys/kern/md5c.c:174:17: warning: '__kern__MD5Transform' accessing 16 bytes in a region of size 4 [-Wstringop-overflow=]
      174 |                 __kern__MD5Transform (&context->A, (char *)context->data);
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/src/sys/kern/md5c.c:174:17: note: referencing argument 1 of type 'u_int32_t[4]' {aka 'unsigned int[4]'}
    /usr/src/sys/kern/md5c.c:174:17: note: referencing argument 2 of type 'const unsigned char[64]'
    /usr/src/sys/kern/md5c.c:232:1: note: in a call to function '__kern__MD5Transform'
      232 | __kern__MD5Transform (u_int32_t state[4], const unsigned char block[64])
          | ^~~~~~~~~~~~~~~~~~~~
    /usr/src/sys/kern/md5c.c:177:25: warning: '__kern__MD5Transform' accessing 16 bytes in a region of size 4 [-Wstringop-overflow=]
      177 |                         __kern__MD5Transform (&context->A, &input[i]);
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/src/sys/kern/md5c.c:177:25: note: referencing argument 1 of type 'u_int32_t[4]' {aka 'unsigned int[4]'}
    /usr/src/sys/kern/md5c.c:177:25: note: referencing argument 2 of type 'const unsigned char[64]'
    /usr/src/sys/kern/md5c.c:232:1: note: in a call to function '__kern__MD5Transform'
      232 | __kern__MD5Transform (u_int32_t state[4], const unsigned char block[64])
          | ^~~~~~~~~~~~~~~~~~~~
    ```

Summary of changes:
 sys/kern/md5c.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/8a4138a8cdf9c5c209e41b5f4778e7eefac1b647


-- 
DragonFly BSD source repository


More information about the Commits mailing list