Lines 37-43
Link Here
|
37 |
.Os |
37 |
.Os |
38 |
.Sh NAME |
38 |
.Sh NAME |
39 |
.Nm fgets , |
39 |
.Nm fgets , |
40 |
.Nm gets , |
|
|
41 |
.Nm gets_s |
40 |
.Nm gets_s |
42 |
.Nd get a line from a stream |
41 |
.Nd get a line from a stream |
43 |
.Sh LIBRARY |
42 |
.Sh LIBRARY |
Lines 48-55
Link Here
|
48 |
.Fn fgets "char * restrict str" "int size" "FILE * restrict stream" |
47 |
.Fn fgets "char * restrict str" "int size" "FILE * restrict stream" |
49 |
.Ft char * |
48 |
.Ft char * |
50 |
.Fn gets_s "char *str" "rsize_t size" |
49 |
.Fn gets_s "char *str" "rsize_t size" |
51 |
.Ft char * |
|
|
52 |
.Fn gets "char *str" |
53 |
.Sh DESCRIPTION |
50 |
.Sh DESCRIPTION |
54 |
The |
51 |
The |
55 |
.Fn fgets |
52 |
.Fn fgets |
Lines 81-103
except that the newline character (if any) is not stored in the string.
Link Here
|
81 |
The |
78 |
The |
82 |
.Fn gets |
79 |
.Fn gets |
83 |
function |
80 |
function |
84 |
is equivalent to |
81 |
was unsafe and is no longer available. |
85 |
.Fn fgets |
|
|
86 |
with an infinite |
87 |
.Fa size |
88 |
and a |
89 |
.Fa stream |
90 |
of |
91 |
.Dv stdin , |
92 |
except that the newline character (if any) is not stored in the string. |
93 |
It is the caller's responsibility to ensure that the input line, |
94 |
if any, is sufficiently short to fit in the string. |
95 |
.Sh RETURN VALUES |
82 |
.Sh RETURN VALUES |
96 |
Upon successful completion, |
83 |
Upon successful completion, |
97 |
.Fn fgets , |
84 |
.Fn fgets |
98 |
.Fn gets_s , |
|
|
99 |
and |
85 |
and |
100 |
.Fn gets |
86 |
.Fn gets_s |
101 |
return |
87 |
return |
102 |
a pointer to the string. |
88 |
a pointer to the string. |
103 |
If end-of-file occurs before any characters are read, |
89 |
If end-of-file occurs before any characters are read, |
Lines 109-118
they return
Link Here
|
109 |
.Dv NULL |
95 |
.Dv NULL |
110 |
and the buffer contents are indeterminate. |
96 |
and the buffer contents are indeterminate. |
111 |
The |
97 |
The |
112 |
.Fn fgets , |
98 |
.Fn fgets |
113 |
.Fn gets_s , |
|
|
114 |
and |
99 |
and |
115 |
.Fn gets |
100 |
.Fn gets_s |
116 |
functions |
101 |
functions |
117 |
do not distinguish between end-of-file and error, and callers must use |
102 |
do not distinguish between end-of-file and error, and callers must use |
118 |
.Xr feof 3 |
103 |
.Xr feof 3 |
Lines 139-146
or
Link Here
|
139 |
.Xr malloc 3 . |
124 |
.Xr malloc 3 . |
140 |
.Pp |
125 |
.Pp |
141 |
The function |
126 |
The function |
142 |
.Fn gets |
|
|
143 |
and |
144 |
.Fn gets_s |
127 |
.Fn gets_s |
145 |
may also fail and set |
128 |
may also fail and set |
146 |
.Va errno |
129 |
.Va errno |
Lines 153-163
for any of the errors specified for the routine
Link Here
|
153 |
.Xr fgetws 3 , |
136 |
.Xr fgetws 3 , |
154 |
.Xr getline 3 |
137 |
.Xr getline 3 |
155 |
.Sh STANDARDS |
138 |
.Sh STANDARDS |
156 |
The functions |
139 |
The |
157 |
.Fn fgets |
140 |
.Fn fgets |
158 |
and |
141 |
function conforms to |
159 |
.Fn gets |
|
|
160 |
conform to |
161 |
.St -isoC-99 . |
142 |
.St -isoC-99 . |
162 |
.Fn gets_s |
143 |
.Fn gets_s |
163 |
conforms to |
144 |
conforms to |
Lines 166-181
K.3.7.4.1.
Link Here
|
166 |
.Fn gets |
147 |
.Fn gets |
167 |
has been removed from |
148 |
has been removed from |
168 |
.St -isoC-2011 . |
149 |
.St -isoC-2011 . |
169 |
.Sh SECURITY CONSIDERATIONS |
|
|
170 |
The |
171 |
.Fn gets |
172 |
function cannot be used securely. |
173 |
Because of its lack of bounds checking, |
174 |
and the inability for the calling program |
175 |
to reliably determine the length of the next incoming line, |
176 |
the use of this function enables malicious users |
177 |
to arbitrarily change a running program's functionality through |
178 |
a buffer overflow attack. |
179 |
It is strongly suggested that the |
180 |
.Fn fgets |
181 |
function be used in all cases. |