16 vulnerabilities classified as CWE-187 (部分比较). AI Chinese analysis included.
CWE-187, Partial String Comparison, is a logic flaw where software validates input by examining only a subset of a string rather than the entire value. This weakness typically enables attackers to bypass security controls, such as authentication mechanisms, by providing a short input that matches a prefix or substring of the correct credential. For instance, a user might gain access by entering just the first few characters of a password if the system checks only that portion. To prevent this vulnerability, developers must ensure that all string comparisons are performed against the complete input data. Implementing strict equality checks that require the entire string to match, rather than relying on partial matches or substring searches, effectively mitigates this risk and ensures robust validation of sensitive data.
/* Ignore CWE-259 (hard-coded password) and CWE-309 (use of password system for authentication) for this example. */ char *username = "admin"; char *pass = "password"; int AuthenticateUser(char *inUser, char *inPass) { if (strncmp(username, inUser, strlen(inUser))) { logEvent("Auth failure of username using strlen of inUser"); return(AUTH_FAIL); } if (! strncmp(pass, inPass, strlen(inPass))) { logEvent("Auth success of password using strlen of inUser"); return(AUTH_SUCCESS); } else { logEvent("Auth fail of password using sizeof"); return(AUTH_FAIL); } } int main (int argc, char **argv) { int a
p pa pas pass
Vulnerabilities classified as CWE-187 (部分比较) represent 16 CVEs. The CWE taxonomy describes the weakness; review individual CVEs for product-specific impact.