InsightSoftwareConsortium / InsightSoftwareConsortium/ITK

String manipulation security: Remove snprintf with user defined formatting options.

Open
#4,621 8 comments 0 reactions 0 assignees View on GitHub
type:Compiler type:Style
Dominant language
C++
Stars
1.7k
Forks
748
Avg merge
1d 1h
Merged PRs (30d)
64

Description

### Description

Allowing users to specify formatting strings at runtime is a well known exploitable code security vulnerability.

We currently suppress these warnings, but it would be better to re-write the codebase to avoid the security vulnerability all together.

### Steps to Reproduce

```
ITK_GCC_PRAGMA_PUSH
ITK_GCC_SUPPRESS_Wformat_nonliteral
snprintf(fileName, IOCommon::ITK_MAXPATHLEN + 1, m_SeriesFormat.c_str(), fileNumber);
ITK_GCC_PRAGMA_POP
```

### Expected behavior

No warning suppression and no security vulnerability.

### Actual behavior

When ITK_GCC_SUPPRESS_Wformat_nonliteral supression are disabled, warnings are issued.

### Reproducibility

New compilers, and requesting -Wformat-nonliteral

### Versions

Since the earliest versions of ITK to at least 2024-04-29

### Additional Information

https://github.com/InsightSoftwareConsortium/ITK/pull/4616#discussion_r1583057823

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.