Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: L A Walsh Newsgroups: gnu.bash.bug Subject: Re: bash sockets: printf \x0a does TCP fragmentation Date: Tue, 25 Sep 2018 05:15:02 -0700 Lines: 43 Approved: bug-bash@gnu.org Message-ID: References: <20180921231101307758654@bob.proulx.com> <714e1ba0-0052-2f2b-676d-778f2b7129c1@testssl.sh> <20180924130533.4ufaxypoelta6f7n@eeg.ccf.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1537877721 2889 208.118.235.17 (25 Sep 2018 12:15:21 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: <20180924130533.4ufaxypoelta6f7n@eeg.ccf.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14657 On 9/24/2018 6:05 AM, Greg Wooledge wrote: > On Sat, Sep 22, 2018 at 11:50:17AM +0200, dirk+bash@testssl.sh wrote: > >> On 9/22/18 7:30 AM, Bob Proulx wrote: >> >>> dirk+bash@testssl.sh wrote: >>> >>>> printf -- "$data" >&5 2>/dev/null >>>> >>> What happens if $data contains % format strings? What happens if the >>> format contains a sequence such as \c? This looks problematic. This >>> is not a safe programming proctice. >>> > > Looking ONLY at this one line, there is an obvious bug, which Bob has > pointed out. It should be > > printf %s "$data" >&5 2>/dev/null > ---- This brings to mind a consideration: As %s says to print a string of data (presumably not including a NUL byte), then what happens if "$data" is a paragraph of text with embedded newlines. In that case, it sounds like bash might break apart the single printf output into smaller packets rather than transmitting the entirety of "$data" in 1 write (presuming it is less than the maximum data size for a network packet). Also, if you want to flush the data out at the end, it seems "%s\n" would be required to force out the last line of text if it wasn't nl terminated. > That is utterly horrifying. > --- Hmmm....I didn't realize how sensitive some sensibilities were... :-)