Episode I: The Last Error

Firmware Developers Need To Know

Quick recap. This is the first blog in a long blog series diving into implementing cybersecurity for connected devices. Most advice for IoT cybersecurity will not mention error codes. And that is unfortunate, error codes are extremely valuable for disrupting threat actors dwell time – identifying covert subversions in the corners of the Internet. Your device’s error codes can act as a warning beacon for your customers.

TL;DR

  • Error codes are potential indicator of a compromise.
  • Eliminate pain by standardizing on error codes.
  • Source code available.

NULL Pointer

The vast amount of code written for a connected device uses either a negative one (-1) or a NULL pointer to indicate a failure. On success, a zero (0) or non-NULL, valid pointer is returned. There was a time this all made sense, but today this is a sad state of affairs. Let’s reduce threat actors’ dwell time with better error codes. And debugging and support will be easier too.

				
					if (OK > (status = MODULENAME_action(pContext, pData, dataLen)))
        goto exit;
				
			

Tips

  1. Success is the most common return case; therefore, it should be easy to type and have a non-negative value. Error codes should be negative values.
  2. Error codes naming convention should be self-organizing and self-describing. e.g., ERR_TLS_HEARTBEAT_BAD_PAYLOAD_LEN or ERR_IKE_HANDSHAKE_VER_UNKNOWN or ERR_MEM_ALLOC_FAIL.
  3. Error codes should be grouped together ERR_TLS_*, ERR_TLS_HANDSHAKE_*, etc. Reserve space by padding for future group error codes.
  4. For ease of use, error codes, once officially released, should not be removed, relocated or relabeled.
  5. Error code values should be convertible to a string for pretty logging.
  6. Standardized error codes simplify cross-product documentation.
  7. Keep the error code list sorted for fast binary searches.

Easy error codes here.

Share

Table of Contents

Subscribe to
The Dellfer Brief

The latest industry insights and company news delivered to your inbox.

See Our Blog Posts

Enter Your Information to Access This White Paper

Enter Your Information to Access This White Paper

Enter Your Information to Access This White Paper

Enter Your Information to Access This White Paper

Enter Your Information to Access This Datasheet

Enter Your Information to Access This Datasheet