Index: head/lib/libc/stdio/Makefile.inc =================================================================== --- head/lib/libc/stdio/Makefile.inc (revision 331935) +++ head/lib/libc/stdio/Makefile.inc (revision 331936) @@ -1,87 +1,88 @@ # @(#)Makefile.inc 8.3 (Berkeley) 4/17/94 # $FreeBSD$ # stdio sources .PATH: ${LIBC_SRCTOP}/stdio SRCS+= _flock_stub.c asprintf.c clrerr.c dprintf.c \ fclose.c fcloseall.c fdopen.c \ feof.c ferror.c fflush.c fgetc.c fgetln.c fgetpos.c fgets.c fgetwc.c \ fgetwln.c fgetws.c \ fileno.c findfp.c flags.c fmemopen.c fopen.c \ fopencookie.c fprintf.c fpurge.c \ fputc.c fputs.c \ fputwc.c fputws.c fread.c freopen.c fscanf.c fseek.c fsetpos.c \ ftell.c funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwscanf.c \ fwrite.c getc.c getchar.c getdelim.c getline.c \ - gets.c getw.c getwc.c getwchar.c makebuf.c mktemp.c \ + gets.c gets_s.c getw.c getwc.c getwchar.c makebuf.c mktemp.c \ open_memstream.c open_wmemstream.c \ perror.c printf.c printf-pos.c putc.c putchar.c \ puts.c putw.c putwc.c putwchar.c \ refill.c remove.c rewind.c rget.c scanf.c setbuf.c setbuffer.c \ setvbuf.c snprintf.c sprintf.c sscanf.c stdio.c swprintf.c swscanf.c \ tempnam.c tmpfile.c \ tmpnam.c ungetc.c ungetwc.c vasprintf.c vdprintf.c vfprintf.c \ vfscanf.c \ vfwprintf.c vfwscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c \ vsscanf.c \ vswprintf.c vswscanf.c vwprintf.c vwscanf.c wbuf.c wprintf.c wscanf.c \ wsetup.c SRCS+= xprintf.c xprintf_float.c xprintf_int.c xprintf_str.c SRCS+= xprintf_errno.c xprintf_hexdump.c xprintf_quote.c SRCS+= xprintf_time.c xprintf_vis.c SYM_MAPS+= ${LIBC_SRCTOP}/stdio/Symbol.map MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \ flockfile.3 \ fopen.3 fopencookie.3 fputs.3 \ fputws.3 fread.3 fseek.3 funopen.3 fwide.3 getc.3 \ getline.3 getwc.3 mktemp.3 open_memstream.3 \ printf.3 printf_l.3 putc.3 putwc.3 remove.3 scanf.3 scanf_l.3 setbuf.3 \ stdio.3 tmpnam.3 \ ungetc.3 ungetwc.3 wprintf.3 wscanf.3 MLINKS+=fclose.3 fcloseall.3 fclose.3 fdclose.3 MLINKS+=ferror.3 ferror_unlocked.3 \ ferror.3 clearerr.3 ferror.3 clearerr_unlocked.3 \ ferror.3 feof.3 ferror.3 feof_unlocked.3 \ ferror.3 fileno.3 ferror.3 fileno_unlocked.3 MLINKS+=fflush.3 fpurge.3 MLINKS+=fgets.3 gets.3 +MLINKS+=fgets.3 gets_s.3 MLINKS+=flockfile.3 ftrylockfile.3 flockfile.3 funlockfile.3 MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3 fopen.3 fmemopen.3 MLINKS+=fputs.3 puts.3 MLINKS+=fread.3 fwrite.3 MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \ fseek.3 ftello.3 fseek.3 rewind.3 MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3 MLINKS+=getc.3 fgetc.3 getc.3 getc_unlocked.3 getc.3 getchar.3 \ getc.3 getchar_unlocked.3 getc.3 getw.3 MLINKS+=getline.3 getdelim.3 MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3 MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3 \ mktemp.3 mkostemp.3 mktemp.3 mkostemps.3 MLINKS+=open_memstream.3 open_wmemstream.3 MLINKS+=printf.3 asprintf.3 printf.3 dprintf.3 printf.3 fprintf.3 \ printf.3 snprintf.3 printf.3 sprintf.3 \ printf.3 vasprintf.3 printf.3 vdprintf.3 \ printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \ printf.3 vsprintf.3 MLINKS+=printf_l.3 asprintf_l.3 printf_l.3 fprintf_l.3 printf_l.3 snprintf_l.3 \ printf_l.3 sprintf_l.3 printf_l.3 vasprintf_l.3 printf_l.3 vfprintf_l.3 \ printf_l.3 vprintf_l.3 printf_l.3 vsnprintf_l.3 printf_l.3 vsprintf_l.3 MLINKS+=putc.3 fputc.3 putc.3 putc_unlocked.3 putc.3 putchar.3 \ putc.3 putchar_unlocked.3 putc.3 putw.3 MLINKS+=putwc.3 fputwc.3 putwc.3 putwchar.3 MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \ scanf.3 vsscanf.3 MLINKS+=scanf_l.3 fscanf_l.3 scanf_l.3 sscanf_l.3 scanf_l.3 vfscanf_l.3 \ scanf_l.3 vscanf_l.3 scanf_l.3 vsscanf_l.3 MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3 MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3 MLINKS+=wprintf.3 fwprintf.3 wprintf.3 swprintf.3 \ wprintf.3 vwprintf.3 wprintf.3 vfwprintf.3 wprintf.3 vswprintf.3 MLINKS+=wscanf.3 fwscanf.3 wscanf.3 swscanf.3 wscanf.3 vwscanf.3 \ wscanf.3 vswscanf.3 wscanf.3 vfwscanf.3 Index: head/lib/libc/stdio/Symbol.map =================================================================== --- head/lib/libc/stdio/Symbol.map (revision 331935) +++ head/lib/libc/stdio/Symbol.map (revision 331936) @@ -1,208 +1,209 @@ /* * $FreeBSD$ */ FBSD_1.0 { flockfile; ftrylockfile; funlockfile; asprintf; clearerr; fclose; fcloseall; fdopen; feof; ferror; fflush; fgetc; fgetln; fgetpos; fgets; fgetwc; fgetwln; fgetws; fileno; __sF; __stdinp; __stdoutp; __stderrp; f_prealloc; /* deprecated??? */ fopen; fprintf; fpurge; fputc; fputs; fputwc; fputws; fread; freopen; fscanf; fseek; fseeko; fsetpos; ftell; ftello; funopen; fwide; fwprintf; fwrite; fwscanf; getc; getchar; gets; getw; getwc; getwchar; mkstemps; mkstemp; mkdtemp; mktemp; perror; printf; putc; putchar; puts; putw; putwc; putwchar; remove; rewind; __srget; scanf; setbuf; setbuffer; setlinebuf; setvbuf; snprintf; sprintf; sscanf; swprintf; swscanf; tempnam; tmpfile; tmpnam; ungetc; ungetwc; getchar_unlocked; getc_unlocked; putchar_unlocked; putc_unlocked; feof_unlocked; ferror_unlocked; clearerr_unlocked; fileno_unlocked; vasprintf; vfprintf; vfscanf; vfwprintf; vfwscanf; vprintf; vscanf; vsnprintf; vsprintf; vsscanf; vswprintf; vswscanf; vwprintf; vwscanf; __swbuf; wprintf; wscanf; }; FBSD_1.1 { dprintf; getdelim; getline; vdprintf; }; FBSD_1.3 { asprintf_l; fprintf_l; fwprintf_l; printf_l; snprintf_l; sprintf_l; swprintf_l; vasprintf_l; vfprintf_l; vfwprintf_l; vprintf_l; vsnprintf_l; vsprintf_l; vswprintf_l; vwprintf_l; wprintf_l; fgetwc_l; fputwc_l; ungetwc_l; vfwscanf_l; vswscanf_l; fscanf_l; fwscanf_l; scanf_l; sscanf_l; swscanf_l; vfscanf_l; vscanf_l; vsscanf_l; vwscanf_l; wscanf_l; fgetws_l; fputws_l; getwc_l; getwchar_l; putwc_l; putwchar_l; fmemopen; open_memstream; open_wmemstream; mkostemp; mkostemps; }; FBSD_1.4 { fdclose; fopencookie; + gets_s; }; FBSDprivate_1.0 { _flockfile; _flockfile_debug_stub; _flockfile_debug; _ftrylockfile; _funlockfile; __vfscanf; /* * xprintf support */ __use_xprintf; __lowercase_hex; __uppercase_hex; __printf_flush; __printf_puts; __printf_pad; __printf_out; __xvprintf; register_printf_function; register_printf_render; register_printf_render_std; __printf_arginfo_float; __printf_render_float; __printf_arginfo_hexdump; __printf_render_hexdump; __printf_arginfo_int; __printf_render_int; __printf_arginfo_ptr; __printf_render_ptr; __printf_arginfo_str; __printf_render_str; __printf_arginfo_chr; __printf_render_chr; __printf_arginfo_time; __printf_render_time; __printf_arginfo_vis; __printf_render_vis; }; Index: head/lib/libc/stdio/fgets.3 =================================================================== --- head/lib/libc/stdio/fgets.3 (revision 331935) +++ head/lib/libc/stdio/fgets.3 (revision 331936) @@ -1,156 +1,178 @@ .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Chris Torek and the American National Standards Committee X3, .\" on Information Processing Systems. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)fgets.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" .Dd May 5, 2012 .Dt FGETS 3 .Os .Sh NAME .Nm fgets , .Nm gets .Nd get a line from a stream .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdio.h .Ft char * .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 function reads at most one less than the number of characters specified by .Fa size from the given .Fa stream and stores them in the string .Fa str . Reading stops when a newline character is found, at end-of-file or error. The newline, if any, is retained. If any characters are read and there is no error, a .Ql \e0 character is appended to end the string. .Pp The +.Fn gets_s +function +is equivalent to +.Fn fgets +with a +.Fa stream +of +.Dv stdin , +except that the newline character (if any) is not stored in the string. +.Pp +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. .Sh RETURN VALUES Upon successful completion, -.Fn fgets +.Fn fgets , +.Fn gets_s , and .Fn gets return a pointer to the string. If end-of-file occurs before any characters are read, they return .Dv NULL and the buffer contents remain unchanged. If an error occurs, they return .Dv NULL and the buffer contents are indeterminate. The -.Fn fgets +.Fn fgets , +.Fn gets_s , and .Fn gets functions do not distinguish between end-of-file and error, and callers must use .Xr feof 3 and .Xr ferror 3 to determine which occurred. .Sh ERRORS .Bl -tag -width Er .It Bq Er EBADF The given .Fa stream is not a readable stream. .El .Pp The function .Fn fgets may also fail and set .Va errno for any of the errors specified for the routines .Xr fflush 3 , .Xr fstat 2 , .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 , .Xr fgetln 3 , .Xr fgetws 3 , .Xr getline 3 .Sh STANDARDS The functions .Fn fgets and .Fn gets conform to .St -isoC-99 . +.Fn gets_s +conforms to +.St -isoC-2011 +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. Index: head/lib/libc/stdio/gets_s.c =================================================================== --- head/lib/libc/stdio/gets_s.c (nonexistent) +++ head/lib/libc/stdio/gets_s.c (revision 331936) @@ -0,0 +1,102 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * Copyright (c) 2017, 2018 + * Cyril S. E. Schubert. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +static inline char * +_gets_s(char *buf, rsize_t n) +{ + int c; + char *s; + + ORIENT(stdin, -1); + for (s = buf, n--; (c = __sgetc(stdin)) != '\n' && n > 0 ; n--) { + if (c == EOF) { + if (s == buf) { + return (NULL); + } else + break; + } else + *s++ = c; + } + + /* + * If end of buffer reached, discard until \n or eof. + * Then throw an error. + */ + if (n == 0) { + /* discard */ + while ((c = __sgetc(stdin)) != '\n' && c != EOF); + /* throw the error after lock released prior to exit */ + __throw_constraint_handler_s("gets_s : end of buffer", E2BIG); + return (NULL); + } + *s = 0; + return (buf); +} + +/* ISO/IEC 9899:2011 K.3.7.4.1 */ +char * +gets_s(char *buf, rsize_t n) +{ + char *ret; + if (buf == NULL) { + __throw_constraint_handler_s("gets_s : str is NULL", EINVAL); + return(NULL); + } else if (n > RSIZE_MAX) { + __throw_constraint_handler_s("gets_s : n > RSIZE_MAX", + EINVAL); + return(NULL); + } else if (n == 0) { + __throw_constraint_handler_s("gets_s : n == 0", EINVAL); + return(NULL); + } + + FLOCKFILE_CANCELSAFE(stdin); + ret = _gets_s(buf, n); + FUNLOCKFILE_CANCELSAFE(); + return (ret); +} Property changes on: head/lib/libc/stdio/gets_s.c ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: head/lib/libc/tests/stdio/Makefile =================================================================== --- head/lib/libc/tests/stdio/Makefile (revision 331935) +++ head/lib/libc/tests/stdio/Makefile (revision 331936) @@ -1,43 +1,44 @@ # $FreeBSD$ .include ATF_TESTS_C+= fdopen_test ATF_TESTS_C+= fmemopen2_test ATF_TESTS_C+= fopen2_test ATF_TESTS_C+= freopen_test ATF_TESTS_C+= getdelim_test +ATF_TESTS_C+= gets_s_test ATF_TESTS_C+= mkostemp_test ATF_TESTS_C+= open_memstream2_test ATF_TESTS_C+= open_wmemstream_test ATF_TESTS_C+= perror_test ATF_TESTS_C+= print_positional_test ATF_TESTS_C+= printbasic_test ATF_TESTS_C+= printfloat_test ATF_TESTS_C+= scanfloat_test SRCS.fopen2_test= fopen_test.c NETBSD_ATF_TESTS_C= clearerr_test NETBSD_ATF_TESTS_C+= fflush_test NETBSD_ATF_TESTS_C+= fmemopen_test NETBSD_ATF_TESTS_C+= fopen_test NETBSD_ATF_TESTS_C+= fputc_test NETBSD_ATF_TESTS_C+= mktemp_test NETBSD_ATF_TESTS_C+= open_memstream_test NETBSD_ATF_TESTS_C+= popen_test NETBSD_ATF_TESTS_C+= printf_test NETBSD_ATF_TESTS_C+= scanf_test LIBADD.printfloat_test+= m LIBADD.scanfloat_test+= m .if ${COMPILER_TYPE} == "gcc" # 90: use of assignment suppression and length modifier together in scanf format PROG_OVERRIDE_VARS+= NO_WFORMAT NO_WFORMAT.scanfloat_test= .endif .include "../Makefile.netbsd-tests" .include Index: head/lib/libc/tests/stdio/gets_s_test.c =================================================================== --- head/lib/libc/tests/stdio/gets_s_test.c (nonexistent) +++ head/lib/libc/tests/stdio/gets_s_test.c (revision 331936) @@ -0,0 +1,145 @@ +/*- + * Copyright (c) 2017 Cyril S. E. Schubert. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include + +static errno_t error_code; +static const char * message; + +void +h(const char * msg, void * ptr __unused, errno_t error) +{ + error_code = error; + message = msg; +} + +/* null ptr */ +ATF_TC_WITHOUT_HEAD(null_ptr); +ATF_TC_BODY(null_ptr, tc) +{ + ATF_CHECK_MSG(gets_s(NULL, 1) == NULL, + "gets_s() failed to handle NULL pointer"); +} + +/* normal */ +ATF_TC_WITHOUT_HEAD(normal); +ATF_TC_BODY(normal, tc) +{ + pid_t kidpid; + int fd[2]; + int nfd; + + // close(STDIN_FILENO); + // close(STDOUT_FILENO); + pipe(fd); + + if ((kidpid = fork()) == 0) { + char b[10]; + + close(fd[1]); + nfd = dup2(fd[0], 0); + close(fd[0]); + stdin = fdopen(nfd, "r"); + ATF_CHECK_MSG(gets_s(b, sizeof(b)) == 0, "gets_s() normal failed"); + fclose(stdin); + } else { + int stat; + + close(fd[0]); + stdout = fdopen(fd[1], "w"); + puts("a sting"); + fclose(stdout); + (void) waitpid(kidpid, &stat, WEXITED); + } +} + +/* n > rmax */ +ATF_TC_WITHOUT_HEAD(n_gt_rmax); +ATF_TC_BODY(n_gt_rmax, tc) +{ + char b; + + ATF_CHECK_MSG(gets_s(&b, RSIZE_MAX + 1) == NULL, + "gets_s() n > RSIZE_MAX"); +} + +/* n == 0 */ +ATF_TC_WITHOUT_HEAD(n_eq_zero); +ATF_TC_BODY(n_eq_zero, tc) +{ + char b; + + ATF_CHECK_MSG(gets_s(&b, 0) == NULL, "gets_s() n is zero"); +} + +/* n > rmax, handler */ +ATF_TC_WITHOUT_HEAD(n_gt_rmax_handler); +ATF_TC_BODY(n_gt_rmax_handler, tc) +{ + char b; + + error_code = 0; + message = NULL; + set_constraint_handler_s(h); + ATF_CHECK_MSG(gets_s(&b, RSIZE_MAX + 1) == NULL, "gets_s() n > RSIZE_MAX"); + ATF_CHECK_MSG(error_code > 0, "gets_s() error code is %d", error_code); + ATF_CHECK_MSG(strcmp(message, "gets_s : n > RSIZE_MAX") == 0, "gets_s(): incorrect error message"); +} + +/* n == 0, handler */ +ATF_TC_WITHOUT_HEAD(n_eq_zero_handler); +ATF_TC_BODY(n_eq_zero_handler, tc) +{ + char b; + + error_code = 0; + message = NULL; + set_constraint_handler_s(h); + ATF_CHECK(gets_s(&b, 0) == NULL); + ATF_CHECK_MSG(error_code > 0, "gets_s() error code is %d", error_code); + ATF_CHECK_MSG(strcmp(message, "gets_s : n == 0") == 0, "gets_s(): incorrect error message"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, null_ptr); + ATF_TP_ADD_TC(tp, normal); + ATF_TP_ADD_TC(tp, n_gt_rmax); + ATF_TP_ADD_TC(tp, n_eq_zero); + ATF_TP_ADD_TC(tp, n_gt_rmax_handler); + ATF_TP_ADD_TC(tp, n_eq_zero_handler); + return (atf_no_error()); +} Property changes on: head/lib/libc/tests/stdio/gets_s_test.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property