Closed Bug 1363336 Opened 3 years ago Closed 3 years ago

[Static Analysis][Dereference before null check] In function nsSocketTransport::InitiateSocket

Categories

(Core :: Networking, enhancement)

enhancement
Not set

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: andi, Assigned: andi)

References

(Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: CID 1405958)

Attachments

(1 file)

The Static Analysis tool Coverity detected that |fd| can produce a null pointer dereference since it's already dereferenced before being null checked:

[1] Null check
>>    if (fd && mFastOpenCallback &&
>>        mFastOpenCallback->FastOpenEnabled()) {

[2] Dereference
>>   status = PR_SetSocketOption(fd, &opt);

[3] Allocation
>>    PRFileDesc *fd;
>>    bool proxyTransparent;
>>    bool usingSSL;
>>
>>    rv = BuildSocket(fd, proxyTransparent, usingSSL);
>>    if (NS_FAILED(rv)) {
>>        SOCKET_LOG(("  BuildSocket failed [rv=%" PRIx32 "]\n", static_cast<uint32_t>(rv)));
>>        return rv;
>>    }

Looking at [3] the null check is useless and causes a false-positive, we should eliminate it.
Comment on attachment 8865827 [details]
Bug 1363336 - eliminate useless null-check in for |fd|.

https://reviewboard.mozilla.org/r/137430/#review140574

Please remove whitespace-only changes from the patch.
The review should probably be done by :dragana since she wrote this code.
Thanks!
Attachment #8865827 - Flags: review?(valentin.gosu) → review-
Comment on attachment 8865827 [details]
Bug 1363336 - eliminate useless null-check in for |fd|.

https://reviewboard.mozilla.org/r/137430/#review140584
Attachment #8865827 - Flags: review?(dd.mozilla) → review+
Pushed by bpostelnicu@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4bbf624389f1
eliminate useless null-check in for |fd|. r=dragana
https://hg.mozilla.org/mozilla-central/rev/4bbf624389f1
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.