Module Name: src
Committed By: jruoho
Date: Sat May 1 08:12:30 UTC 2010
Modified Files:
src/lib/libc/stdlib: strsuftoll.3
Log Message:
Add more bugs. Namely, besides the return values that are confusing, no
function in a modern standard C library, exposed by <stdlib.h>, should be as
easy to (buffer) overflow as strsuftollx(3).
In addition, improvements to wording and markup.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdlib/strsuftoll.3
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/stdlib/strsuftoll.3
diff -u src/lib/libc/stdlib/strsuftoll.3:1.7 src/lib/libc/stdlib/strsuftoll.3:1.8
--- src/lib/libc/stdlib/strsuftoll.3:1.7 Wed Apr 30 13:10:51 2008
+++ src/lib/libc/stdlib/strsuftoll.3 Sat May 1 08:12:30 2010
@@ -1,4 +1,4 @@
-.\" $NetBSD: strsuftoll.3,v 1.7 2008/04/30 13:10:51 martin Exp $
+.\" $NetBSD: strsuftoll.3,v 1.8 2010/05/01 08:12:30 jruoho Exp $
.\"
.\" Copyright (c) 2002,2007 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd April 12, 2007
+.Dd May 1, 2010
.Dt STRSUFTOLL 3
.Os
.Sh NAME
@@ -49,7 +49,8 @@
.Fn strsuftollx
convert
.Fa val
-into a long long number,
+into a number of type
+.Vt long long ,
checking that the result is not smaller than
.Fa min
or larger than
@@ -57,19 +58,21 @@
Two or more decimal numbers may be separated by an
.Dq x
to indicate a product.
+.Pp
Each decimal number may have one of the following optional suffixes:
+.Pp
.Bl -tag -width 3n -offset indent -compact
-.It b
+.It Em b
Block; multiply by 512
-.It k
+.It Em k
Kibi; multiply by 1024 (1 KiB)
-.It m
+.It Em m
Mebi; multiply by 1048576 (1 MiB)
-.It g
+.It Em g
Gibi; multiply by 1073741824 (1 GiB)
-.It t
+.It Em t
Tebi; multiply by 1099511627776 (1 TiB)
-.It w
+.It Em w
Word; multiply by the number of bytes in an integer
.El
.Pp
@@ -83,6 +86,17 @@
and
.Fn strsuftoll
displays that error and terminates the process.
+The parameter
+.Fa desc
+is used to construct
+.Fa errbuf .
+.Pp
+Neither
+.Fa desc
+nor
+.Fa val
+may be
+.Dv NULL .
.Sh RETURN VALUES
The functions
.Fn strsuftoll
@@ -107,4 +121,25 @@
.Xr errx 3 ,
.Xr strtoll 3
.Sh BUGS
-Ignores the current locale.
+At least few limitations should be mentioned:
+.Bl -bullet
+.It
+Both functions ignore the current locale.
+.It
+Neither
+.Fn strsuftoll
+nor
+.Fn strsuftollx
+fail gracefully in case of invalid,
+.Dv NULL ,
+pointers.
+.It
+The return values are inconsistent.
+.It
+The
+.Fn strsuftollx
+function is prone to buffer overflows if used incorrectly.
+Arguably only
+.Fn strsuftoll
+should be exposed to a caller.
+.El