WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
173690
[TestWebKitAPI] Fix misuse of -[NSData dataWithBytesNoCopy:length:] with global variables
https://bugs.webkit.org/show_bug.cgi?id=173690
Summary
[TestWebKitAPI] Fix misuse of -[NSData dataWithBytesNoCopy:length:] with glob...
David Kilzer (:ddkilzer)
Reported
2017-06-21 20:12:00 PDT
Per documentation, -[NSData dataWithBytesNoCopy:length:] takes ownership of malloc()-ed memory, then frees it when it's released. These tests were passing global variables into the method, which is not malloc()-ed memory, which violations the API contract. The fix is to switch to using -[NSData dataWithBytes:length:] so that the global C strings are copied into malloc()-ed memory. Caught by the clang static analyzer.
Attachments
Patch v1
(4.70 KB, patch)
2017-06-21 20:13 PDT
,
David Kilzer (:ddkilzer)
no flags
Details
Formatted Diff
Diff
Patch v2
(4.82 KB, patch)
2017-06-21 22:49 PDT
,
David Kilzer (:ddkilzer)
no flags
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
David Kilzer (:ddkilzer)
Comment 1
2017-06-21 20:13:09 PDT
Created
attachment 313579
[details]
Patch v1
Chris Dumez
Comment 2
2017-06-21 21:17:04 PDT
Comment on
attachment 313579
[details]
Patch v1 View in context:
https://bugs.webkit.org/attachment.cgi?id=313579&action=review
> Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IconLoadingDelegate.mm:-145 > - RetainPtr<IconLoadingSchemeHandler> handler = adoptNS([[IconLoadingSchemeHandler alloc] initWithData:[NSData dataWithBytesNoCopy:(void*)mainBytes length:sizeof(mainBytes)]]);
Why not keep the existing code but add "freeWhenDone:NO" ?
https://developer.apple.com/documentation/foundation/nsdata/1416020-initwithbytesnocopy?language=objc
David Kilzer (:ddkilzer)
Comment 3
2017-06-21 22:41:51 PDT
(In reply to Chris Dumez from
comment #2
)
> Comment on
attachment 313579
[details]
> Patch v1 > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=313579&action=review
> > > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IconLoadingDelegate.mm:-145 > > - RetainPtr<IconLoadingSchemeHandler> handler = adoptNS([[IconLoadingSchemeHandler alloc] initWithData:[NSData dataWithBytesNoCopy:(void*)mainBytes length:sizeof(mainBytes)]]); > > Why not keep the existing code but add "freeWhenDone:NO" ? >
https://developer.apple.com/documentation/foundation/nsdata/1416020
- > initwithbytesnocopy?language=objc
Sure, could do that as well. I saw the shorter method first!
David Kilzer (:ddkilzer)
Comment 4
2017-06-21 22:49:33 PDT
Created
attachment 313586
[details]
Patch v2
David Kilzer (:ddkilzer)
Comment 5
2017-06-22 06:15:16 PDT
Committed
r218694
: <
http://trac.webkit.org/changeset/218694
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug