Date: Fri, 18 Dec 2015 17:44:31 -0500 From: Pedro Giffuni <pfg@FreeBSD.org> To: Warner Losh <imp@bsdimp.com> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r292454 - head/bin/ed Message-ID: <DCA75AAB-5752-44E4-90B9-FC33404EA350@FreeBSD.org> In-Reply-To: <44E9BE06-1883-4AF8-816D-D699CF733EEB@bsdimp.com> References: <201512182158.tBILwhRB040583@repo.freebsd.org> <44E9BE06-1883-4AF8-816D-D699CF733EEB@bsdimp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi Warner; > Il giorno 18/dic/2015, alle ore 17:01, Warner Losh <imp@bsdimp.com> ha = scritto: >=20 > Isn=E2=80=99t strlcpy() the more appropriate interface? strncpy = doesn=E2=80=99t guarantee NUL termination. >=20 Maybe, but we were using strcpy() which doesn=E2=80=99t guarantee NULL = termination either and things have been working. I also thought that portability may be = specially important for the stuff in bin/. Pedro. > Warner >=20 >> On Dec 18, 2015, at 2:58 PM, Pedro F. Giffuni <pfg@FreeBSD.org> = wrote: >>=20 >> Author: pfg >> Date: Fri Dec 18 21:58:42 2015 >> New Revision: 292454 >> URL: https://svnweb.freebsd.org/changeset/base/292454 >>=20 >> Log: >> ed(1): Prevent possible string overflows >>=20 >> CID: 1007252 >> MFC after: 2 weeks >>=20 >> Modified: >> head/bin/ed/main.c >>=20 >> Modified: head/bin/ed/main.c >> = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D >> --- head/bin/ed/main.c Fri Dec 18 21:34:28 2015 = (r292453) >> +++ head/bin/ed/main.c Fri Dec 18 21:58:42 2015 = (r292454) >> @@ -505,7 +505,8 @@ exec_command(void) >> return ERR; >> else if (open_sbuf() < 0) >> return FATAL; >> - if (*fnp && *fnp !=3D '!') strcpy(old_filename, fnp); >> + if (*fnp && *fnp !=3D '!') >> + strncpy(old_filename, fnp, PATH_MAX); >> #ifdef BACKWARDS >> if (*fnp =3D=3D '\0' && *old_filename =3D=3D '\0') { >> errmsg =3D "no current filename"; >> @@ -532,7 +533,8 @@ exec_command(void) >> return ERR; >> } >> GET_COMMAND_SUFFIX(); >> - if (*fnp) strcpy(old_filename, fnp); >> + if (*fnp) >> + strncpy(old_filename, fnp, PATH_MAX); >> printf("%s\n", strip_escapes(old_filename)); >> break; >> case 'g': >> @@ -663,7 +665,7 @@ exec_command(void) >> GET_COMMAND_SUFFIX(); >> if (!isglobal) clear_undo_stack(); >> if (*old_filename =3D=3D '\0' && *fnp !=3D '!') >> - strcpy(old_filename, fnp); >> + strncpy(old_filename, fnp, PATH_MAX); >> #ifdef BACKWARDS >> if (*fnp =3D=3D '\0' && *old_filename =3D=3D '\0') { >> errmsg =3D "no current filename"; >> @@ -797,7 +799,7 @@ exec_command(void) >> return ERR; >> GET_COMMAND_SUFFIX(); >> if (*old_filename =3D=3D '\0' && *fnp !=3D '!') >> - strcpy(old_filename, fnp); >> + strncpy(old_filename, fnp, PATH_MAX); >> #ifdef BACKWARDS >> if (*fnp =3D=3D '\0' && *old_filename =3D=3D '\0') { >> errmsg =3D "no current filename"; >>=20 >=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DCA75AAB-5752-44E4-90B9-FC33404EA350>