-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dereferencing an alloca() pointer (identified via its parser taint) is a matter of validating that it is suitably bounded and not null, then converting it into an actual map_value pointer by adding the scratchmem base to it. But this is made a bit more complex because bounds validation involves not only validation of the address but the access size, and there we have two distinct sorts of derefs to deal with: non-lvalue derefs, like *foo, for which the load is done at the time of dereferencing and the size is known, and lvalue loads, like foo[10]=bar, where the size stored is not known until after the deref is complete. For non-lvalue derefs this is quite easy: adjust dt_cg_load so it tells us the size of load it's generating an op for, and add a bounds check to the DT_TOK_DEREF case in dt_cg_node. For lvalue derefs this is trickier: at DT_TOK_DEREF codegen time we have no idea what size of store will be carried out, and in fact dt_cg_node generates no code at all to deref an lvalue store. The deref is carried out in dt_cg_store_val, which has to grow a special case for a store to a writable lvalue node whose child is a deref with the DT_NF_ALLOCA flag turned on. (This combination is generated by the compiler for lvalue stores, so is completely stereotyped and safe to rely on). When this case fires we can do a bounds-check just like the one done for reads. We can also add a lot of tests and flip off XFAIL for a few pre-existing ones, now that alloca and dereferencing of allocations both work. Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com> Signed-off-by: Nick Alcock <nick.alcock@oracle.com> Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
- Loading branch information
1 parent
8d43f03
commit 245d035
Showing
54 changed files
with
1,070 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/* @@xfail: dtv2 */ | ||
BEGIN | ||
{ | ||
self->a = alloca(1024); | ||
this->a = alloca(256); | ||
exit(0); | ||
} |
26 changes: 26 additions & 0 deletions
26
test/unittest/funcs/alloca/err.D_ALLOCA_INCOMPAT.ternary.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2022, 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. | ||
*/ | ||
|
||
/* | ||
* ASSERTION: ternary conditionals with alloca and non-alloca branches | ||
* cannot be assigned to variables. | ||
* | ||
* SECTION: Actions and Subroutines/alloca() | ||
*/ | ||
|
||
#pragma D option quiet | ||
|
||
BEGIN | ||
{ | ||
a = (char *) alloca(1); | ||
a = (a == NULL) ? (char *) 50 : a; | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- @@stderr -- | ||
dtrace: failed to compile script test/unittest/funcs/alloca/err.D_ALLOCA_INCOMPAT.ternary.d: [D_ALLOCA_INCOMPAT] line 20: ternary conditional with alloca and non-alloca branches cannot be assigned to a variable |
Oops, something went wrong.