58 vulnerabilities classified as CWE-193 (Off-by-one错误). AI Chinese analysis included.
CWE-193 represents an off-by-one error, a logic flaw where a product calculates or utilizes an incorrect maximum or minimum value that is exactly one unit greater or lesser than the correct limit. This weakness typically arises in boundary conditions during array indexing, loop iterations, or buffer allocation, leading to memory corruption or unexpected program termination. Attackers exploit these miscalculations to trigger buffer overflows, allowing them to overwrite adjacent memory structures with malicious payloads. By exceeding intended bounds, adversaries can execute arbitrary code, escalate privileges, or cause denial-of-service conditions. To prevent such vulnerabilities, developers must rigorously validate boundary conditions, employ static analysis tools to detect logic errors, and use high-level languages with automatic bounds checking. Additionally, thorough code reviews focusing on loop limits and array accesses ensure that integer arithmetic accurately reflects the intended data structure sizes, thereby eliminating the discrepancy that enables exploitation.
int i; unsigned int numWidgets; Widget **WidgetList; numWidgets = GetUntrustedSizeValue(); if ((numWidgets == 0) || (numWidgets > MAX_NUM_WIDGETS)) { ExitError("Incorrect number of widgets requested!"); } WidgetList = (Widget **)malloc(numWidgets * sizeof(Widget *)); printf("WidgetList ptr=%p\n", WidgetList); for(i=0; i<numWidgets; i++) { WidgetList[i] = InitializeWidget(); } WidgetList[numWidgets] = NULL; showWidgets(WidgetList);char firstname[20]; char lastname[20]; char fullname[40]; fullname[0] = '\0'; strncat(fullname, firstname, 20); strncat(fullname, lastname, 20);char firstname[20]; char lastname[20]; char fullname[40]; fullname[0] = '\0'; strncat(fullname, firstname, sizeof(fullname)-strlen(fullname)-1); strncat(fullname, lastname, sizeof(fullname)-strlen(fullname)-1);Vulnerabilities classified as CWE-193 (Off-by-one错误) represent 58 CVEs. The CWE taxonomy describes the weakness; review individual CVEs for product-specific impact.