Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 84e429a

Browse files
Fix 20778 - Ensure that _d_print_throwable prints the entire message
The previous implementation simply forwarded the pointer + length to `fprintf` and didn't check the return value. This caused the message to be truncated for the following cases: - it contains `\0` (the bug report) - the length is greater than `int.max` This commit changes the implementation s.t. it uses `fwrite` instead which doesn't stop at `\0` and (theoretically) supports lengths up to `size_t.max`
1 parent 2f2a68e commit 84e429a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/rt/dmain2.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ extern (C) void _d_print_throwable(Throwable t)
658658

659659
void sink(in char[] buf) scope nothrow
660660
{
661-
fprintf(stderr, "%.*s", cast(int)buf.length, buf.ptr);
661+
fwrite(buf.ptr, char.sizeof, buf.length, stderr);
662662
}
663663
formatThrowable(t, &sink);
664664
}

test/exceptions/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
include ../common.mak
22

33
TESTS=stderr_msg unittest_assert invalid_memory_operation unknown_gc static_dtor \
4-
future_message refcounted rt_trap_exceptions_drt catch_in_finally
4+
future_message refcounted rt_trap_exceptions_drt catch_in_finally \
5+
message_with_null
56

67
ifeq ($(OS)-$(BUILD),linux-debug)
78
TESTS+=line_trace line_trace_21656 long_backtrace_trunc rt_trap_exceptions
@@ -77,6 +78,9 @@ $(ROOT)/catch_in_finally.done: STDERR_EXP="success."
7778
$(ROOT)/rt_trap_exceptions.done: STDERR_EXP="object.Exception@src/rt_trap_exceptions.d(12): this will abort"
7879
$(ROOT)/rt_trap_exceptions.done: STDERR_EXP2="src/rt_trap_exceptions.d:8 main"
7980
$(ROOT)/assert_fail.done: STDERR_EXP="success."
81+
82+
$(ROOT)/message_with_null.done: STDERR_EXP=" world"
83+
8084
$(ROOT)/%.done: $(ROOT)/%
8185
@echo Testing $*
8286
$(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS) 2>$(ROOT)/$*.stderr || true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module message_with_null;
2+
3+
void main()
4+
{
5+
throw new Exception("hello\0 world!");
6+
}

0 commit comments

Comments
 (0)