Bug 252614 - /usr/bin/diff : BUG: Incorrectly displaying files as duplicates (includes fix)
Summary: /usr/bin/diff : BUG: Incorrectly displaying files as duplicates (includes fix)
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-12 16:53 UTC by Jamie Landeg-Jones
Modified: 2021-01-15 23:44 UTC (History)
3 users (show)

See Also:


Attachments
patch to fix diff bug (1.52 KB, patch)
2021-01-12 16:53 UTC, Jamie Landeg-Jones
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jamie Landeg-Jones 2021-01-12 16:53:19 UTC
Created attachment 221499 [details]
patch to fix diff bug

When diff hits certain access errors, function diffreg() shows the error message, and then returns to the calling function, which calls print_status() with the return value.

However, in these cases, the return value isn't changed from the initial default value of D_SAME.

Normally, print_status() with a value of D_SAME does nothing, so this works out ok, however, if the "-s" flag is set, a message is displayed showing identicality:

case D_SAME:
                if (sflag)
                        printf("Files %s%s and %s%s are identical\n",                                                                                                       path1, entry, path2, entry);
                break;

This then produces such results as:

% diff  -s /COPYRIGHT /var/run/rpcbind.sock
diff: /var/run/rpcbind.sock: Operation not supported
Files /COPYRIGHT and /var/run/rpcbind.sock are identical

% diff  -s /COPYRIGHT /etc/master.passwd
diff: /etc/master.passwd: Permission denied
Files /COPYRIGHT and /etc/master.passwd are identical

A quick fix would be to alter the above line:

   if (sflag)

to

   if (sflag && status & 2)

A less hacky fix is attached as a patch. It creates a D_ERROR status which is returned in such cases, and print_status() then deals with that status seperately from D_SAME.
Comment 1 John Baldwin freebsd_committer freebsd_triage 2021-01-15 23:44:11 UTC
Adding bapt@ and kevans@ in case they want to look as they've hacked on diff(1) recently.