[DTrace-devel] [PATCH 5/5] string: ensure string size is handled correctly

Eugene Loh eugene.loh at oracle.com
Thu Aug 14 01:00:54 UTC 2025


Cool.  Can the v2 change s/strsuze/strsize/?

On 8/13/25 18:09, Kris Van Hees wrote:
> A v2 coming soon - I needed to cover a few more cases of tests that I failed to
> notice.
>
> On Wed, Aug 13, 2025 at 11:57:33AM -0400, Kris Van Hees via DTrace-devel wrote:
>> A string is defined as a character array of size strsize.  Strings
>> that are less that strsize in length are terminated by a NUL byte.
>> This implies that the NUL byte is part of the array and therefore,
>> strsuze is indeed the size of the array and not the maximum number
>> of characters in the string.
>>
>> Tests are adjusted to reflect this behaviour.
>>
>> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
>> ---
>>   libdtrace/dt_cg.c                                     | 11 +++++------
>>   .../funcs/inet_ntoa6/tst.inet_ntoa6.strsize_10.r      |  6 +++---
>>   test/unittest/funcs/strjoin/tst.strjoin-bordercases.d |  2 +-
>>   .../funcs/strjoin/tst.strjoin-capped-size-2.d         |  2 +-
>>   .../funcs/strjoin/tst.strjoin-capped-size-3.d         |  2 +-
>>   test/unittest/funcs/strjoin/tst.strjoin-capped-size.d |  2 +-
>>   test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d     |  2 +-
>>   test/unittest/funcs/strtok/tst.strtok_long.d          |  4 ++--
>>   test/unittest/funcs/strtok/tst.strtok_long.r          |  4 ++--
>>   test/unittest/funcs/substr/tst.substr-stored-len.d    |  2 +-
>>   test/unittest/funcs/substr/tst.substr-strsize.d       |  2 +-
>>   test/unittest/funcs/substr/tst.substr_nonDPTR.d       |  2 +-
>>   test/unittest/funcs/tst.basename_nonDPTR.d            |  2 +-
>>   test/unittest/funcs/tst.inet_ntoa_nonDPTR.d           |  2 +-
>>   test/unittest/funcs/tst.lltostr-short.d               |  2 +-
>>   15 files changed, 23 insertions(+), 24 deletions(-)
>>
>> diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
>> index 88dddb087..cd9e7f4e9 100644
>> --- a/libdtrace/dt_cg.c
>> +++ b/libdtrace/dt_cg.c
>> @@ -1741,11 +1741,10 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
>>   			dt_cg_check_ptr_arg(dlp, drp, dnp, NULL);
>>   
>>   		TRACE_REGSET("store_val(): Begin ");
>> -		off = dt_rec_add(dtp, dt_cg_fill_gap, kind, size + 1, 1, pfp,
>> -				 arg);
>> +		off = dt_rec_add(dtp, dt_cg_fill_gap, kind, size, 1, pfp, arg);
>>   
>>   		/*
>> -		 * Copy the string data (no more than STRSIZE + 1 bytes) to the
>> +		 * Copy the string data (no more than STRSIZE bytes) to the
>>   		 * buffer at (%r9 + off).  We depend on the fact that
>>   		 * probe_read_str() stops at the terminating NUL byte.
>>   		 */
>> @@ -1754,7 +1753,7 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
>>   
>>   		emit(dlp, BPF_MOV_REG(BPF_REG_1, BPF_REG_9));
>>   		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off));
>> -		emit(dlp, BPF_MOV_IMM(BPF_REG_2, strsize + 1));
>> +		emit(dlp, BPF_MOV_IMM(BPF_REG_2, strsize));
>>   		emit(dlp, BPF_MOV_REG(BPF_REG_3, dnp->dn_reg));
>>   		dt_regset_free(drp, dnp->dn_reg);
>>   		dt_cg_tstring_free(pcb, dnp);
>> @@ -1765,13 +1764,13 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
>>   		/*
>>   		 * Pad the rest with zeroes, if necessary.
>>   		 */
>> -		emit(dlp,  BPF_BRANCH_IMM(BPF_JGE, BPF_REG_0, strsize + 1, lbl_ok));
>> +		emit(dlp,  BPF_BRANCH_IMM(BPF_JGE, BPF_REG_0, strsize, lbl_ok));
>>   		if (dt_regset_xalloc_args(drp) == -1)
>>   			longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
>>   		emit(dlp,  BPF_MOV_REG(BPF_REG_1, BPF_REG_9));
>>   		emit(dlp,  BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, off));
>>   		emit(dlp,  BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0));
>> -		emit(dlp,  BPF_MOV_IMM(BPF_REG_2, strsize + 1));
>> +		emit(dlp,  BPF_MOV_IMM(BPF_REG_2, strsize));
>>   		emit(dlp,  BPF_ALU64_REG(BPF_SUB, BPF_REG_2, BPF_REG_0));
>>   		dt_cg_zerosptr(BPF_REG_3, dlp, drp);
>>   		emit(dlp,  BPF_CALL_HELPER(dtp->dt_bpfhelper[BPF_FUNC_probe_read_kernel]));
>> diff --git a/test/unittest/funcs/inet_ntoa6/tst.inet_ntoa6.strsize_10.r b/test/unittest/funcs/inet_ntoa6/tst.inet_ntoa6.strsize_10.r
>> index 5e7d49b03..8090daad6 100644
>> --- a/test/unittest/funcs/inet_ntoa6/tst.inet_ntoa6.strsize_10.r
>> +++ b/test/unittest/funcs/inet_ntoa6/tst.inet_ntoa6.strsize_10.r
>> @@ -1,8 +1,8 @@
>> -fe80:7060:
>> -1080::808:
>> +fe80:7060
>> +1080::808
>>   ::1
>>   ::
>>   127.0.0.1
>>   127.0.0.1
>> -::fffe:7f0
>> +::fffe:7f
>>   
>> diff --git a/test/unittest/funcs/strjoin/tst.strjoin-bordercases.d b/test/unittest/funcs/strjoin/tst.strjoin-bordercases.d
>> index 253b2d6ef..1ac5ffd12 100644
>> --- a/test/unittest/funcs/strjoin/tst.strjoin-bordercases.d
>> +++ b/test/unittest/funcs/strjoin/tst.strjoin-bordercases.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option rawbytes
>> -#pragma D option strsize=5
>> +#pragma D option strsize=6
>>   #pragma D option quiet
>>   
>>   BEGIN
>> diff --git a/test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.d b/test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.d
>> index 625c786b6..44a6acd88 100644
>> --- a/test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.d
>> +++ b/test/unittest/funcs/strjoin/tst.strjoin-capped-size-2.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option rawbytes
>> -#pragma D option strsize=6
>> +#pragma D option strsize=7
>>   #pragma D option quiet
>>   
>>   BEGIN
>> diff --git a/test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.d b/test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.d
>> index 52718325a..d2982a70b 100644
>> --- a/test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.d
>> +++ b/test/unittest/funcs/strjoin/tst.strjoin-capped-size-3.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option rawbytes
>> -#pragma D option strsize=6
>> +#pragma D option strsize=7
>>   #pragma D option quiet
>>   
>>   BEGIN
>> diff --git a/test/unittest/funcs/strjoin/tst.strjoin-capped-size.d b/test/unittest/funcs/strjoin/tst.strjoin-capped-size.d
>> index fe5b323f7..b54fd2f29 100644
>> --- a/test/unittest/funcs/strjoin/tst.strjoin-capped-size.d
>> +++ b/test/unittest/funcs/strjoin/tst.strjoin-capped-size.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option rawbytes
>> -#pragma D option strsize=10
>> +#pragma D option strsize=11
>>   #pragma D option quiet
>>   
>>   BEGIN
>> diff --git a/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d b/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d
>> index a1816f975..2b700a5a8 100644
>> --- a/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d
>> +++ b/test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option quiet
>> -#pragma D option strsize=14
>> +#pragma D option strsize=15
>>   
>>   BEGIN
>>   {
>> diff --git a/test/unittest/funcs/strtok/tst.strtok_long.d b/test/unittest/funcs/strtok/tst.strtok_long.d
>> index 1fbe415dc..254a65485 100644
>> --- a/test/unittest/funcs/strtok/tst.strtok_long.d
>> +++ b/test/unittest/funcs/strtok/tst.strtok_long.d
>> @@ -9,8 +9,8 @@
>>   
>>   BEGIN
>>   {
>> -	/* 256-char string ending in "XYZ" */
>> -	x = "_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________XYZ";
>> +	/* 256-char string ending in "XYZ" (255 chars + NUL byte)*/
>> +	x = "____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________XYZ";
>>   
>>   	/* check whether the last char of a long string is seen */
>>   	y = "a";
>> diff --git a/test/unittest/funcs/strtok/tst.strtok_long.r b/test/unittest/funcs/strtok/tst.strtok_long.r
>> index a752554e8..4b172ca1b 100644
>> --- a/test/unittest/funcs/strtok/tst.strtok_long.r
>> +++ b/test/unittest/funcs/strtok/tst.strtok_long.r
>> @@ -1,5 +1,5 @@
>> -_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________XYZ
>> +____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________XYZ
>>   zyxwvutsrqponmlkjihgfedcba
>> -_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________XY
>> +____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________XY
>>   Z
>>   
>> diff --git a/test/unittest/funcs/substr/tst.substr-stored-len.d b/test/unittest/funcs/substr/tst.substr-stored-len.d
>> index 97d2b0f61..fa3e5337c 100644
>> --- a/test/unittest/funcs/substr/tst.substr-stored-len.d
>> +++ b/test/unittest/funcs/substr/tst.substr-stored-len.d
>> @@ -13,7 +13,7 @@
>>   
>>   #pragma D option quiet
>>   #pragma D option rawbytes
>> -#pragma D option strsize=13
>> +#pragma D option strsize=14
>>   
>>   BEGIN
>>   {
>> diff --git a/test/unittest/funcs/substr/tst.substr-strsize.d b/test/unittest/funcs/substr/tst.substr-strsize.d
>> index b4d0cc63e..04eab4297 100644
>> --- a/test/unittest/funcs/substr/tst.substr-strsize.d
>> +++ b/test/unittest/funcs/substr/tst.substr-strsize.d
>> @@ -15,7 +15,7 @@
>>   
>>   #pragma D option quiet
>>   #pragma D option rawbytes
>> -#pragma D option strsize=13
>> +#pragma D option strsize=14
>>   
>>   BEGIN
>>   {
>> diff --git a/test/unittest/funcs/substr/tst.substr_nonDPTR.d b/test/unittest/funcs/substr/tst.substr_nonDPTR.d
>> index 9d847ab6f..3e10af08e 100644
>> --- a/test/unittest/funcs/substr/tst.substr_nonDPTR.d
>> +++ b/test/unittest/funcs/substr/tst.substr_nonDPTR.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option quiet
>> -#pragma D option strsize=13
>> +#pragma D option strsize=14
>>   
>>   BEGIN
>>   {
>> diff --git a/test/unittest/funcs/tst.basename_nonDPTR.d b/test/unittest/funcs/tst.basename_nonDPTR.d
>> index 4f93685f7..cecef827b 100644
>> --- a/test/unittest/funcs/tst.basename_nonDPTR.d
>> +++ b/test/unittest/funcs/tst.basename_nonDPTR.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option quiet
>> -#pragma D option strsize=14
>> +#pragma D option strsize=15
>>   
>>   BEGIN
>>   {
>> diff --git a/test/unittest/funcs/tst.inet_ntoa_nonDPTR.d b/test/unittest/funcs/tst.inet_ntoa_nonDPTR.d
>> index 500c53e86..f079c7ef4 100644
>> --- a/test/unittest/funcs/tst.inet_ntoa_nonDPTR.d
>> +++ b/test/unittest/funcs/tst.inet_ntoa_nonDPTR.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option quiet
>> -#pragma D option strsize=14
>> +#pragma D option strsize=15
>>   
>>   BEGIN
>>   {
>> diff --git a/test/unittest/funcs/tst.lltostr-short.d b/test/unittest/funcs/tst.lltostr-short.d
>> index 969045667..65a5714c2 100644
>> --- a/test/unittest/funcs/tst.lltostr-short.d
>> +++ b/test/unittest/funcs/tst.lltostr-short.d
>> @@ -6,7 +6,7 @@
>>    */
>>   
>>   #pragma D option quiet
>> -#pragma D option strsize=7
>> +#pragma D option strsize=8
>>   
>>   BEGIN
>>   {
>> -- 
>> 2.45.2
>>
>>
>> _______________________________________________
>> DTrace-devel mailing list
>> DTrace-devel at oss.oracle.com
>> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list