---
title: "CWE-558: Use of getlogin() in Multithreaded Application"
url: https://radicalnotion.ai/cwe/cwe-558
type: cwe
description: "The product uses the getlogin() function in a multithreaded context, potentially causing it to return incorrect values."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-558: Use of getlogin() in Multithreaded Application

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

## Description

The product uses the getlogin() function in a multithreaded context, potentially causing it to return incorrect values.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

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

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Access Control, Other | Modify Application Data, Bypass Protection Mechanism | Since getlogin() is not reentrant, the contents are not locked out, and the value of the string can be changed by another process. This makes it very risky to use because the username could be changed by other threads. |

## Potential mitigations

### Implementation

Use getlogin\_r() instead, which is reentrant, meaning that other processes or threads are locked out from changing the username.

### Architecture and Design

Using names for security purposes is not advised. Names are easy to forge and can have overlapping user IDs, potentially causing confusion or impersonation.

## 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.)

## Demonstrative examples

### Example 1

The following code relies on getlogin() to determine whether or not a user is trusted. It is easily subverted.

Bad code:

```c
pwd = getpwnam(getlogin());
if (isTrustedGroup(pwd->pw_gid)) {
    allow();
} else {
    deny();
}
```

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-663](https://radicalnotion.ai/cwe/cwe-663) | Use of a Non-reentrant Function in a Concurrent Context |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Often Misused: Authentication | - | - |
| Software Fault Patterns | Use of an improper API | SFP3 | - |

## Frequently asked questions

### What is CWE-558?

The product uses the getlogin() function in a multithreaded context, potentially causing it to return incorrect values.

### How do you prevent CWE-558?

Use getlogin\_r() instead, which is reentrant, meaning that other processes or threads are locked out from changing the username.

### How is CWE-558 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-558?

Exploiting CWE-558 can lead to: Modify Application Data, Bypass Protection Mechanism.

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

---

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