Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Defining a magic pointer or counter inside a program / class and checking for a

ID: 659004 • Letter: D

Question

Defining a magic pointer or counter inside a program / class and checking for a fixed value before executing critical commands is a way to generate a barrier against wrong execution.

This check is supposed to be used on an embedded system which runs a program written in C/C++. Imagine a situation where the program counter is set to a dangerous address by mistake (EMI, bad programmer, hacker, Santa...). This piece of code would for example erase a flash cell in the MCU. We do not want that -> Put an if in front of every erase command and check for 0xDEADBEEF.

I know the gain is not too high and the program looses flexibility. I also thought about having waypoints (Erase -> Is write set? -> Do you have firmware data?)

What is this technique called? Are there any papers about it or even patterns?

Explanation / Answer

A field you add to a structure for the purpose of error checking is often called a dog tag (I think it's so called after Code Complete - Steve McConnel).

A dog tag is used to check for corrupted memory:

when you allocate a variable put a value that should remain unchanged into its tag file;
when you use the structure check the tag's field value (if the tag field doesn't have the expected value the data has been corrupted);
when you delete a pointer corrupt the tag so that if you accidentally try to free the same pointer again you'll detect the corruption.
Canary values on the stack are dog tag fields (take a look at Is

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote