This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Add internal implementations for strlcat and strlcpy
ClosedPublic

Authored by zaks.anna on Nov 16 2015, 10:21 AM.

Details

Summary

The compiler-rt should make use of strlcpy() rather than strncpy(). Using internal_strncpy() may be fine with appropriate bounds checking or enforcement of nul-termination elsewhere, but it's just good practice these days to avoid using strncpy() in new code.

A patch by Jeremy Sequoia!

Diff Detail

Repository
rL LLVM

Event Timeline

zaks.anna updated this revision to Diff 40309.Nov 16 2015, 10:21 AM
zaks.anna retitled this revision from to [compiler-rt] Add internal implementations for strlcat and strlcpy.
zaks.anna updated this object.
zaks.anna added reviewers: samsonov, kcc.
zaks.anna added a subscriber: llvm-commits.
kcc edited edge metadata.Nov 16 2015, 11:33 AM

Please clang-format and add tests (to test/sanitizer_common/TestCases)

kcc added a comment.Nov 16 2015, 11:34 AM

I mean, clang-format only the new parts of code.

samsonov edited edge metadata.Nov 17 2015, 4:07 PM

Um, I think we need unit tests for this, they should go to lib/sanitizer_common/tests

Do you plan to actually replace internal_strncpy / internal_strncat in the subsequent changes?

zaks.anna updated this revision to Diff 40468.Nov 17 2015, 6:47 PM
zaks.anna edited edge metadata.

Added tests and re-formatted.

Do you plan to actually replace internal_strncpy / internal_strncat in the subsequent changes?

No. I want to use it in an upcoming patch. Do you think we should replace all uses?

glider added a subscriber: glider.Nov 18 2015, 2:44 AM
glider added inline comments.
lib/sanitizer_common/sanitizer_libc.cc
181 ↗(On Diff #40468)

Nit: missing spaces around '+'

185 ↗(On Diff #40468)

Ditto (also '-')

203 ↗(On Diff #40468)

dst and src must not overlap, but maybe we use memmove() here just to make sure nothing blows up?

zaks.anna updated this revision to Diff 40567.Nov 18 2015, 3:03 PM

Addressed review by glider.

kcc accepted this revision.Nov 18 2015, 3:18 PM
kcc edited edge metadata.

LGTM with one nit

lib/sanitizer_common/tests/sanitizer_libc_test.cc
149 ↗(On Diff #40567)

use

static const size_t kStrlcpyBufSize = 8;
This revision is now accepted and ready to land.Nov 18 2015, 3:18 PM
This revision was automatically updated to reflect the committed changes.