sed: Bounds check the file path used in the 'w' command.

Modified version of a diff from Sebastien Marie to prevent a crash found
with the afl fuzzer.

Obtained from:	OpenBSD (CVS Rev. 1.37)
MFC after:	1 week


git-svn-id: svn+ssh://svn.freebsd.org/base/head@275838 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f