xref: /dflybsd-src/lib/libc/stdio/gets.3 (revision 086b156cdf18f6fbb398ffa6f62a25f4f158853e)
1*086b156cSSascha Wildner.\" Copyright (c) 1990, 1991, 1993
2*086b156cSSascha Wildner.\"	The Regents of the University of California.  All rights reserved.
3*086b156cSSascha Wildner.\"
4*086b156cSSascha Wildner.\" This code is derived from software contributed to Berkeley by
5*086b156cSSascha Wildner.\" Chris Torek and the American National Standards Committee X3,
6*086b156cSSascha Wildner.\" on Information Processing Systems.
7*086b156cSSascha Wildner.\"
8*086b156cSSascha Wildner.\" Redistribution and use in source and binary forms, with or without
9*086b156cSSascha Wildner.\" modification, are permitted provided that the following conditions
10*086b156cSSascha Wildner.\" are met:
11*086b156cSSascha Wildner.\" 1. Redistributions of source code must retain the above copyright
12*086b156cSSascha Wildner.\"    notice, this list of conditions and the following disclaimer.
13*086b156cSSascha Wildner.\" 2. Redistributions in binary form must reproduce the above copyright
14*086b156cSSascha Wildner.\"    notice, this list of conditions and the following disclaimer in the
15*086b156cSSascha Wildner.\"    documentation and/or other materials provided with the distribution.
16*086b156cSSascha Wildner.\" 3. Neither the name of the University nor the names of its contributors
17*086b156cSSascha Wildner.\"    may be used to endorse or promote products derived from this software
18*086b156cSSascha Wildner.\"    without specific prior written permission.
19*086b156cSSascha Wildner.\"
20*086b156cSSascha Wildner.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21*086b156cSSascha Wildner.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*086b156cSSascha Wildner.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*086b156cSSascha Wildner.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24*086b156cSSascha Wildner.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*086b156cSSascha Wildner.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*086b156cSSascha Wildner.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*086b156cSSascha Wildner.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*086b156cSSascha Wildner.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*086b156cSSascha Wildner.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*086b156cSSascha Wildner.\" SUCH DAMAGE.
31*086b156cSSascha Wildner.\"
32*086b156cSSascha Wildner.\"     @(#)fgets.3	8.1 (Berkeley) 6/4/93
33*086b156cSSascha Wildner.\" $FreeBSD: src/lib/libc/stdio/fgets.3,v 1.22 2009/02/28 06:00:58 das Exp $
34*086b156cSSascha Wildner.\"
35*086b156cSSascha Wildner.Dd September 9, 2019
36*086b156cSSascha Wildner.Dt GETS 3
37*086b156cSSascha Wildner.Os
38*086b156cSSascha Wildner.Sh NAME
39*086b156cSSascha Wildner.Nm gets
40*086b156cSSascha Wildner.Nd get a line from a stream
41*086b156cSSascha Wildner.Sh LIBRARY
42*086b156cSSascha Wildner.Lb libc
43*086b156cSSascha Wildner.Sh SYNOPSIS
44*086b156cSSascha Wildner.In stdio.h
45*086b156cSSascha Wildner.Ft char *
46*086b156cSSascha Wildner.Fn gets "char *str"
47*086b156cSSascha Wildner.Sh DESCRIPTION
48*086b156cSSascha Wildner.Bf -symbolic
49*086b156cSSascha WildnerThis interface is made obsolete by
50*086b156cSSascha Wildner.Xr fgets 3
51*086b156cSSascha Wildnerand
52*086b156cSSascha Wildner.Xr gets_s 3 .
53*086b156cSSascha WildnerSee
54*086b156cSSascha Wildner.Sx SECURITY CONSIDERATIONS
55*086b156cSSascha Wildnerbelow.
56*086b156cSSascha Wildner.Ef
57*086b156cSSascha Wildner.Pp
58*086b156cSSascha WildnerThe
59*086b156cSSascha Wildner.Fn gets
60*086b156cSSascha Wildnerfunction
61*086b156cSSascha Wildneris equivalent to
62*086b156cSSascha Wildner.Xr fgets 3
63*086b156cSSascha Wildnerwith an infinite
64*086b156cSSascha Wildner.Fa size
65*086b156cSSascha Wildnerand a
66*086b156cSSascha Wildner.Fa stream
67*086b156cSSascha Wildnerof
68*086b156cSSascha Wildner.Dv stdin ,
69*086b156cSSascha Wildnerexcept that the newline character (if any) is not stored in the string.
70*086b156cSSascha WildnerIt is the caller's responsibility to ensure that the input line,
71*086b156cSSascha Wildnerif any, is sufficiently short to fit in the string.
72*086b156cSSascha Wildner.Sh RETURN VALUES
73*086b156cSSascha WildnerUpon successful completion,
74*086b156cSSascha Wildner.Fn gets
75*086b156cSSascha Wildnerreturns
76*086b156cSSascha Wildnera pointer to the string.
77*086b156cSSascha WildnerIf end-of-file occurs before any characters are read,
78*086b156cSSascha Wildnerthey return
79*086b156cSSascha Wildner.Dv NULL
80*086b156cSSascha Wildnerand the buffer contents remain unchanged.
81*086b156cSSascha WildnerIf an error occurs,
82*086b156cSSascha Wildnerthey return
83*086b156cSSascha Wildner.Dv NULL
84*086b156cSSascha Wildnerand the buffer contents are indeterminate.
85*086b156cSSascha WildnerThe
86*086b156cSSascha Wildner.Fn gets
87*086b156cSSascha Wildnerfunction
88*086b156cSSascha Wildnerdoes not distinguish between end-of-file and error, and callers must use
89*086b156cSSascha Wildner.Xr feof 3
90*086b156cSSascha Wildnerand
91*086b156cSSascha Wildner.Xr ferror 3
92*086b156cSSascha Wildnerto determine which occurred.
93*086b156cSSascha Wildner.Sh ERRORS
94*086b156cSSascha Wildner.Bl -tag -width Er
95*086b156cSSascha Wildner.It Bq Er EBADF
96*086b156cSSascha WildnerThe given
97*086b156cSSascha Wildner.Fa stream
98*086b156cSSascha Wildneris not a readable stream.
99*086b156cSSascha Wildner.El
100*086b156cSSascha Wildner.Pp
101*086b156cSSascha WildnerThe
102*086b156cSSascha Wildner.Fn gets
103*086b156cSSascha Wildnerfunction may also fail and set
104*086b156cSSascha Wildner.Va errno
105*086b156cSSascha Wildnerfor any of the errors specified for the routine
106*086b156cSSascha Wildner.Xr getchar 3 .
107*086b156cSSascha Wildner.Sh SECURITY CONSIDERATIONS
108*086b156cSSascha WildnerThe
109*086b156cSSascha Wildner.Fn gets
110*086b156cSSascha Wildnerfunction cannot be used securely.
111*086b156cSSascha WildnerBecause of its lack of bounds checking,
112*086b156cSSascha Wildnerand the inability for the calling program
113*086b156cSSascha Wildnerto reliably determine the length of the next incoming line,
114*086b156cSSascha Wildnerthe use of this function enables malicious users
115*086b156cSSascha Wildnerto arbitrarily change a running program's functionality through
116*086b156cSSascha Wildnera buffer overflow attack.
117*086b156cSSascha WildnerIt is strongly suggested that the
118*086b156cSSascha Wildner.Fn fgets
119*086b156cSSascha Wildnerand
120*086b156cSSascha Wildner.Fn gets_s
121*086b156cSSascha Wildnerfunctions be used in all cases.
122*086b156cSSascha Wildner.Sh SEE ALSO
123*086b156cSSascha Wildner.Xr fgets 3 ,
124*086b156cSSascha Wildner.Xr gets_s 3
125*086b156cSSascha Wildner.Sh STANDARDS
126*086b156cSSascha WildnerThe
127*086b156cSSascha Wildner.Fn gets
128*086b156cSSascha Wildnerfunction conforms to
129*086b156cSSascha Wildner.St -isoC-99 .
130