Jump to page: 1 2
Thread overview
[Issue 23654] execv_: toAStringz: memory corruption
Jan 26, 2023
kdevel
Jan 26, 2023
kdevel
Jan 26, 2023
kdevel
Jan 26, 2023
hsteoh@qfbox.info
Jan 27, 2023
kdevel
Aug 29
kdevel
Aug 29
kdevel
Oct 22
kdevel
January 26, 2023
https://issues.dlang.org/show_bug.cgi?id=23654

--- Comment #1 from kdevel <kdevel@vogtner.de> ---
(In reply to kdevel from comment #0)
> private void toAStringz(in string[] a, const(char)**az)
> {
>     import std.string : toStringz;
>     foreach (string s; a)
>     {
>         *az++ = toStringz(s);
>     }
>     *az = null;

>     auto argv_ = cast(const(char)**)core.stdc.stdlib.malloc((char*).sizeof *
> (1 + argv.length));

It seems to be GC-related. The unittest passes, if

   - the GC is disabled, or
   - the memory is allocated with new:

$ dmd -checkaction=context -unittest -main -run tassnd-no-gc.d
8192
16384
32768
65536
131072
1 modules passed unittests
$ dmd -checkaction=context -unittest -main -run tassnd-no-malloc.d
8192
16384
32768
65536
131072
1 modules passed unittests

--
January 26, 2023
https://issues.dlang.org/show_bug.cgi?id=23654

--- Comment #2 from kdevel <kdevel@vogtner.de> ---
Created attachment 1866
  --> https://issues.dlang.org/attachment.cgi?id=1866&action=edit
GC disabled

--
January 26, 2023
https://issues.dlang.org/show_bug.cgi?id=23654

--- Comment #3 from kdevel <kdevel@vogtner.de> ---
Created attachment 1867
  --> https://issues.dlang.org/attachment.cgi?id=1867&action=edit
use new for allocation (no malloc)

--
January 26, 2023
https://issues.dlang.org/show_bug.cgi?id=23654

hsteoh@qfbox.info changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@qfbox.info

--
January 26, 2023
https://issues.dlang.org/show_bug.cgi?id=23654

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@gmail.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All
           Severity|normal                      |regression

--- Comment #4 from Steven Schveighoffer <schveiguy@gmail.com> ---
Regression, introduced here: https://github.com/dlang/phobos/commit/6302257b0cdc5d171511cc6f1566956ff11b09c5

--
January 26, 2023
https://issues.dlang.org/show_bug.cgi?id=23654

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|dmd                         |phobos

--
January 27, 2023
https://issues.dlang.org/show_bug.cgi?id=23654

--- Comment #5 from kdevel <kdevel@vogtner.de> ---
Created attachment 1868
  --> https://issues.dlang.org/attachment.cgi?id=1868&action=edit
Patch (v0) against process.d

Could not yet test this code. That is how I would implement those D wrappers.

--
August 28
https://issues.dlang.org/show_bug.cgi?id=23654

--- Comment #6 from anonymous4 <dfj1esp02@sneakemail.com> ---
Doesn't fork break the GC heap? If you want to allocate from GC after fork, it may not work.

--
August 29
https://issues.dlang.org/show_bug.cgi?id=23654

--- Comment #7 from kdevel <kdevel@vogtner.de> ---
Created attachment 1888
  --> https://issues.dlang.org/attachment.cgi?id=1888&action=edit
D-Program execv-recur.d demonstrating the memory corruption

//
// execv-recur.d
// 2023-08-29 stvo
//
// disable the GC with
//
//    DRT_GCOPT=disable:1 ./execv-recur 1
//
// this program then expectedly reports
//
//    rc = <-1> errno = <7> strerror = <Argument list too long>
//
// If run with enabled GC
//
//    ./execv-recur 1
//
// the memory gets corrupted and the program reports
//
//    object.Exception@execv-recur.d(49): exp <4> actual <131072>
//

--
August 29
https://issues.dlang.org/show_bug.cgi?id=23654

--- Comment #8 from kdevel <kdevel@vogtner.de> ---
(In reply to anonymous4 from comment #6)
> Doesn't fork break the GC heap? If you want to allocate from GC after fork, it may not work.

The corruption does not require a previous call to fork.

--
« First   ‹ Prev
1 2