Page MenuHomeFreeBSD

D12298.id33726.diff
No OneTemporary

D12298.id33726.diff

Index: contrib/libc++/include/cstdio
===================================================================
--- contrib/libc++/include/cstdio
+++ contrib/libc++/include/cstdio
@@ -74,7 +74,6 @@
int fputs(const char* restrict s, FILE* restrict stream);
int getc(FILE* stream);
int getchar(void);
-char* gets(char* s); // removed in C++14
int putc(int c, FILE* stream);
int putchar(int c);
int puts(const char* s);
@@ -153,9 +152,6 @@
#ifndef _LIBCPP_HAS_NO_STDIN
using ::getchar;
-#if _LIBCPP_STD_VER <= 11 && !defined(_LIBCPP_MSVCRT)
-using ::gets;
-#endif
using ::scanf;
using ::vscanf;
#endif
Index: contrib/netbsd-tests/lib/libc/ssp/h_gets.c
===================================================================
--- contrib/netbsd-tests/lib/libc/ssp/h_gets.c
+++ contrib/netbsd-tests/lib/libc/ssp/h_gets.c
@@ -33,6 +33,15 @@
#include <stdio.h>
+#ifdef __FreeBSD__
+char *unsafe_gets(char *);
+char *gets(char *buf)
+{
+ return unsafe_gets(buf);
+}
+__sym_compat(gets, unsafe_gets, FBSD_1.0);
+#endif
+
int
main(int argc, char *argv[])
{
Index: include/stdio.h
===================================================================
--- include/stdio.h
+++ include/stdio.h
@@ -262,7 +262,6 @@
size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
int getc(FILE *);
int getchar(void);
-char *gets(char *);
void perror(const char *);
int printf(const char * __restrict, ...);
int putc(int, FILE *);
Index: lib/libc/stdio/Symbol.map
===================================================================
--- lib/libc/stdio/Symbol.map
+++ lib/libc/stdio/Symbol.map
@@ -49,7 +49,6 @@
fwscanf;
getc;
getchar;
- gets;
getw;
getwc;
getwchar;
Index: lib/libc/stdio/fgets.3
===================================================================
--- lib/libc/stdio/fgets.3
+++ lib/libc/stdio/fgets.3
@@ -36,8 +36,7 @@
.Dt FGETS 3
.Os
.Sh NAME
-.Nm fgets ,
-.Nm gets
+.Nm fgets
.Nd get a line from a stream
.Sh LIBRARY
.Lb libc
@@ -45,8 +44,6 @@
.In stdio.h
.Ft char *
.Fn fgets "char * restrict str" "int size" "FILE * restrict stream"
-.Ft char *
-.Fn gets "char *str"
.Sh DESCRIPTION
The
.Fn fgets
@@ -67,38 +64,24 @@
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
-and
-.Fn gets
-return
+returns
a pointer to the string.
If end-of-file occurs before any characters are read,
-they return
+it returns
.Dv NULL
and the buffer contents remain unchanged.
If an error occurs,
-they return
+it returns
.Dv NULL
and the buffer contents are indeterminate.
The
.Fn fgets
-and
-.Fn gets
-functions
-do not distinguish between end-of-file and error, and callers must use
+function
+does not distinguish between end-of-file and error, and callers must use
.Xr feof 3
and
.Xr ferror 3
@@ -121,13 +104,6 @@
.Xr read 2 ,
or
.Xr malloc 3 .
-.Pp
-The function
-.Fn gets
-may also fail and set
-.Va errno
-for any of the errors specified for the routine
-.Xr getchar 3 .
.Sh SEE ALSO
.Xr feof 3 ,
.Xr ferror 3 ,
@@ -135,22 +111,7 @@
.Xr fgetws 3 ,
.Xr getline 3
.Sh STANDARDS
-The functions
-.Fn fgets
-and
-.Fn gets
-conform to
-.St -isoC-99 .
-.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.
+function conforms to
+.St -isoC-99 .
Index: lib/libc/stdio/gets.c
===================================================================
--- lib/libc/stdio/gets.c
+++ lib/libc/stdio/gets.c
@@ -44,10 +44,8 @@
#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;
@@ -77,3 +75,4 @@
FUNLOCKFILE_CANCELSAFE();
return (ret);
}
+__sym_compat(gets, __gets_unsafe, FBSD_1.0);
Index: lib/libc/stdio/stdio.3
===================================================================
--- lib/libc/stdio/stdio.3
+++ lib/libc/stdio/stdio.3
@@ -279,7 +279,6 @@
.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"

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 19, 12:32 AM (17 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31739783
Default Alt Text
D12298.id33726.diff (4 KB)

Event Timeline