Activity log for bug #1961954

Date Who What changed Old value New value Message
2022-02-23 09:47:31 braoult bug added bug
2022-02-23 09:47:31 braoult attachment added unstr.c: fix fread() return value test https://bugs.launchpad.net/bugs/1961954/+attachment/5562975/+files/unstr.patch
2022-02-23 10:28:51 braoult description 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 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
2022-02-23 12:32:07 Ubuntu Foundations Team Bug Bot tags patch
2022-02-23 12:32:15 Ubuntu Foundations Team Bug Bot bug added subscriber Ubuntu Review Team