Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librc: avoid using fixed-size buffers for paths #715

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

floppym
Copy link
Contributor

@floppym floppym commented May 31, 2024

Use heap allocations instead. This avoids warnings:

../src/librc/librc.c: In function ‘rc_service_mark’:
../src/librc/librc.c:817:58: warning: ‘/’ directive output may be truncated writing 1 byte into a region of size between 0 and 4095 [-Wformat-truncation=]
  817 |                         snprintf(was, sizeof(was), "%s/%s/%s",
      |                                                          ^
../src/librc/librc.c:817:25: note: ‘snprintf’ output 3 or more bytes (assuming 4098) into a destination of size 4096
  817 |                         snprintf(was, sizeof(was), "%s/%s/%s",
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  818 |                             file, dir->value, base);
      |                             ~~~~~~~~~~~~~~~~~~~~~~~
../src/librc/librc.c:822:58: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
  822 |                         snprintf(was, sizeof(was), "%s/%s", file, dir->value);
      |                                                          ^
../src/librc/librc.c:822:25: note: ‘snprintf’ output 2 or more bytes (assuming 4097) into a destination of size 4096
  822 |                         snprintf(was, sizeof(was), "%s/%s", file, dir->value);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use heap allocations instead. This avoids warnings:

```
../src/librc/librc.c: In function ‘rc_service_mark’:
../src/librc/librc.c:817:58: warning: ‘/’ directive output may be truncated writing 1 byte into a region of size between 0 and 4095 [-Wformat-truncation=]
  817 |                         snprintf(was, sizeof(was), "%s/%s/%s",
      |                                                          ^
../src/librc/librc.c:817:25: note: ‘snprintf’ output 3 or more bytes (assuming 4098) into a destination of size 4096
  817 |                         snprintf(was, sizeof(was), "%s/%s/%s",
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  818 |                             file, dir->value, base);
      |                             ~~~~~~~~~~~~~~~~~~~~~~~
../src/librc/librc.c:822:58: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
  822 |                         snprintf(was, sizeof(was), "%s/%s", file, dir->value);
      |                                                          ^
../src/librc/librc.c:822:25: note: ‘snprintf’ output 2 or more bytes (assuming 4097) into a destination of size 4096
  822 |                         snprintf(was, sizeof(was), "%s/%s", file, dir->value);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
@williamh williamh merged commit 70be1c0 into OpenRC:master Jun 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants