CWE-467: Use of sizeof() on a Pointer Type
The code calls sizeof() on a pointer type, when the programmer intended to determine the size of the data that is being pointed to.
Last updated
The code calls sizeof() on a pointer type, when the programmer intended to determine the size of the data that is being pointed to.
Last updated
4 recorded CVEs are caused by CWE-467 (Use of sizeof() on a Pointer Type). The highest-severity and most recent are shown first. 1 new CWE-467 CVE has been recorded so far in 2026 (1 in 2025).
Junos OS & Junos OS Evolved: A specific IPv4 packet can lead to FPC restart.
Fixes to common vulnerabilities found in IBM Db2 High Performance Unload
ModSecurity: Transformation utf8toUnicode produces wrong output on i386 architecture
usb: aqc111: check packet for fixup for true limit
What can happen when CWE-467 is exploited.
Modify Memory, Read Memory
Affects: Integrity, Confidentiality
This error can often cause one to allocate a buffer that is much smaller than what is needed, leading to resultant weaknesses such as buffer overflows.
Typically introduced during these phases of the software lifecycle.
Languages
Practical mitigations for CWE-467, grouped by where in the lifecycle they apply.
Use expressions such as "sizeof(*pointer)" instead of "sizeof(pointer)", unless you intend to run sizeof() on a pointer type to gain some platform independence or if you are allocating a variable on the stack.
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Effectiveness: High
MITRE examples of the weakness in code.
Care should be taken to ensure sizeof returns the size of the data structure itself, and not the size of the pointer to the data structure.
Vulnerable example
double *foo;
...
foo = (double *)malloc(sizeof(foo));Safe example
double *foo;
...
foo = (double *)malloc(sizeof(*foo));This example defines a fixed username and password. The AuthenticateUser() function is intended to accept a username and a password from an untrusted user, and check to ensure that it matches the username and password. If the username and password match, AuthenticateUser() is intended to indicate that authentication succeeded.
Vulnerable example
/* 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) {
printf("Sizeof username = %d\n", sizeof(username));
printf("Sizeof pass = %d\n", sizeof(pass));
if (strncmp(username, inUser, sizeof(username))) {
printf("Auth failure of username using sizeof\n");
return(AUTH_FAIL);
}
/* Because of CWE-467, the sizeof returns 4 on many platforms and architectures. */
if (! strncmp(pass, inPass, sizeof(pass))) {
printf("Auth success of password using sizeof\n");
return(AUTH_SUCCESS);
}
else {
printf("Auth fail of password using sizeof\n");
return(AUTH_FAIL);
}
}
int main (int argc, char **argv)
{
int authResult;
if (argc < 3) {
ExitError("Usage: Provide a username and password");
}
authResult = AuthenticateUser(argv[1], argv[2]);
if (authResult != AUTH_SUCCESS) {
ExitError("Authentication failed");
}
else {
DoAuthenticatedTask(argv[1]);
}
}Attack input
pass5
passABCDEFGH
passWORDReal CVEs that MITRE cites as examples of this weakness.
Common questions about CWE-467.
Weakness data is sourced from the MITRE CWE catalog (v4.21). CVE associations are aggregated and kept current by RadicalNotion.AI.
Get an alert when a new CWE-467 CVE affects your products, with AI-written analysis and remediation steps.