From 6b3c9ddd0b9bf74151f165185c67550b83fd65ae Mon Sep 17 00:00:00 2001 From: avsm <> Date: Tue, 7 Oct 2003 22:17:27 +0000 Subject: [PATCH] corrent __bounded__ attribute for the *Data functions, and add __minbytes__ checks where appropriate. tested by itojun@ fixes PR 3505 from Janjaap van Velthooven --- src/include/md4.h | 21 ++++++++++++++------- src/include/md5.h | 21 ++++++++++++++------- src/include/rmd160.h | 21 ++++++++++++++------- src/include/sha1.h | 21 ++++++++++++++------- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/include/md4.h b/src/include/md4.h index ba020227..4dc26c04 100644 --- a/src/include/md4.h +++ b/src/include/md4.h @@ -1,5 +1,5 @@ /* MD4.H - header file for MD4C.C - * $OpenBSD: md4.h,v 1.10 2003/08/01 17:38:33 avsm Exp $ + * $OpenBSD: md4.h,v 1.11 2003/10/07 22:17:27 avsm Exp $ */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All @@ -37,13 +37,20 @@ typedef struct MD4Context { __BEGIN_DECLS void MD4Init(MD4_CTX *); -void MD4Update(MD4_CTX *, const unsigned char *, size_t); -void MD4Final(unsigned char [16], MD4_CTX *); -void MD4Transform(u_int32_t [4], const unsigned char [64]); -char * MD4End(MD4_CTX *, char *); -char * MD4File(char *, char *); +void MD4Update(MD4_CTX *, const unsigned char *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void MD4Final(unsigned char [16], MD4_CTX *) + __attribute__((__bounded__(__minbytes__,1,16))); +void MD4Transform(u_int32_t [4], const unsigned char [64]) + __attribute__((__bounded__(__minbytes__,1,4))) + __attribute__((__bounded__(__minbytes__,2,64))); +char * MD4End(MD4_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,33))); +char * MD4File(char *, char *) + __attribute__((__bounded__(__minbytes__,2,33))); char * MD4Data(const unsigned char *, size_t, char *) - __attribute__((__bounded__(__string__,3,2))); + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,33))); __END_DECLS #endif /* _MD4_H_ */ diff --git a/src/include/md5.h b/src/include/md5.h index b490c489..2c419aeb 100644 --- a/src/include/md5.h +++ b/src/include/md5.h @@ -1,5 +1,5 @@ /* MD5.H - header file for MD5C.C - * $OpenBSD: md5.h,v 1.10 2003/08/01 17:38:33 avsm Exp $ + * $OpenBSD: md5.h,v 1.11 2003/10/07 22:17:27 avsm Exp $ */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All @@ -38,13 +38,20 @@ typedef struct MD5Context { __BEGIN_DECLS void MD5Init(MD5_CTX *); -void MD5Update(MD5_CTX *, const unsigned char *, size_t); -void MD5Final(unsigned char [16], MD5_CTX *); -void MD5Transform(u_int32_t [4], const unsigned char [64]); -char * MD5End(MD5_CTX *, char *); -char * MD5File(char *, char *); +void MD5Update(MD5_CTX *, const unsigned char *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void MD5Final(unsigned char [16], MD5_CTX *) + __attribute__((__bounded__(__minbytes__,1,16))); +void MD5Transform(u_int32_t [4], const unsigned char [64]) + __attribute__((__bounded__(__minbytes__,1,4))) + __attribute__((__bounded__(__minbytes__,2,64))); +char * MD5End(MD5_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,33))); +char * MD5File(char *, char *) + __attribute__((__bounded__(__minbytes__,2,33))); char * MD5Data(const unsigned char *, size_t, char *) - __attribute__ ((__bounded__(__string__,3,2))); + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,33))); __END_DECLS #endif /* _MD5_H_ */ diff --git a/src/include/rmd160.h b/src/include/rmd160.h index de1e034c..1c5b885a 100644 --- a/src/include/rmd160.h +++ b/src/include/rmd160.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rmd160.h,v 1.10 2003/08/01 17:38:33 avsm Exp $ */ +/* $OpenBSD: rmd160.h,v 1.11 2003/10/07 22:17:27 avsm Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. * @@ -36,13 +36,20 @@ typedef struct RMD160Context { __BEGIN_DECLS void RMD160Init(RMD160_CTX *); -void RMD160Transform(u_int32_t [5], const u_char [64]); -void RMD160Update(RMD160_CTX *, const u_char *, u_int32_t); -void RMD160Final(u_char [20], RMD160_CTX *); -char *RMD160End(RMD160_CTX *, char *); -char *RMD160File(char *, char *); +void RMD160Transform(u_int32_t [5], const u_char [64]) + __attribute__((__bounded__(__minbytes__,1,5))) + __attribute__((__bounded__(__minbytes__,2,64))); +void RMD160Update(RMD160_CTX *, const u_char *, u_int32_t) + __attribute__((__bounded__(__string__,2,3))); +void RMD160Final(u_char [20], RMD160_CTX *) + __attribute__((__bounded__(__minbytes__,1,20))); +char *RMD160End(RMD160_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,41))); +char *RMD160File(char *, char *) + __attribute__((__bounded__(__minbytes__,2,41))); char *RMD160Data(const u_char *, size_t, char *) - __attribute__((__bounded__(__string__,3,2))); + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,41))); __END_DECLS #endif /* _RMD160_H */ diff --git a/src/include/sha1.h b/src/include/sha1.h index 9df09a81..f6bb73d0 100644 --- a/src/include/sha1.h +++ b/src/include/sha1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sha1.h,v 1.14 2003/08/01 17:38:33 avsm Exp $ */ +/* $OpenBSD: sha1.h,v 1.15 2003/10/07 22:17:27 avsm Exp $ */ /* * SHA-1 in C @@ -18,14 +18,21 @@ typedef struct { #include __BEGIN_DECLS -void SHA1Transform(u_int32_t state[5], const u_char buffer[64]); +void SHA1Transform(u_int32_t state[5], const u_char buffer[64]) + __attribute__((__bounded__(__minbytes__,1,5))) + __attribute__((__bounded__(__minbytes__,2,64))); void SHA1Init(SHA1_CTX *context); -void SHA1Update(SHA1_CTX *context, const u_char *data, u_int len); -void SHA1Final(u_char digest[20], SHA1_CTX *context); -char *SHA1End(SHA1_CTX *, char *); -char *SHA1File(char *, char *); +void SHA1Update(SHA1_CTX *context, const u_char *data, u_int len) + __attribute__((__bounded__(__string__,2,3))); +void SHA1Final(u_char digest[20], SHA1_CTX *context) + __attribute__((__bounded__(__minbytes__,1,20))); +char *SHA1End(SHA1_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,41))); +char *SHA1File(char *, char *) + __attribute__((__bounded__(__minbytes__,2,41))); char *SHA1Data(const u_char *, size_t, char *) - __attribute__((__bounded__ (__string__,3,2))); + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,41))); __END_DECLS #define SHA1_DIGESTSIZE 20