Metatests for null pointer dereference

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2023-11-02 19:23:26 +01:00
parent f309fbf0d5
commit 80ba832be6

View file

@ -28,6 +28,29 @@ void meta_test_fail(const char *name)
} }
/****************************************************************/
/* Platform features */
/****************************************************************/
void null_pointer_dereference(const char *name)
{
(void) name;
char *p;
memset(&p, 0, sizeof(p));
volatile char c;
c = *p;
(void) c;
}
void null_pointer_call(const char *name)
{
(void) name;
void (*p)(void);
memset(&p, 0, sizeof(p));
p();
}
/****************************************************************/ /****************************************************************/
/* Command line entry point */ /* Command line entry point */
/****************************************************************/ /****************************************************************/
@ -40,6 +63,8 @@ typedef struct {
metatest_t metatests[] = { metatest_t metatests[] = {
{ "test_fail", "any", meta_test_fail }, { "test_fail", "any", meta_test_fail },
{ "null_dereference", "any", null_pointer_dereference },
{ "null_call", "any", null_pointer_call },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };