NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/57141: Bug in swab()



>Number:         57141
>Category:       lib
>Synopsis:       Bug in swab()
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 28 13:30:00 +0000 2022
>Originator:     Jai Arora, Abhishek Rose, Shubhani Gupta, Sorav Bansal
>Release:        `trunk` branch of the src repository
>Organization:
CompilerAI Research Group, IIT Delhi
>Environment:
5.4.0-135-generic #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
>Description:
The bug is in the C implementation of swab as located in lib/libc/string/ directory of the NetBSD repository. The source code was downloaded from the official git repository(https://github.com/NetBSD/src, top level commit on the `trunk` branch).

Linux[0] manpage for swab() specifies that the function copies n bytes from the array pointed to by from to the array pointed to by to, exchanging adjacent even and odd bytes. NetBSD's implementation incorrectly rounds n to a multiple of 8, leading one less memory swap than expected.

0: https://man7.org/linux/man-pages/man3/swab.3.html
>How-To-Repeat:
An example input is:
  const char src[] = {90, 91, 1, 2};
  char dst[4] = {'A', 'B', 'C', 'D'};
  swab(src, dst, 4);
  if (dst[0] != 91 || dst[1] != 90 || dst[2] != 2 || dst[3] != 1) {
    printf("BUG!\n");
  }

The file that demonstrates the bug can be found here: https://github.com/compilerai/bug-reports/blob/master/bug_files/netbsd_swab_bug.c
>Fix:
A patch that applies the necessary fix is available here: https://github.com/compilerai/bug-reports/blob/master/patch/netbsd_swab.patch



Home | Main Index | Thread Index | Old Index