---
title: "CWE-467: Use of sizeof() on a Pointer Type"
url: https://radicalnotion.ai/cwe/cwe-467
type: cwe
description: "The code calls sizeof() on a pointer type, when the programmer intended to determine the size of the data that is being pointed to."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-467: Use of sizeof() on a Pointer Type

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 4
- **Of those, in CISA KEV:** 0
- **New in 2026:** 1
- **CWE catalog version:** 4.21

## Description

The code calls sizeof() on a pointer type, when the programmer intended to determine the size of the data that is being pointed to.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | The use of sizeof() on a pointer can sometimes generate useful information. An obvious case is to find out the wordsize on a platform. More often than not, the appearance of sizeof(pointer) indicates an incorrect calculation - i.e., a bug. |

## Applicable platforms

**Languages:** C (Undetermined), C++ (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality | Modify Memory, Read Memory | 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. |

## Potential mitigations

### Implementation

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.

## Detection methods

### Automated Static Analysis

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

## Demonstrative examples

### Example 1

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.

Bad code:

```c
double *foo;
...
foo = (double *)malloc(sizeof(foo));
```

Good code:

```c
double *foo;
...
foo = (double *)malloc(sizeof(*foo));
```

### Example 2

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.

Bad code:

```c
/* 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 code:

```
pass5
passABCDEFGH
passWORD
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2025-33132 | Database utility uses sizeof() on a pointer type, leading to incorrect size calculation and a crash. |

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2020-1638 | Junos OS & Junos OS Evolved: A specific IPv4 packet can lead to FPC restart. | high | 7.5 | - | No | 2020-04-08 |
| CVE-2025-33132 | Fixes to common vulnerabilities found in IBM Db2 High Performance Unload | medium | 6.5 | - | No | 2025-10-27 |
| CVE-2026-52761 | ModSecurity: Transformation utf8toUnicode produces wrong output on i386 architecture | medium | 5.8 | - | No | 2026-07-10 |
| CVE-2023-52655 | usb: aqc111: check packet for fixup for true limit | medium | 5.5 | - | No | 2024-05-13 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-131](https://radicalnotion.ai/cwe/cwe-131) | Incorrect Calculation of Buffer Size |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Use of sizeof() on a pointer type | - | - |
| CERT C Secure Coding | Do not apply the sizeof operator to a pointer when taking the size of an array | ARR01-C | - |
| CERT C Secure Coding | Allocate sufficient memory for an object | MEM35-C | CWE More Abstract |
| Software Fault Patterns | Incorrect Buffer Length Computation | SFP10 | - |

## Frequently asked questions

### What is CWE-467?

The code calls sizeof() on a pointer type, when the programmer intended to determine the size of the data that is being pointed to.

### What CVEs are caused by CWE-467?

4 recorded CVEs are attributed to CWE-467, including CVE-2020-1638, CVE-2025-33132 and CVE-2026-52761.

### How do you prevent CWE-467?

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.

### How is CWE-467 detected?

Automated Static Analysis: 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.)

### What are the consequences of CWE-467?

Exploiting CWE-467 can lead to: Modify Memory, Read Memory.

### Is CWE-467 actively exploited?

4 recorded CVEs are caused by CWE-467; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/467.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-467). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
