diff options
author | Ed Maste <emaste@FreeBSD.org> | 2019-09-01 16:12:05 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2019-09-01 16:12:05 +0000 |
commit | 7381dcc9eeb7da1b1ba103212e15561e14b48a8d (patch) | |
tree | eeaa77a0ef72438d893e997a8eb7a85bf1e0e0f8 /lib/libc/stdio | |
parent | 47b900534815085b63bb8a87071fc6e1626cec1f (diff) | |
download | src-7381dcc9eeb7da1b1ba103212e15561e14b48a8d.tar.gz src-7381dcc9eeb7da1b1ba103212e15561e14b48a8d.zip |
Notes
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/fgets.3 | 48 | ||||
-rw-r--r-- | lib/libc/stdio/gets.c | 5 | ||||
-rw-r--r-- | lib/libc/stdio/stdio.3 | 1 |
3 files changed, 10 insertions, 44 deletions
diff --git a/lib/libc/stdio/fgets.3 b/lib/libc/stdio/fgets.3 index ce334b7493b0..8b4bd388b7e3 100644 --- a/lib/libc/stdio/fgets.3 +++ b/lib/libc/stdio/fgets.3 @@ -32,12 +32,11 @@ .\" @(#)fgets.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd April 3, 2018 +.Dd September 1, 2019 .Dt FGETS 3 .Os .Sh NAME .Nm fgets , -.Nm gets , .Nm gets_s .Nd get a line from a stream .Sh LIBRARY @@ -48,8 +47,6 @@ .Fn fgets "char * restrict str" "int size" "FILE * restrict stream" .Ft char * .Fn gets_s "char *str" "rsize_t size" -.Ft char * -.Fn gets "char *str" .Sh DESCRIPTION The .Fn fgets @@ -81,23 +78,12 @@ except that the newline character (if any) is not stored in the string. The .Fn gets function -is equivalent to -.Fn fgets -with an infinite -.Fa size -and a -.Fa stream -of -.Dv stdin , -except that the newline character (if any) is not stored in the string. -It is the caller's responsibility to ensure that the input line, -if any, is sufficiently short to fit in the string. +was unsafe and is no longer available. .Sh RETURN VALUES Upon successful completion, -.Fn fgets , -.Fn gets_s , +.Fn fgets and -.Fn gets +.Fn gets_s return a pointer to the string. If end-of-file occurs before any characters are read, @@ -109,10 +95,9 @@ they return .Dv NULL and the buffer contents are indeterminate. The -.Fn fgets , -.Fn gets_s , +.Fn fgets and -.Fn gets +.Fn gets_s functions do not distinguish between end-of-file and error, and callers must use .Xr feof 3 @@ -139,8 +124,6 @@ or .Xr malloc 3 . .Pp The function -.Fn gets -and .Fn gets_s may also fail and set .Va errno @@ -153,11 +136,9 @@ for any of the errors specified for the routine .Xr fgetws 3 , .Xr getline 3 .Sh STANDARDS -The functions +The .Fn fgets -and -.Fn gets -conform to +function conforms to .St -isoC-99 . .Fn gets_s conforms to @@ -166,16 +147,3 @@ K.3.7.4.1. .Fn gets has been removed from .St -isoC-2011 . -.Sh SECURITY CONSIDERATIONS -The -.Fn gets -function cannot be used securely. -Because of its lack of bounds checking, -and the inability for the calling program -to reliably determine the length of the next incoming line, -the use of this function enables malicious users -to arbitrarily change a running program's functionality through -a buffer overflow attack. -It is strongly suggested that the -.Fn fgets -function be used in all cases. diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c index 1f360ac5ae61..c8822e3b8d86 100644 --- a/lib/libc/stdio/gets.c +++ b/lib/libc/stdio/gets.c @@ -45,10 +45,8 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" #include "local.h" -__warn_references(gets, "warning: this program uses gets(), which is unsafe."); - char * -gets(char *buf) +__gets_unsafe(char *buf) { int c; char *s, *ret; @@ -78,3 +76,4 @@ end: FUNLOCKFILE_CANCELSAFE(); return (ret); } +__sym_compat(gets, __gets_unsafe, FBSD_1.0); diff --git a/lib/libc/stdio/stdio.3 b/lib/libc/stdio/stdio.3 index 0ac315b957cb..7b3dd364c79a 100644 --- a/lib/libc/stdio/stdio.3 +++ b/lib/libc/stdio/stdio.3 @@ -279,7 +279,6 @@ library conforms to .It "getchar get next character or word from input stream" .It "getdelim get a line from a stream" .It "getline get a line from a stream" -.It "gets get a line from a stream" .It "getw get next character or word from input stream" .It "getwc get next wide character from input stream" .It "getwchar get next wide character from input stream" |