Standard: Code sanitization #164

Open
opened 2020-08-20 05:56:06 +02:00 by Kreyren · 1 comment
Kreyren commented 2020-08-20 05:56:06 +02:00 (Migrated from github.com)

The coding standard requires a sanitization of the code so that it can be reliable for mission critical runtime i.e flying an aircraft.

Proof-of-concept

mkdir something

Is not sanitized and if the runtime in the code below depends on the directory something then it's going to cause a cascade failure.

Expected:

if [ ! -d something ]; then
	if command -v mkdir 1>/dev/null; then
		mkdir something || { printf '%s\n' "Unable to create a directory 'something'" && exit 1 ;}
	elif command -v other-mkdir; then
		other-mkdir something || { printf '%s\n' "Unable to create a directory 'something'" && exit 1 ;}
	else
		exit 255
	fi
elif [ -d something ]; then
	true
else
	exit 255
fi

This way the software is able to exit safely assuming that standard utilities alike mkdir are checked appropriately prior to mission critical task.

Helpful error message is also expected.

The else statements should be only used for an unexpected trap to capture code quality issues i.e if there is an unexpected symlink named something that would trigger exit 255 (these should hopefully have a helpful message too)

There should be an attempt to avoid fatal failure.

<!-- Please keep your request as short as possible, the longer the request the longer it's going to take for us to process it --> The coding standard requires a sanitization of the code so that it can be reliable for mission critical runtime i.e flying an aircraft. # Proof-of-concept ```sh mkdir something ``` Is not sanitized and if the runtime in the code below depends on the directory `something` then it's going to cause a cascade failure. Expected: ```sh if [ ! -d something ]; then if command -v mkdir 1>/dev/null; then mkdir something || { printf '%s\n' "Unable to create a directory 'something'" && exit 1 ;} elif command -v other-mkdir; then other-mkdir something || { printf '%s\n' "Unable to create a directory 'something'" && exit 1 ;} else exit 255 fi elif [ -d something ]; then true else exit 255 fi ``` This way the software is able to exit safely assuming that standard utilities alike `mkdir` are checked appropriately prior to mission critical task. Helpful error message is also expected. The `else` statements should be only used for an unexpected trap to capture code quality issues i.e if there is an unexpected symlink named `something` that would trigger exit 255 (these should hopefully have a helpful message too) There should be an attempt to avoid fatal failure.
issue-label-bot[bot] commented 2020-08-20 05:56:10 +02:00 (Migrated from github.com)

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.74. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Issue-Label Bot is automatically applying the label `feature_request` to this issue, with a confidence of 0.74. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback! Links: [app homepage](https://github.com/marketplace/issue-label-bot), [dashboard](https://mlbot.net/data/RXT0112/Zernit) and [code](https://github.com/hamelsmu/MLapp) for this bot.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kreyren/Zernit#164