Page MenuHomeFreeBSD

Convert copystr to strlcpy
Needs ReviewPublic

Authored by cracauer on Mon, Mar 30, 11:02 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Mar 31, 3:43 AM
Unknown Object (File)
Mon, Mar 30, 11:33 PM
Subscribers

Details

Reviewers
mhorne
Summary

Convert the last users of copystr that were not using the length
argument to strlcpy.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 71894
Build 68777: arc lint + arc unit

Event Timeline

sys/dev/vmm/vmm_dev.c
274–277

Strlcpy returns the number of characters that would be copied if dst is large enought. Not an error

Correctly deal with return value.

mhorne requested changes to this revision.Tue, Mar 31, 4:19 PM
mhorne added a subscriber: mhorne.

Hi, thanks for taking this on, it would be nice to see this conversion completed.

Most important: the order of 'src' and 'dest' is reversed between copystr() and strlcpy(). You have not accounted for this.

Second: there are more instances of copystr() in the tree needing conversion that do not yet appear in this patch.

sys/dev/vmm/vmm_dev.c
274–277

Clever, but not quite right. In this case, error is propagated upwards, and eventually returned to userspace. We need to take care to set a real error code, not a boolean value.

You can see that copystr() is defined as a macro (in sys/systm.h) as a wrapper for strlcpy(). So in each of these instances the goal is likely to de-inline that macro, returning ENAMETOOLONG wherever it does now.

Similar advice applies below.

This revision now requires changes to proceed.Tue, Mar 31, 4:19 PM

Yeez, that was a bad shot from the hip. Sorry about that.

Give me some time and I do the complete thing with those cases that do use the length return argument, too,. Just not late at night.

It's worse. copystr and strlcpy also have a different
idea of what string length means. Taken into account now.