antirez / antirez/kilo

Enhance memory safety and buffer initialization for stability

未关闭
#100 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C
星标
9.1k
派生
995
PR 合并指标
30 天内没有已合并 PR

描述

### Describe

I found potential memory safety and stability issues in the kilo codebase:

- **CWE-476 (NULL Pointer Dereference)**:

In `editorUpdateSyntax`, `editorRowAppendString`, and `editorOpen`, memory allocation results (via `realloc` or `malloc`) are not properly checked for `NULL`.

This could lead to memory leaks or crashes if an allocation fails.

- **CWE-457 (Use of Uninitialized Variable)**:

In `getCursorPosition`, the buffer `buf` is not explicitly initialized, which could result in undefined behavior.

### Expected behavior

- Memory allocation failures (e.g., `realloc`, `malloc`) should be properly handled and should not overwrite original pointers.
- Buffers should be initialized before use to avoid undefined behavior.

### Actual behavior

- In multiple functions, the return values of `realloc` or `malloc` are not checked before dereferencing.
- In `getCursorPosition`, `buf` may contain uninitialized data before valid input is read.

### How to Reproduce

- Simulate low-memory conditions (e.g., `ulimit -v 10000` on Linux) and observe crashes or instability.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。