Page MenuHomeFreeBSD

ufs/extattr.h: Fix documentation of ea_name termination
ClosedPublic

Authored by cem on Jan 17 2017, 4:03 AM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 25 2024, 1:24 PM
Unknown Object (File)
Feb 22 2024, 7:44 PM
Unknown Object (File)
Jan 6 2024, 6:24 PM
Unknown Object (File)
Jan 6 2024, 6:24 PM
Unknown Object (File)
Jan 6 2024, 6:24 PM
Unknown Object (File)
Dec 22 2023, 9:19 PM
Unknown Object (File)
Nov 15 2023, 3:55 AM
Unknown Object (File)
Nov 14 2023, 1:39 PM
Subscribers
None

Details

Summary

The ea_name string is not nul-terminated. Correct the documentation.

Because the subsequent field is padded to 8 bytes, and the padding is
zeroed, the ea_name string will appear to be nul-terminated whenever the
length isn't exactly one (mod eight).

This was introduced in r167010 (2007).

No functional change.

PR: 216127
Reported by: dewayne at heuristicsystems.com.au
Sponsored by: Dell EMC Isilon

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

cem retitled this revision from to ufs/extattr.h: Fix documentation of ea_name termination.
cem updated this object.
cem edited the test plan for this revision. (Show Details)
cem added reviewers: mckusick, kib.

Additionally, mark the length fields as unsigned. This particularly matters
for the single byte ea_namelength field, which can represent extended attribute
names up to 255 bytes long.

share/man/man5/fs.5
417 ↗(On Diff #24099)

Use sizeof() - 1 ?

419 ↗(On Diff #24099)

There too.

sys/ufs/ufs/extattr.h
81 ↗(On Diff #24099)

Add a line before the content comment, mentioning the padding ?

112 ↗(On Diff #24099)

Why removing it ? Even if the macro no longer used in the tree, it is still seems to be useful and might be used by third-party code.

share/man/man5/fs.5
417 ↗(On Diff #24099)

Sure, although I expect modern compilers will already compute this constant at compile time for strlen of string constants.

In practice, I'm not sure these examples are helpful anyway. Maybe they can just be removed? In the restore code I sprintf the ea_name into a nul-terminated string in one place and just use that instead. You need a nul-terminated name for the extattr_set calls anyway.

sys/ufs/ufs/extattr.h
81 ↗(On Diff #24099)

Good idea.

112 ↗(On Diff #24099)

It relies upon strlen(ea_name), which is invalid in general. (It is only valid if you create such a structure with strcpy(ea_name, blah).) I think use of strlen(ea_name) suggests that ea_name is nul-terminated, and there's no need for confusion about it.

And, the macro was never used in the tree.

cem marked 4 inline comments as done.
  • Use sizeof()-1 in place of strlen() of a constant
  • Mention alignment padding in extattr struct after ea_name
  • Update fs.5 copy of struct extattr from ufs/ufs/extattr.h
kib edited edge metadata.
This revision is now accepted and ready to land.Jan 17 2017, 5:34 PM
This revision was automatically updated to reflect the committed changes.