Search for question
Question

Homework #2, due on 5/6/2023 Security weaknesses in programming languages Arithmetic overflow (unsigned integers) In C, signed integer overflow is undefined behavior. As a result, a compiler may assume that signed operations do not overflow. The code below is supposed to provide sanity checks in order to return an error code when the expression offset + len does overflow: int offset, len; // signed integers /* first check that both offset and len are positives */ if (offset 0 || len <= 0) return -EINVAL; /* if offset + len exceeds the MAXSIZE threshold, or in case of overflow, return an error code */ if ((offset + len > MAXSIZE) || (offset + len < 0) return -EFBIG // offset + len does overflow /* assume from now on that len + offset did not overflow ... */ Questions: 1. Explain why this code is vulnerable (i.e., the checks may fail). 2. Propose a solution to correct it.