unstr (package fortune-mod) incorrectly reads data file

Bug #1961954 reported by braoult
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
fortune-mod (Ubuntu)
New
Undecided
Unassigned

Bug Description

How to reproduce :

$ strfile fort
"fort.dat" created
There were 36 strings
Longest string: 201 bytes
Shortest string: 25 bytes

$ ls -l fort*
-rw-rw-r-- 1 br br 3383 Feb 23 10:31 fort
-rw-rw-r-- 1 br br 172 Feb 23 10:31 fort.dat

$ unstr fort
Input file: fort
unstr: data file corrupted

The bug is line 234 of unstr.c (source file: https://sources.debian.org/src/fortune-mod/1%3A1.99.1-7/util/unstr.c/).

The current checked_fread() macro compares fread() return value with the number of bytes to read :
#define checked_fread(item, size) \
    if (fread(item, size, 1, Dataf) != size) \
      { \
        fprintf(stderr, "unstr: data file corrupted\n"); \
        exit(1); \
      }

It should instead compare fread() return value with the number of items to read, which is 1 :
#define checked_fread(item, size) \
    if (fread(item, size, 1, Dataf) != 1) \
      { \
        fprintf(stderr, "unstr: data file corrupted\n"); \
        exit(1); \
      }

After changing the code, running the same commands give :
$ strfile fort
"fort.dat" created
There were 36 strings
Longest string: 201 bytes
Shortest string: 25 bytes

$ ls -l fort*
-rw-rw-r-- 1 br br 3383 Feb 23 10:31 fort
-rw-rw-r-- 1 br br 172 Feb 23 10:38 fort.dat

$ ./unstr fort
Input file: fort
nothing to do -- table in file order

Tags: patch
Revision history for this message
braoult (braoult) wrote :
braoult (braoult)
description: updated
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "unstr.c: fix fread() return value test" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.