Closed Bug 17486 Opened 25 years ago Closed 25 years ago

Incorrect & operator precedence in _PR_UnixSendFile

Categories

(NSPR :: NSPR, defect, P3)

Sun
Solaris
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: wtc, Assigned: srinivas)

Details

Attachments

(2 files)

In unix.c, _PR_UnixSendFile, we have:
================
    pagesize = PR_GetPageSize();
    /*
     * If the file is large, mmap and send the file in chunks so as
     * to not consume too much virtual address space
     */
    if ((sfd->file_offset == 0) ||
            (sfd->file_offset & (pagesize - 1) == 0)) {
        /*
         * case 1: page-aligned file offset
         */
================

Because the == operator has a higher precedence than
the & operator, the expression (sfd->file_offset & (pagesize - 1) == 0)
gets evaluated as follows:
===>    (sfd->file_offset & ((pagesize - 1) == 0))
===>    (sfd->file_offset & 0)    # assuming (pagesize - 1) is not 0
===>    0

The if statement reduces to:
    if (sfd->file_offset == 0) {

So we fail to detect a nonzero file offset that is page
aligned.  This results in the assertion failure
"addr_offset > 0" at mozilla/nsprpub/pr/src/md/unix.c (rev. 3.29),
line 3005.
Assignee: wtc → srinivas
The fix is checked in.
/cvsroot/mozilla/nsprpub/pr/src/md/unix/unix.c, revision 3.30.

/m/src/ns/nspr20/pr/src/md/unix/unix.c, revision 2.68

Srinivas, could you look into how to add a new case (where
offset is a multiple of page size) to socket.c?  Thanks.
This fix is checked into NSPR20_RELEASE_3_5_BRANCH (in the
internal /m/src repository), so it will be in the NSPR
3.5.1 patch release.
/m/src/ns/nspr20/pr/src/md/unix/unix.c, revision 2.65.2.1
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
Added a new test case for PR_SendFile in socket.c, for a non-zero page-aligned
file offset.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: