ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:93295] [Ruby trunk Bug#15946] Undefined behavior can occur with memcpy in String#sub!
       [not found] <redmine.issue-15946.20190621003733@ruby-lang.org>
@ 2019-06-21  0:37 ` luke.gru
  2019-06-21 13:48 ` [ruby-core:93300] " nobu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: luke.gru @ 2019-06-21  0:37 UTC (permalink / raw
  To: ruby-core

Issue #15946 has been reported by luke-gru (Luke Gruber).

----------------------------------------
Bug #15946: Undefined behavior can occur with memcpy in String#sub!
https://bugs.ruby-lang.org/issues/15946

* Author: luke-gru (Luke Gruber)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hi, I've found an overlapping memcpy in an odd situation:

```ruby
s = "hello there this is a long string and cant be embedded"
s2 = s.dup # create shared string pointing to s
s3 = s.slice(1, 100) # create shared string pointing to s with offset
s2.sub!(s3, s2) # just 1 example that exhibits the undefined behavior memcpy

```

In the c function `rb_str_sub_bang()`, I added a printf call and here's the output:

```
if (rlen != plen) {
     memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
}
fprintf(stderr, "p: %p, rp: %p, beg0: %ld, rlen: %ld, rp-p:%ld\n", p, rp, beg0, rlen, (long)((char*)rp-(char*)p));
/* outputs: p: 0x560a2cec8bc0, rp: 0x560a2cec8bc0, beg0: 1, rlen: 54, rp-p:0 */
memcpy(p + beg0, rp, rlen);
```

Doesn't crash on my system but possible on some systems.

Thanks :)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:93300] [Ruby trunk Bug#15946] Undefined behavior can occur with memcpy in String#sub!
       [not found] <redmine.issue-15946.20190621003733@ruby-lang.org>
  2019-06-21  0:37 ` [ruby-core:93295] [Ruby trunk Bug#15946] Undefined behavior can occur with memcpy in String#sub! luke.gru
@ 2019-06-21 13:48 ` nobu
  2019-08-09 13:42 ` [ruby-core:94220] [Ruby master " nagachika00
  2019-08-26 16:17 ` [ruby-core:94579] " usa
  3 siblings, 0 replies; 4+ messages in thread
From: nobu @ 2019-06-21 13:48 UTC (permalink / raw
  To: ruby-core

Issue #15946 has been updated by nobu (Nobuyoshi Nakada).


Thank you.
`s3` doesn't seem to need to share `s`.

----------------------------------------
Bug #15946: Undefined behavior can occur with memcpy in String#sub!
https://bugs.ruby-lang.org/issues/15946#change-78770

* Author: luke-gru (Luke Gruber)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hi, I've found an overlapping memcpy in an odd situation:

```ruby
s = "hello there this is a long string and cant be embedded"
s2 = s.dup # create shared string pointing to s
s3 = s.slice(1, 100) # create shared string pointing to s with offset
s2.sub!(s3, s2) # just 1 example that exhibits the undefined behavior memcpy

```

In the c function `rb_str_sub_bang()`, I added a printf call and here's the output:

```
if (rlen != plen) {
     memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
}
fprintf(stderr, "p: %p, rp: %p, beg0: %ld, rlen: %ld, rp-p:%ld\n", p, rp, beg0, rlen, (long)((char*)rp-(char*)p));
/* outputs: p: 0x560a2cec8bc0, rp: 0x560a2cec8bc0, beg0: 1, rlen: 54, rp-p:0 */
memcpy(p + beg0, rp, rlen);
```

Doesn't crash on my system but possible on some systems.

Thanks :)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:94220] [Ruby master Bug#15946] Undefined behavior can occur with memcpy in String#sub!
       [not found] <redmine.issue-15946.20190621003733@ruby-lang.org>
  2019-06-21  0:37 ` [ruby-core:93295] [Ruby trunk Bug#15946] Undefined behavior can occur with memcpy in String#sub! luke.gru
  2019-06-21 13:48 ` [ruby-core:93300] " nobu
@ 2019-08-09 13:42 ` nagachika00
  2019-08-26 16:17 ` [ruby-core:94579] " usa
  3 siblings, 0 replies; 4+ messages in thread
From: nagachika00 @ 2019-08-09 13:42 UTC (permalink / raw
  To: ruby-core

Issue #15946 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.4: REQUIRED, 2.5: REQUIRED, 2.6: REQUIRED to 2.4: REQUIRED, 2.5: REQUIRED, 2.6: DONE

ruby_2_6 r67739 merged revision(s) 8f51da5d41f0642d5a971e4223d1ba14643c6398.

----------------------------------------
Bug #15946: Undefined behavior can occur with memcpy in String#sub!
https://bugs.ruby-lang.org/issues/15946#change-80520

* Author: luke-gru (Luke Gruber)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: REQUIRED, 2.5: REQUIRED, 2.6: DONE
----------------------------------------
Hi, I've found an overlapping memcpy in an odd situation:

```ruby
s = "hello there this is a long string and cant be embedded"
s2 = s.dup # create shared string pointing to s
s3 = s.slice(1, 100) # create shared string pointing to s with offset
s2.sub!(s3, s2) # just 1 example that exhibits the undefined behavior memcpy

```

In the c function `rb_str_sub_bang()`, I added a printf call and here's the output:

```
if (rlen != plen) {
     memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
}
fprintf(stderr, "p: %p, rp: %p, beg0: %ld, rlen: %ld, rp-p:%ld\n", p, rp, beg0, rlen, (long)((char*)rp-(char*)p));
/* outputs: p: 0x560a2cec8bc0, rp: 0x560a2cec8bc0, beg0: 1, rlen: 54, rp-p:0 */
memcpy(p + beg0, rp, rlen);
```

Doesn't crash on my system but possible on some systems.

Thanks :)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:94579] [Ruby master Bug#15946] Undefined behavior can occur with memcpy in String#sub!
       [not found] <redmine.issue-15946.20190621003733@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-08-09 13:42 ` [ruby-core:94220] [Ruby master " nagachika00
@ 2019-08-26 16:17 ` usa
  3 siblings, 0 replies; 4+ messages in thread
From: usa @ 2019-08-26 16:17 UTC (permalink / raw
  To: ruby-core

Issue #15946 has been updated by usa (Usaku NAKAMURA).

Backport changed from 2.4: REQUIRED, 2.5: REQUIRED, 2.6: DONE to 2.4: REQUIRED, 2.5: DONE, 2.6: DONE

ruby_2_5 r67770 merged revision(s) 8f51da5d41f0642d5a971e4223d1ba14643c6398.

----------------------------------------
Bug #15946: Undefined behavior can occur with memcpy in String#sub!
https://bugs.ruby-lang.org/issues/15946#change-81037

* Author: luke-gru (Luke Gruber)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: REQUIRED, 2.5: DONE, 2.6: DONE
----------------------------------------
Hi, I've found an overlapping memcpy in an odd situation:

```ruby
s = "hello there this is a long string and cant be embedded"
s2 = s.dup # create shared string pointing to s
s3 = s.slice(1, 100) # create shared string pointing to s with offset
s2.sub!(s3, s2) # just 1 example that exhibits the undefined behavior memcpy

```

In the c function `rb_str_sub_bang()`, I added a printf call and here's the output:

```
if (rlen != plen) {
     memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
}
fprintf(stderr, "p: %p, rp: %p, beg0: %ld, rlen: %ld, rp-p:%ld\n", p, rp, beg0, rlen, (long)((char*)rp-(char*)p));
/* outputs: p: 0x560a2cec8bc0, rp: 0x560a2cec8bc0, beg0: 1, rlen: 54, rp-p:0 */
memcpy(p + beg0, rp, rlen);
```

Doesn't crash on my system but possible on some systems.

Thanks :)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-26 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-15946.20190621003733@ruby-lang.org>
2019-06-21  0:37 ` [ruby-core:93295] [Ruby trunk Bug#15946] Undefined behavior can occur with memcpy in String#sub! luke.gru
2019-06-21 13:48 ` [ruby-core:93300] " nobu
2019-08-09 13:42 ` [ruby-core:94220] [Ruby master " nagachika00
2019-08-26 16:17 ` [ruby-core:94579] " usa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).