Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cstr macro for ffi literal strings #19925

Merged
merged 1 commit into from Feb 14, 2018
Merged

Conversation

@upsuper
Copy link
Member

upsuper commented Feb 1, 2018

Use cstr!() macro with CStr to ensure that literal strings used with FFI is properly nul-terminated to avoid cases like #19915.


This change is Reviewable

@highfive
Copy link

highfive commented Feb 1, 2018

Heads up! This PR modifies the following files:

  • @bholley: ports/geckolib/lib.rs, ports/geckolib/error_reporter.rs, ports/geckolib/Cargo.toml
  • @emilio: ports/geckolib/lib.rs, ports/geckolib/error_reporter.rs, ports/geckolib/Cargo.toml
@upsuper
Copy link
Member Author

upsuper commented Feb 1, 2018

This currently doesn't pass tidy test because it introduces new version of syn and quote, so it depends on #19786. I suppose we need to update those crates eventually, given that cssparser has been using the new versions.

@upsuper
Copy link
Member Author

upsuper commented Feb 1, 2018

r? @emilio or @nox

cstr is a new crate I wrote, so you may want to review code there as well.

@highfive highfive assigned emilio and unassigned KiChjang Feb 1, 2018
@nox
Copy link
Member

nox commented Feb 1, 2018

There was already a terminated crate.

@emilio
Copy link
Member

emilio commented Feb 1, 2018

I think it's nice to use CStr in this case, seems easier, we don't need guarantees about encoding...

@nox
Copy link
Member

nox commented Feb 1, 2018

@emilio Do you mean a macro that returns a CStr, or using CStr directly?

@emilio
Copy link
Member

emilio commented Feb 1, 2018

I meant the macro, but I don't really care. If you think using another crate is a good call, I'm fine with it :)

@upsuper
Copy link
Member Author

upsuper commented Feb 1, 2018

Updated the cstr crate to include some more doc and addressed comments from @nox on IRC. The updated cstr crate also removes the dependency to quote crate, so we have one fewer duplicate version package now. (Although that probably doesn't matter as far as it is still blocked on syn.)

@emilio
Copy link
Member

emilio commented Feb 4, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Feb 4, 2018

📌 Commit d95032c has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Feb 4, 2018

Testing commit d95032c with merge 9362d2b...

bors-servo added a commit that referenced this pull request Feb 4, 2018
Use cstr macro for ffi literal strings

Use `cstr!()` macro with `CStr` to ensure that literal strings used with FFI is properly nul-terminated to avoid cases like #19915.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19925)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 4, 2018

💔 Test failed - linux-dev

@CYBAI
Copy link
Collaborator

CYBAI commented Feb 4, 2018

In ran test-tidy --no-progress --all:

Checking files for tidiness...

./Cargo.lock:1: duplicate versions for package `unicode-xid`
	The following packages depend on version 0.0.4 from 'crates.io':
		syn
		synom
	The following packages depend on version 0.1.0 from 'crates.io':
		proc-macro2
		syn

./Cargo.lock:1: duplicate versions for package `syn`
	The following packages depend on version 0.11.11 from 'crates.io':
		cssparser
		cssparser-macros
		darling_core
		darling_macro
		deny_public_fields
		domobject_derive
		html5ever
		jstraceable_derive
		malloc_size_of_derive
		serde_derive
		serde_derive_internals
		style_derive
		synstructure
	The following packages depend on version 0.12.10 from 'crates.io':
		cstr-macros

Running the dependency licensing lint...

In ran test-stylo:

   Compiling geckoservo v0.0.1 (file:///home/servo/buildbot/slave/linux-dev/build/ports/geckolib)
error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:397:29
    |
397 |             Action::Drop => cstr!("PEDeclDropped").as_ptr(),
    |                             ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:396:29
    |
396 |             Action::Skip => cstr!("PEDeclSkipped").as_ptr(),
    |                             ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:375:27
    |
375 |                     ) => (cstr!("PEColorNotColor"), Action::Nothing),
    |                           ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:368:18
    |
368 |                 (cstr!("PEUnknownAtRule"), Action::Skip),
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:358:18
    |
358 |                 (cstr!("PEDeclDropped"), Action::Nothing),
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:352:25
    |
352 |                         cstr!("PEDeclDropped")
    |                         ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:349:25
    |
349 |                         cstr!("PEMQNoMinMaxWithoutValue")
    |                         ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:346:25
    |
346 |                         cstr!("PEMQExpectedFeatureValue")
    |                         ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:343:25
    |
343 |                         cstr!("PEMQExpectedFeatureName")
    |                         ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:340:25
    |
340 |                         cstr!("PEGatherMediaNotIdent")
    |                         ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:335:33
    |
335 |                 return (prefix, cstr!("PEBadSelectorRSIgnored"), Action::Nothing);
    |                                 ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:329:34
    |
329 |                             Some(cstr!("PENegationBadArg"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:326:34
    |
326 |                             Some(cstr!("PEClassSelNotIdent"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:323:34
    |
323 |                             Some(cstr!("PEPseudoSelBadName"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:320:34
    |
320 |                             Some(cstr!("PEPseudoClassArgNotIdent"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:317:34
    |
317 |                             Some(cstr!("PEPseudoSelEndOrUserActionPC"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:314:34
    |
314 |                             Some(cstr!("PEPseudoSelUnknown"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:311:34
    |
311 |                             Some(cstr!("PESelectorGroupExtraCombinator"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:308:34
    |
308 |                             Some(cstr!("PESelectorGroupNoSelector"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:305:33
    |
305 |                            Some(cstr!("PEUnknownNamespacePrefix"))
    |                                 ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:302:34
    |
302 |                             Some(cstr!("PETypeSelNotType"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:299:34
    |
299 |                             Some(cstr!("PEAttributeNameExpected"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:296:34
    |
296 |                             Some(cstr!("PEAttributeNameOrNamespaceExpected"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:293:34
    |
293 |                             Some(cstr!("PEAttSelBadValue"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:290:34
    |
290 |                             Some(cstr!("PEAttSelNoBar"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:287:34
    |
287 |                             Some(cstr!("PEAttSelUnexpected"))
    |                                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:281:18
    |
281 |                 (cstr!("PEUnknownAtRule"), Action::Nothing)
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:271:18
    |
271 |                 (cstr!("PEAtNSUnexpected"), Action::Nothing)
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:265:18
    |
265 |                 (cstr!("PEBadSelectorKeyframeRuleIgnored"), Action::Nothing),
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:263:18
    |
263 |                 (cstr!("PEKeyframeBadName"), Action::Nothing),
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:261:18
    |
261 |                 (cstr!("PEUnknownFontDesc"), Action::Skip),
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:259:18
    |
259 |                 (cstr!("PEUnknownProperty"), Action::Drop),
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:255:27
    |
255 |                     _ => (cstr!("PEUnknownProperty"), Action::Drop)
    |                           ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:253:26
    |
253 |                         (cstr!("PEValueParsingError"), Action::Drop)
    |                          ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:250:33
    |
250 |                                 cstr!("PEValueParsingError"), Action::Drop)
    |                                 ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:249:38
    |
249 |                         return (Some(cstr!("PEExpectedNoneOrURLOrFilterFunction")),
    |                                      ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:246:33
    |
246 |                                 cstr!("PEValueParsingError"), Action::Drop)
    |                                 ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:245:38
    |
245 |                         return (Some(cstr!("PEColorNotColor")),
    |                                      ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:238:18
    |
238 |                 (cstr!("PEParseDeclarationDeclExpected"), Action::Skip)
    |                  ^^^^

error: cannot find macro `cstr!` in this scope
   --> ports/geckolib/tests/../../../ports/geckolib/error_reporter.rs:382:26
    |
382 |                         (cstr!("PEDeclDropped"), Action::Nothing)
    |                          ^^^^

error: aborting due to 40 previous errors

error: Could not compile `stylo_tests`.
@upsuper upsuper force-pushed the upsuper-forks:cstr branch from d95032c to 14b0141 Feb 4, 2018
@upsuper
Copy link
Member Author

upsuper commented Feb 4, 2018

Fixed the test-stylo issue, but it is still blocked on syn upgrade.

@bors-servo
Copy link
Contributor

bors-servo commented Feb 13, 2018

The latest upstream changes (presumably #20022) made this pull request unmergeable. Please resolve the merge conflicts.

@upsuper upsuper force-pushed the upsuper-forks:cstr branch from 14b0141 to 92feec1 Feb 14, 2018
@upsuper
Copy link
Member Author

upsuper commented Feb 14, 2018

Looks like #20022 bumpped the versions of the dependencies I need here \o/

@upsuper
Copy link
Member Author

upsuper commented Feb 14, 2018

@bors-servo r=emilio

@bors-servo
Copy link
Contributor

bors-servo commented Feb 14, 2018

📌 Commit 92feec1 has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Feb 14, 2018

Testing commit 92feec1 with merge 5af219e...

bors-servo added a commit that referenced this pull request Feb 14, 2018
Use cstr macro for ffi literal strings

Use `cstr!()` macro with `CStr` to ensure that literal strings used with FFI is properly nul-terminated to avoid cases like #19915.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19925)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 14, 2018

@bors-servo bors-servo merged commit 92feec1 into servo:master Feb 14, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@upsuper upsuper deleted the upsuper-forks:cstr branch Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.