You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA. */
#include "config.h"
#if !defined(__FreeBSD__) && !defined(__APPLE__)
#define _POSIX_SOURCE
#endif /* Some BSDs break <sys/socket.h> if this is defined. */
-#define _GNU_SOURCE
+#define _GNU_SOURCE
#define _XOPEN_SOURCE
#define _BSD_TYPES
#define __EXTENSIONS__
size_t n = strlen (src);
TRACE ("%s\n", __PRETTY_FUNCTION__);
- MF_VALIDATE_EXTENT(src, CLAMPADD(n, 1), __MF_CHECK_READ, "strcpy src");
+ MF_VALIDATE_EXTENT(src, CLAMPADD(n, 1), __MF_CHECK_READ, "strcpy src");
MF_VALIDATE_EXTENT(dest, CLAMPADD(n, 1), __MF_CHECK_WRITE, "strcpy dest");
return strcpy (dest, src);
}
size_t src_sz;
TRACE ("%s\n", __PRETTY_FUNCTION__);
dest_sz = strlen (dest);
- src_sz = strlen (src);
+ src_sz = strlen (src);
MF_VALIDATE_EXTENT(src, CLAMPADD(src_sz, 1), __MF_CHECK_READ, "strcat src");
MF_VALIDATE_EXTENT(dest, CLAMPADD(dest_sz, CLAMPADD(src_sz, 1)),
__MF_CHECK_WRITE, "strcat dest");
{
/* nb: validating the extents (s,n) might be a mistake for two reasons.
-
- (1) the string s might be shorter than n chars, and n is just a
+
+ (1) the string s might be shorter than n chars, and n is just a
poor choice by the programmer. this is not a "true" error in the
sense that the call to strncat would still be ok.
-
+
(2) we could try to compensate for case (1) by calling strlen(s) and
using that as a bound for the extent to verify, but strlen might fall off
the end of a non-terminated string, leading to a false positive.
-
+
so we will call strnlen(s,n) and use that as a bound.
if strnlen returns a length beyond the end of the registered extent
size_t s2_sz;
TRACE ("%s\n", __PRETTY_FUNCTION__);
s1_sz = strlen (s1);
- s2_sz = strlen (s2);
+ s2_sz = strlen (s2);
MF_VALIDATE_EXTENT(s1, CLAMPADD(s1_sz, 1), __MF_CHECK_READ, "strcmp 1st arg");
MF_VALIDATE_EXTENT(s2, CLAMPADD(s2_sz, 1), __MF_CHECK_WRITE, "strcmp 2nd arg");
return strcmp (s1, s2);
size_t s2_sz;
TRACE ("%s\n", __PRETTY_FUNCTION__);
s1_sz = strlen (s1);
- s2_sz = strlen (s2);
+ s2_sz = strlen (s2);
MF_VALIDATE_EXTENT(s1, CLAMPADD(s1_sz, 1), __MF_CHECK_READ, "strcasecmp 1st arg");
MF_VALIDATE_EXTENT(s2, CLAMPADD(s2_sz, 1), __MF_CHECK_READ, "strcasecmp 2nd arg");
return strcasecmp (s1, s2);
size_t n = strlen (s);
TRACE ("%s\n", __PRETTY_FUNCTION__);
MF_VALIDATE_EXTENT(s, CLAMPADD(n,1), __MF_CHECK_READ, "strdup region");
- result = (char *)CALL_REAL(malloc,
+ result = (char *)CALL_REAL(malloc,
CLAMPADD(CLAMPADD(n,1),
CLAMPADD(__mf_opts.crumple_zone,
__mf_opts.crumple_zone)));
MF_VALIDATE_EXTENT(s, sz, __MF_CHECK_READ, "strndup region"); /* nb: strNdup */
/* note: strndup still adds a \0, even with the N limit! */
- result = (char *)CALL_REAL(malloc,
+ result = (char *)CALL_REAL(malloc,
CLAMPADD(CLAMPADD(n,1),
CLAMPADD(__mf_opts.crumple_zone,
__mf_opts.crumple_zone)));
-
+
if (UNLIKELY(! result)) return result;
result += __mf_opts.crumple_zone;
#ifdef HAVE_MEMMEM
-WRAPPER2(void *, memmem,
+WRAPPER2(void *, memmem,
const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen)
{
/* The following indicate if the result of the corresponding function
* should be explicitly un/registered by the wrapper
*/
+
+#ifdef __FreeBSD__
+#define MF_REGISTER_fopen __MF_TYPE_STATIC
+#else
#undef MF_REGISTER_fopen
+#endif
#define MF_RESULT_SIZE_fopen (sizeof (FILE))
+
#undef MF_REGISTER_opendir
#define MF_RESULT_SIZE_opendir 0 /* (sizeof (DIR)) */
#undef MF_REGISTER_readdir
WRAPPER2(int, accept, int s, struct sockaddr *addr, socklen_t *addrlen)
{
TRACE ("%s\n", __PRETTY_FUNCTION__);
- MF_VALIDATE_EXTENT (addr, (size_t)*addrlen, __MF_CHECK_WRITE, "accept addr");
+ if (addr != NULL)
+ MF_VALIDATE_EXTENT (addr, (size_t)*addrlen, __MF_CHECK_WRITE, "accept addr");
return accept (s, addr, addrlen);
}