Skip to content

Commit

Permalink
test: Use kernel pointer for nonDPTR tests
Browse files Browse the repository at this point in the history
The nonDPTR tests need to use non-DTrace pointers to be meaningful.
They were using pointers in user space, but technically speaking such
pointers should first be copied (e.g., with copyin or copyinstr) first.
But that makes them DTrace pointers, bypassing the whole point!

Use a kernel pointer like `linux_banner.  Use short strsize so that .r
results files will check consistent "Linux version " strings.

Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Feb 27, 2023
1 parent c858588 commit b1553e4
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 106 deletions.
16 changes: 6 additions & 10 deletions test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=14

BEGIN
{
/* "abcdef" */
system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
printf("|%s|\n", strjoin(`linux_banner, `linux_banner));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("|%s|\n", strjoin((void *)arg1, (void *)arg1));
exit(0);
exit(1);
}

ERROR { exit(1); }
2 changes: 1 addition & 1 deletion test/unittest/funcs/strjoin/tst.strjoin_nonDPTR.r
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
|abcdefabcdef|
|Linux version |

22 changes: 9 additions & 13 deletions test/unittest/funcs/strtok/tst.strtok_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=14

BEGIN
{
/* "abcdef" */
system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
printf("|%s|\n", strtok(`linux_banner, " "));
printf("|%s|\n", strtok(NULL, " "));
printf("|%s|\n", strtok("@@@@@ !!!!!", `linux_banner));
printf("|%s|\n", strtok(NULL, `linux_banner));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("|%s|\n", strtok((void *)arg1, "defghidEFGHI"));
printf("|%s|\n", strtok(NULL, "fF"));
printf("|%s|\n", strtok("nmlkjihgfFOOBARedcba", (void *)arg1));
printf("|%s|\n", strtok(NULL, (void *)arg1));
exit(0);
exit(1);
}

ERROR { exit(1); }
8 changes: 4 additions & 4 deletions test/unittest/funcs/strtok/tst.strtok_nonDPTR.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
|abc|
|de|
|nmlkjihg|
|FOOBAR|
|Linux|
|version|
|@@@@@|
|!!!!!|

18 changes: 7 additions & 11 deletions test/unittest/funcs/substr/tst.substr_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=13

BEGIN
{
/* "abcdef" */
system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
printf("|%s|\n", substr(`linux_banner, 1));
printf("|%s|\n", substr(`linux_banner, 1, 4));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("|%s|\n", substr((void *)arg1, 1));
printf("|%s|\n", substr((void *)arg1, 1, 4));
exit(0);
exit(1);
}

ERROR { exit(1); }
4 changes: 2 additions & 2 deletions test/unittest/funcs/substr/tst.substr_nonDPTR.r
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
|bcdef|
|bcde|
|inux version |
|inux|

16 changes: 6 additions & 10 deletions test/unittest/funcs/tst.basename_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=14

BEGIN
{
/* "/foo/bar/baz/.//" */
system("printf '\x2f\x66\x6f\x6f\x2f\x62\x61\x72\x2f\x62\x61\x7a\x2f\x2e\x2f\x2f' > /dev/null 2>&1");
printf("|%s|\n", basename(`linux_banner));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("|%s|\n", basename((void *)arg1));
exit(0);
exit(1);
}

ERROR { exit(1); }
2 changes: 1 addition & 1 deletion test/unittest/funcs/tst.basename_nonDPTR.r
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
|.|
|Linux version |

16 changes: 6 additions & 10 deletions test/unittest/funcs/tst.dirname_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=14

BEGIN
{
/* "/foo/bar///baz/" */
system("printf '\x2f\x66\x6f\x6f\x2f\x62\x61\x72\x2f\x2f\x2f\x62\x61\x7a\x2f' > /dev/null 2>&1");
printf("|%s|\n", dirname(`linux_banner));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("|%s|\n", dirname((void *)arg1));
exit(0);
exit(1);
}

ERROR { exit(1); }
2 changes: 1 addition & 1 deletion test/unittest/funcs/tst.dirname_nonDPTR.r
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
|/foo/bar|
|.|

16 changes: 6 additions & 10 deletions test/unittest/funcs/tst.index_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=14

BEGIN
{
/* "abcdef" */
system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
printf("index is %d, should be 0\n", index(`linux_banner, `linux_banner));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("index is %d, should be 0\n", index((void *)arg1, (void *)arg1));
exit(0);
exit(1);
}

ERROR { exit(1); }
16 changes: 7 additions & 9 deletions test/unittest/funcs/tst.inet_ntoa_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=14

BEGIN
{
system("printf '\xc0\xa8\x01\x17' > /dev/null 2>&1");
/* "Linu" will be 76.105.110.117 */
printf("%s\n", inet_ntoa(`linux_banner));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("%s\n", inet_ntoa((void *)arg1));
exit(0);
exit(1);
}

ERROR { exit(1); }
2 changes: 1 addition & 1 deletion test/unittest/funcs/tst.inet_ntoa_nonDPTR.r
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
192.168.1.23
76.105.110.117

16 changes: 6 additions & 10 deletions test/unittest/funcs/tst.rindex_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=14

BEGIN
{
/* "abcdef" */
system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
printf("rindex is %d, should be 0\n", rindex(`linux_banner, `linux_banner));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("rindex is %d, should be 0\n", rindex((void *)arg1, (void *)arg1));
exit(0);
exit(1);
}

ERROR { exit(1); }
18 changes: 7 additions & 11 deletions test/unittest/funcs/tst.strchr_nonDPTR.d
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#pragma D option quiet
#pragma D option destructive
#pragma D option strsize=14

BEGIN
{
/* "abcdef" */
system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
printf("|%s|\n", strchr(`linux_banner, 'x'));
printf("|%s|\n", strrchr(`linux_banner, 'u'));
exit(0);
}

syscall::write:entry
/ppid == $pid/
ERROR
{
printf("|%s|\n", strchr((void *)arg1, 'b'));
printf("|%s|\n", strrchr((void *)arg1, 'b'));
exit(0);
exit(1);
}

ERROR { exit(1); }
4 changes: 2 additions & 2 deletions test/unittest/funcs/tst.strchr_nonDPTR.r
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
|bcdef|
|bcdef|
|x version|
|ux version|

0 comments on commit b1553e4

Please sign in to comment.