summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2014-04-19 11:21:16 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2014-04-19 11:21:16 +0000
commit177818cf1b15b104ba268235f8c0b8a7435f04de (patch)
tree674bfe0ea1da40ee52a072113322a33e9e45de46 /lib
parent040cde4c2a229a54547aa80565c66e99b0ad0ccf (diff)
Demonstrate correct usage of snprintf (regarding overflow detection)
ok guenther
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/printf.38
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3
index 072a7949c05..7a394c4f9df 100644
--- a/lib/libc/stdio/printf.3
+++ b/lib/libc/stdio/printf.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: printf.3,v 1.64 2013/07/17 05:42:11 schwarze Exp $
+.\" $OpenBSD: printf.3,v 1.65 2014/04/19 11:21:15 deraadt Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -33,7 +33,7 @@
.\"
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: July 17 2013 $
+.Dd $Mdocdate: April 19 2014 $
.Dt PRINTF 3
.Os
.Sh NAME
@@ -871,7 +871,9 @@ for later interpolation by
.Pp
Be sure to use the proper secure idiom:
.Bd -literal -offset indent
-snprintf(buffer, sizeof(buffer), "%s", string);
+ret = snprintf(buffer, sizeof(buffer), "%s", string);
+if (ret == -1 || ret >= sizeof(buffer)
+ goto toolong;
.Ed
.Pp
There is no way for