Page MenuHomeFreeBSD

lib/libsbuf: add regression tests for sbuf_printf overflow
AcceptedPublic

Authored by souradiptodas6_gmail.com on Mon, Apr 20, 4:02 PM.
Tags
Referenced Files
F153982304: D56529.diff
Sat, Apr 25, 6:14 AM
F153893376: D56529.diff
Fri, Apr 24, 2:23 PM
Unknown Object (File)
Tue, Apr 21, 3:16 PM
Subscribers

Details

Reviewers
ngie
Group Reviewers
committers
tests
Summary

Added test cases to sbuf_string_test.c to validate libsbuf behavior during buffer overflow and error states.

1> sbuf_printf_overflow: Verifies that data is safely truncated and the ENOMEM error code is set when a fixed-length buffer is exceeded.

2> sbuf_printf_test: Validates that sbuf_printf correctly returns -1 when an overflow occurs.

These tests ensure that the string buffer library remains robust against edge cases.

Test Plan

1> Compiled the tests on FreeBSD (CURRENT/14).

2> Ran the tests using atf-run (or via make tests).

3> Verified that all test cases passed and correctly caught the intended error states.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

ngie added a subscriber: ngie.
ngie added inline comments.
lib/libsbuf/tests/sbuf_string_test.c
296

Please add a newline before this.

This revision is now accepted and ready to land.Mon, Apr 20, 9:07 PM
erj added inline comments.
lib/libsbuf/tests/sbuf_string_test.c
293

The man page says the preferred way to check for an sbuf error is to use the return value from sbuf_finish(); maybe that could be another test case to add.

300

Why not keep this consistent with the test case above and use buf?

Updated the diff to include the sbuf_finish test case, corrected variable naming for consistency, and added the newline on the desired place. Thank you for the guidance and suggestions . Ready for further review.

This revision now requires review to proceed.Tue, Apr 21, 3:37 AM
This revision is now accepted and ready to land.Wed, Apr 22, 4:22 AM