Commit Graph

1420 Commits

Author SHA1 Message Date
Jorge Aparicio
8fb0e80e40 address RalfJung's comment 2018-09-22 21:01:21 +02:00
Jorge Aparicio
7c37c6d33e alloc: fix deprecated warnings 2018-09-22 21:01:21 +02:00
Alex Crichton
8ac88d375e std: Check for overflow in str::repeat
This commit fixes a buffer overflow issue in the standard library
discovered by Scott McMurray where if a large number was passed to
`str::repeat` it may cause and out of bounds write to the buffer of a `Vec`.
This bug was accidentally introduced in #48657 when optimizing the
`str::repeat` function. The bug affects stable Rust releases 1.26.0 to
1.29.0. We plan on backporting this fix to create a 1.29.1 release, and
the 1.30.0 release onwards will include this fix.

The fix in this commit is to introduce a deterministic panic in the case of
capacity overflow. When repeating a slice where the resulting length is larger
than the address space, there’s no way it can succeed anyway!

The standard library and surrounding libraries were briefly checked to see if
there were othere instances of preallocating a vector with a calculation that
may overflow. No instances of this bug (out of bounds write due to a calculation
overflow) were found at this time.

Note that this commit is the first steps towards fixing this issue,
we'll be making a formal post to the Rust security list once these
commits have been merged.
2018-09-20 09:31:53 -07:00
bors
1e21c9a297 Auto merge of #53877 - withoutboats:compositional-pin, r=aturon
Update to a new pinning API.

~~Blocked on #53843 because of method resolution problems with new pin type.~~

@r? @cramertj

cc @RalfJung @pythonesque anyone interested in #49150
2018-09-19 06:56:19 +00:00
Taylor Cramer
3ec1810e32 Cleanup and fix method resolution issue 2018-09-17 16:31:33 -07:00
bors
8a2dec6e58 Auto merge of #53804 - RalfJung:ptr-invalid, r=nagisa
fix some uses of pointer intrinsics with invalid pointers

[Found by miri](https://github.com/solson/miri/pull/446):

* `Vec::into_iter` calls `ptr::read` (and the underlying `copy_nonoverlapping`) with an unaligned pointer to a ZST. [According to LLVM devs](https://bugs.llvm.org/show_bug.cgi?id=38583), this is UB because it contradicts the metadata we are attaching to that pointer.
* `HashMap` creation calls `ptr:.write_bytes` on a NULL pointer with a count of 0. This is likely not currently UB *currently*, but it violates the rules we are setting in https://github.com/rust-lang/rust/pull/53783, and we might want to exploit those rules later (e.g. with more `nonnull` attributes for LLVM).

    Probably what `HashMap` really should do is use `NonNull::dangling()` instead of 0 for the empty case, but that would require a more careful analysis of the code.

It seems like ideally, we should do a review of usage of such intrinsics all over libstd to ensure that they use valid pointers even when the size is 0. Is it worth opening an issue for that?
2018-09-16 18:03:39 +00:00
Ralf Jung
357c5dacee use mem::zeroed to make up ZST values 2018-09-16 14:26:27 +02:00
toidiu
731f4efae5 stabalize infer outlives requirements (RFC 2093).
Co-authored-by: nikomatsakis
2018-09-11 11:40:04 -04:00
bors
06da917b01 Auto merge of #51885 - GuillaumeGomez:trait-impl-show-docs, r=Mark-Simulacrum,QuietMisdreavus
Trait impl show docs

Fixes #51834.

<img width="1440" alt="screen shot 2018-06-29 at 00 14 33" src="https://user-images.githubusercontent.com/3050060/42063323-6e6e8cc8-7b31-11e8-88ef-4dd2229df76c.png">

(You can see both commit changes in the screenshot 😄)

r? @QuietMisdreavus
2018-09-08 04:14:54 +00:00
kennytm
3c77043677
Rollup merge of #53874 - withoutboats:pin-ptr-impls, r=RalfJung
Implement Unpin for Box, Rc, and Arc

Per the discussion in #49150, these should implement `Unpin` even if what they point to does not.
2018-09-07 15:26:49 +08:00
Guillaume Gomez
c1ad1b0338 Fix invalid urls 2018-09-06 23:32:30 +02:00
Without Boats
972cd8bb69
Fix typos. 2018-09-06 21:31:06 +02:00
bors
8b7f164eab Auto merge of #52994 - varkor:trim_direction, r=alexcrichton
Add trim_start, trim_end etc.; deprecate trim_left, trim_right, etc. in future

Adds the methods: `trim_start`, `trim_end`, `trim_start_matches` and `trim_end_matches`.
Deprecates `trim_left`, `trim_right`, `trim_left_matches` and `trim_right_matches` starting from Rust 1.33.0, three versions from when they'll initially be marked as being deprecated, using the future deprecation from https://github.com/rust-lang/rust/issues/30785 and https://github.com/rust-lang/rust/pull/51681.

Fixes https://github.com/rust-lang/rust/issues/30459.
2018-09-05 23:45:08 +00:00
Without Boats
c82af09bb0
Add comment. 2018-09-05 23:47:10 +02:00
Mark Rousskov
9ec5ef541a Breaking change upgrades 2018-09-04 13:22:08 -06:00
bors
839d99c861 Auto merge of #53884 - kennytm:rollup, r=kennytm
Rollup of 9 pull requests

Successful merges:

 - #53076 (set cfg(rustdoc) when rustdoc is running on a crate)
 - #53622 (cleanup: Add main functions to some UI tests)
 - #53769 (Also link Clippy repo in the CONTRIBUTING.md file)
 - #53774 (Add rust-gdbgui script.)
 - #53781 (bench: libcore: fix build failure of any.rs benchmark (use "dyn Any"))
 - #53782 (Make Arc cloning mechanics clearer in module docs)
 - #53790 (Add regression test for issue #52060)
 - #53801 (Prevent duplicated impl on foreign types)
 - #53850 (Nuke the `const_to_allocation` query)
2018-09-01 15:48:21 +00:00
kennytm
fcd76b4d3c
Rollup merge of #53782 - rask:task/arc-docs-adjustment, r=cramertj
Make Arc cloning mechanics clearer in module docs

Add some more wording to module documentation regarding how
`Arc::clone()` works, as some users have assumed cloning Arc's
to work via dereferencing to inner value as follows:

    use std::sync::Arc;

    let myarc = Arc::new(1);
    let myarcref = myarc.clone();

    assert!(1 == myarcref);

Instead of the actual mechanic of referencing the existing
Arc value:

    use std::sync::Arg;

    let myarc = Arc::new(1);
    let myarcref = myarc.clone();

    assert!(myarcref == &myarc); // not sure if assert could assert this in the real world
2018-09-01 21:14:13 +08:00
Without Boats
974bdc80fe
Update to a new pinning API. 2018-09-01 06:57:58 +02:00
Without Boats
9ff29d6188
Fix Rc impl. 2018-09-01 05:04:46 +02:00
Without Boats
c3bdd76047
Implement Unpin for Box, Rc, and Arc 2018-09-01 01:54:59 +02:00
Otto Rask
bf7e324e4e Add clearer wording to Arc clone example code 2018-08-31 11:21:01 +03:00
Oliver Schneider
d125e904b5 Restrict most uses of const_fn to min_const_fn 2018-08-31 08:40:00 +02:00
Pietro Albini
2531d43f19
Rollup merge of #53113 - kpp:more_docs_for_cow, r=GuillaumeGomez
Add example for Cow

Add one more example that shows how to keep `Cow` in a struct.

Link to playground: https://play.rust-lang.org/?gist=a9256bdd034b44bc3cdd0044bbcdbb7c&version=stable&mode=debug&edition=2015

Users ask this question in [ruRust](https://gitter.im/ruRust/general) chat time to time and it is not obvious to add `ToOwned<Owned=Target>` to requirements of generic params.
2018-08-30 20:15:25 +02:00
Otto Rask
6020219993 Rephrase Arc documentation changes regarding clones
Make it clearer that `Arc::clone()` in fact creates a whole new
Arc with the internal pointer pointing to the same location as
the source Arc.
2018-08-30 12:20:41 +03:00
Ralf Jung
61f0a2b3fd fix some uses of pointer intrinsics with invalid pointers 2018-08-29 23:08:47 +02:00
bors
02cb8f2a4f Auto merge of #53564 - MaloJaffre:vecdeque, r=gnzlbg
Reoptimize VecDeque::append

~Unfortunately, I don't know if these changes fix the unsoundness mentioned in #53529, so it is stil a WIP.
This is also completely untested.
The VecDeque code contains other unsound code: one example : [reading unitialized memory](https://play.rust-lang.org/?gist=6ff47551769af61fd8adc45c44010887&version=nightly&mode=release&edition=2015) (detected by MIRI), so I think this code will need a bigger refactor to make it clearer and safer.~

Note: this is based on #53571.
r? @SimonSapin
Cc: #53529 #52553 @YorickPeterse @jonas-schievink @Pazzaz @shepmaster.
2018-08-29 20:08:16 +00:00
MaloJaffre
21d2a6c986 Add another assert 2018-08-29 13:42:48 +02:00
Otto Rask
5399616f1d Make Arc cloning mechanics clearer in module docs
Add some more wording to module documentation regarding how
`Arc::clone()` works, as some users have assumed cloning Arc's
to work via dereferencing to inner value as follows:

    use std::sync::Arc;

    let myarc = Arc::new(1);
    let myarcref = myarc.clone();

    assert!(1 == myarcref);

Instead of the actual mechanic of referencing the existing
Arc value:

    use std::sync::Arg;

    let myarc = Arc::new(1);
    let myarcref = myarc.clone();

    assert!(myarcref == &myarc); // not sure if assert could assert this
    in the real world
2018-08-29 13:20:56 +03:00
MaloJaffre
1908892d3f Fix tidy 2018-08-28 15:59:21 +02:00
MaloJaffre
1a1a7f6167 Add docs and debug asserts 2018-08-28 15:38:56 +02:00
bors
8c2b371ebc Auto merge of #53227 - nivkner:pin_move, r=RalfJung
move the Pin API into its own module for centralized documentation

This implements the change proposed by @withoutboats in #49150, as suggested by @RalfJung in the review of #53104,
along with the documentation that was originally in it, that was deemed more appropriate in module-level documentation.

r? @RalfJung
2018-08-27 22:56:15 +00:00
bors
70a21e89f1 Auto merge of #53441 - toidiu:ak-fix53419, r=nikomatsakis
fix for late-bound regions

Fix for https://github.com/rust-lang/rust/issues/53419

r? @nikomatsakis
2018-08-27 17:42:45 +00:00
Niko Matsakis
73fb1622b3 check that adding infer-outlives requirement to all crates works 2018-08-24 17:10:50 -04:00
Niv Kaminer
83ca347343 remove copyright headers now that they are not madatory 2018-08-25 00:07:00 +03:00
bors
727eabd681 Auto merge of #53662 - kennytm:rollup, r=kennytm
Rollup of 16 pull requests

Successful merges:

 - #53311 (Window Mutex: Document that we properly initialize the SRWLock)
 - #53503 (Discourage overuse of mem::forget)
 - #53545 (Fix #50865: ICE on impl-trait returning functions reaching private items)
 - #53559 (add macro check for lint)
 - #53562 (Lament the invincibility of the Turbofish)
 - #53563 (use String::new() instead of String::from(""), "".to_string(), "".to_owned() or "".into())
 - #53592 (docs: minor stylistic changes to str/string docs)
 - #53594 (Update RELEASES.md to include clippy-preview)
 - #53600 (Fix a grammatical mistake in "expected generic arguments" errors)
 - #53614 (update nomicon and book)
 - #53617 (tidy: Stop requiring a license header)
 - #53618 (Add missing fmt examples)
 - #53636 (Prefer `.nth(n)` over `.skip(n).next()`.)
 - #53644 (Use SmallVec for SmallCStr)
 - #53664 (Remove unnecessary closure in rustc_mir/build/mod.rs)
 - #53666 (Added rustc_codegen_llvm to compiler documentation.)
2018-08-24 17:02:23 +00:00
MaloJaffre
11e488b64f Optimize VecDeque::append 2018-08-24 17:43:05 +02:00
MaloJaffre
6ce76acae4 Slightly refactor VecDeque implementation 2018-08-24 17:43:05 +02:00
kennytm
c51903c73e
Rollup merge of #53592 - matthiaskrgr:str_doc, r=alexcrichton
docs: minor stylistic changes to str/string docs

std::string::String.repeat(): slightly rephrase to be more in-line with other descriptions.

add ticks around a few keywords in other descriptions.
2018-08-24 19:24:32 +08:00
Sergio Benitez
ed0bd38cac Stabilize 'attr_literals' feature. 2018-08-23 19:06:07 -07:00
Niv Kaminer
b26cce5ec0 link to items in pin module to std docs 2018-08-23 10:16:58 +03:00
Niv Kaminer
bfed149020 reexport Unpin into pin module 2018-08-23 02:13:01 +03:00
Niv Kaminer
1304cee862 add more info on Unpin and connect paragraphs better 2018-08-23 02:13:01 +03:00
Niv Kaminer
6b47a6105c allow unused mut for pinning explanation 2018-08-23 02:13:01 +03:00
Niv Kaminer
8e9aad268e deemphasize immutability and improve swap explanation in pin module 2018-08-23 01:37:03 +03:00
Niv Kaminer
1bb05797c2 expand the documentation on PinBox 2018-08-23 01:37:03 +03:00
Niv Kaminer
f9efd0578a move pin module to liballoc and reexport that 2018-08-23 01:37:03 +03:00
Niv Kaminer
c4ec0cd369 attempt to work around Box<T> not being recognized as local type 2018-08-23 01:37:03 +03:00
Niv Kaminer
30bb4af5d8 add top-level documentation to the std pin module 2018-08-23 01:37:03 +03:00
Niv Kaminer
971d7ed249 move PinBox into pin module and export through std 2018-08-23 01:37:03 +03:00
Niv Kaminer
13da951868 move PinMut into pin module and export through std 2018-08-23 01:37:03 +03:00