EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 59
Firmware Security Basics
Protect devices that live on the network.
Connected devices get probed by strangers. Do not ship default passwords, keep secrets out of source code that you publish, and validate every byte received from outside before using it.
Many chips can lock their debug port and flash readout so firmware cannot be copied. Check each message length before copying, because unchecked copies cause buffer overflows.
Security is a process: plan for updates so flaws can be fixed after release.
EXAMPLE
void copy_name(char *dst, const char *src, unsigned max) {
unsigned i = 0;
while (i + 1 < max && src[i]) { dst[i] = src[i]; i++; }
dst[i] = 0; /* always terminate */
}