Bug 257510

Summary: unstr does not produce a valid fortune file
Product: Base System Reporter: Hubert Tournier <hubert.tournier>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Some People CC: emaste
Priority: ---    
Version: 13.0-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Patch file to correct the issue none

Description Hubert Tournier 2021-07-30 16:32:21 UTC
Created attachment 226804 [details]
Patch file to correct the issue

Overview:

While reimplementing the unstr command, I noticed that the original command, when displaying a fortune file in the order specified in its datafile, does not print the final '%' delimiter, which should end any fortune and any fortune file.

Steps to Reproduce:

# cd /usr/share/games/fortune
# tail -1 freebsd-tips
%
# strfile -Co freebsd-tips
"freebsd-tips.dat" created
There were 134 strings
Longest string: 746 bytes
Shortest string: 39 bytes
# unstr freebsd-tips | tail -4
%
sh (the default Bourne shell in FreeBSD) supports command-line editing.  Just
``set -o emacs'' or ``set -o vi'' to enable it. Use "<TAB>" key to complete
paths.

Build Date & Hardware: 
Additional Builds and Platforms:

Any BSD version since 4.4. This is a 28 years old bug!

Correction:

Here's a patchfile to correct this in /usr/src/usr.bin/fortune/unstr/unstr.c