summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-07-24 01:15:43 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-07-24 01:15:43 +0000
commit4c921dd7a04fb366e8891a7d593feb4485f95ed2 (patch)
tree56f38a7650eb403718a70cecac2747581676191d /lib
parentf1072800c624dea98bbe46e6d5c0debcb75c43c2 (diff)
warn about unsafe APIs at link time. Conditional on libc/Makefile defining
APIWARN; disabled by default. In use by many developers for quite some time, now they have a common knob to enable/disable this
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/Makefile.inc5
-rw-r--r--lib/libc/arch/i386/string/strcat.S9
-rw-r--r--lib/libc/arch/i386/string/strcpy.S9
-rw-r--r--lib/libc/arch/m68k/string/strcat.S9
-rw-r--r--lib/libc/arch/m68k/string/strcpy.S10
-rw-r--r--lib/libc/stdio/sprintf.c7
-rw-r--r--lib/libc/stdio/vsprintf.c7
-rw-r--r--lib/libc/string/strcat.c11
-rw-r--r--lib/libc/string/strcpy.c11
9 files changed, 63 insertions, 15 deletions
diff --git a/lib/libc/Makefile.inc b/lib/libc/Makefile.inc
index 7b346435666..7c37bc07aae 100644
--- a/lib/libc/Makefile.inc
+++ b/lib/libc/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.7 2003/01/20 19:41:53 marc Exp $
+# $OpenBSD: Makefile.inc,v 1.8 2003/07/24 01:15:41 deraadt Exp $
#
# This file contains make rules used to build libc
#
@@ -10,6 +10,9 @@ all:
CFLAGS+= -DLIBC_SCCS -DSYSLIBC_SCCS -I${LIBCSRCDIR}/include
+# Include link-time warnings about unsafe API uses (ie. strcpy)
+#CFLAGS+=-DAPIWARN
+
.if (${YP:L} == "yes")
CFLAGS+=-DYP -I${LIBCSRCDIR}/yp
.endif
diff --git a/lib/libc/arch/i386/string/strcat.S b/lib/libc/arch/i386/string/strcat.S
index fbb4dcec147..2d002d3d0ea 100644
--- a/lib/libc/arch/i386/string/strcat.S
+++ b/lib/libc/arch/i386/string/strcat.S
@@ -5,9 +5,16 @@
#include <machine/asm.h>
+#if defined(APIWARN)
+#APP
+ .stabs "warning: strcat() is almost always misused, consider using strlcat()",30,0,0,0
+ .stabs "_strcat",1,0,0,0
+#NO_APP
+#endif
+
#if defined(LIBC_SCCS)
.text
- .asciz "$OpenBSD: strcat.S,v 1.4 2003/06/11 21:07:03 deraadt Exp $"
+ .asciz "$OpenBSD: strcat.S,v 1.5 2003/07/24 01:15:42 deraadt Exp $"
#endif
/*
diff --git a/lib/libc/arch/i386/string/strcpy.S b/lib/libc/arch/i386/string/strcpy.S
index 5e819556ad4..3d2a4930b71 100644
--- a/lib/libc/arch/i386/string/strcpy.S
+++ b/lib/libc/arch/i386/string/strcpy.S
@@ -5,9 +5,16 @@
#include <machine/asm.h>
+#if defined(APIWARN)
+#APP
+ .stabs "warning: strcpy() is almost always misused, consider using strlcpy()",30,0,0,0
+ .stabs "_strcpy",1,0,0,0
+#NO_APP
+#endif
+
#if defined(LIBC_SCCS)
.text
- .asciz "$OpenBSD: strcpy.S,v 1.4 2003/06/11 21:07:03 deraadt Exp $"
+ .asciz "$OpenBSD: strcpy.S,v 1.5 2003/07/24 01:15:42 deraadt Exp $"
#endif
/*
diff --git a/lib/libc/arch/m68k/string/strcat.S b/lib/libc/arch/m68k/string/strcat.S
index d809086ec23..504ab936fec 100644
--- a/lib/libc/arch/m68k/string/strcat.S
+++ b/lib/libc/arch/m68k/string/strcat.S
@@ -33,9 +33,16 @@
#include "DEFS.h"
+#if defined(APIWARN)
+#APP
+ .stabs "warning: strcat() is almost always misused, consider using strlcat()",30,0,0,0
+ .stabs "_strcat",1,0,0,0
+#NO_APP
+#endif
+
#if defined(LIBC_SCCS)
.text
- .asciz "$OpenBSD: strcat.S,v 1.5 2003/06/11 21:06:33 deraadt Exp $"
+ .asciz "$OpenBSD: strcat.S,v 1.6 2003/07/24 01:15:42 deraadt Exp $"
#endif /* LIBC_SCCS */
ENTRY(strcat)
diff --git a/lib/libc/arch/m68k/string/strcpy.S b/lib/libc/arch/m68k/string/strcpy.S
index 7c175322fc3..db118cfb0c6 100644
--- a/lib/libc/arch/m68k/string/strcpy.S
+++ b/lib/libc/arch/m68k/string/strcpy.S
@@ -33,9 +33,17 @@
#include "DEFS.h"
+
+#if defined(APIWARN)
+#APP
+ .stabs "warning: strcpy() is almost always misused, consider using strlcpy()",30,0,0,0
+ .stabs "_strcpy",1,0,0,0
+#NO_APP
+#endif
+
#if defined(LIBC_SCCS)
.text
- .asciz "$OpenBSD: strcpy.S,v 1.6 2003/06/11 21:06:33 deraadt Exp $"
+ .asciz "$OpenBSD: strcpy.S,v 1.7 2003/07/24 01:15:42 deraadt Exp $"
#endif /* LIBC_SCCS */
ENTRY(strcpy)
diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c
index ba8cc70fe04..c7f2da2d970 100644
--- a/lib/libc/stdio/sprintf.c
+++ b/lib/libc/stdio/sprintf.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: sprintf.c,v 1.8 2003/06/11 21:05:09 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: sprintf.c,v 1.9 2003/07/24 01:15:42 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -39,6 +39,11 @@ static char rcsid[] = "$OpenBSD: sprintf.c,v 1.8 2003/06/11 21:05:09 deraadt Exp
#include <limits.h>
#include "local.h"
+#if defined(APIWARN)
+__warn_references(sprintf,
+ "warning: sprintf() is often misused, please use snprintf()");
+#endif
+
int
sprintf(char *str, char const *fmt, ...)
{
diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c
index 97010c5fc6e..e024a2fb880 100644
--- a/lib/libc/stdio/vsprintf.c
+++ b/lib/libc/stdio/vsprintf.c
@@ -31,12 +31,17 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: vsprintf.c,v 1.7 2003/06/11 21:05:09 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: vsprintf.c,v 1.8 2003/07/24 01:15:42 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <limits.h>
+#if defined(APIWARN)
+__warn_references(vsprintf,
+ "warning: vsprintf() is often misused, please use vsnprintf()");
+#endif
+
int
vsprintf(str, fmt, ap)
char *str;
diff --git a/lib/libc/string/strcat.c b/lib/libc/string/strcat.c
index 05a517a38b4..885822bae3e 100644
--- a/lib/libc/string/strcat.c
+++ b/lib/libc/string/strcat.c
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strcat.c,v 1.5 2003/06/02 20:18:38 millert Exp $";
+static char *rcsid = "$OpenBSD: strcat.c,v 1.6 2003/07/24 01:15:42 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#ifndef _KERNEL
@@ -37,10 +37,13 @@ static char *rcsid = "$OpenBSD: strcat.c,v 1.5 2003/06/02 20:18:38 millert Exp $
#include <lib/libkern/libkern.h>
#endif
+#if defined(APIWARN)
+__warn_references(strcat,
+ "warning: strcat() is almost always misused, please use strlcat()");
+#endif
+
char *
-strcat(s, append)
- register char *s;
- register const char *append;
+strcat(char *s, const char *append)
{
char *save = s;
diff --git a/lib/libc/string/strcpy.c b/lib/libc/string/strcpy.c
index 229d6d03bd2..e5c3d7dcbe8 100644
--- a/lib/libc/string/strcpy.c
+++ b/lib/libc/string/strcpy.c
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strcpy.c,v 1.5 2003/06/02 20:18:38 millert Exp $";
+static char *rcsid = "$OpenBSD: strcpy.c,v 1.6 2003/07/24 01:15:42 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#ifndef _KERNEL
@@ -37,10 +37,13 @@ static char *rcsid = "$OpenBSD: strcpy.c,v 1.5 2003/06/02 20:18:38 millert Exp $
#include <lib/libkern/libkern.h>
#endif
+#if defined(APIWARN)
+__warn_references(strcpy,
+ "warning: strcpy() is almost always misused, please use strlcpy()");
+#endif
+
char *
-strcpy(to, from)
- register char *to;
- register const char *from;
+strcpy(char *to, const char *from)
{
char *save = to;