Public bug reported:

Hot 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

** Affects: fortune-mod (Ubuntu)
     Importance: Undecided
         Status: New

** Patch added: "unstr.c: fix fread() return value test"
   
https://bugs.launchpad.net/bugs/1961954/+attachment/5562975/+files/unstr.patch

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1961954

Title:
  unstr (package fortune-mod) incorrectly reads data file

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/fortune-mod/+bug/1961954/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to