Exercise Security and Safety - JawaharT/Best-Practices-On-Azure-Sphere GitHub Wiki

Exercises for Security and Safety

Exercise one

In this first exercise we will validate the number entered in the Fibonacci program to be greater than or equal to one and an integer data type.

This exercise will demonstrate the ideal way to validate your inputs before use. For instance, let's take the end_integer_input function from the Fibonacci program in a previous exercise and update it to validate user inputs to make sure they are appropriate for the generate_sequence function.

This is reminder of the end_integer_input function created as part of a previous section.

#include <stdio.h> 

int end_integer_input(){ 
    static int number;

    // Use this for testing purposes
    // printf("Enter a Number for Fibonacci Sequence: "); 
    // scanf("%d", number);
    
    // For embedded systems, equivalent to keypad entry here
    number = 10;
    return (int)number; 
} 

Exercise two

In the second exercise we will develop a program to read button A presses from the AVNET MT3620 revision one Azure Sphere board. Here is the incomplete code to begin the exercise and the commented notes will provide guidance on completing the tasks.

// Button A state variable, set to button not-pressed
static GPIO_Value_Type currentButtonAState = GPIO_Value_High;

// Termination state
volatile sig_atomic_t terminationRequired = false;

static void ButtonTimerEventHandler(EventData *eventData){
    bool buttonAPressed = false;

    if (ConsumeTimerFdEvent(buttonPollTimerFd) != 0) {
        terminationRequired = true;
	return;
    }

    // Task 1: Check for button A press

    // Task 2: Check if the button has GPIO_Value_Low when pressed and GPIO_Value_High when released

}

For a version of the correct solutions and an explanation for the differences click here.

⚠️ **GitHub.com Fallback** ⚠️