Page MenuHomeFreeBSD

libstand: verify value provided by nfs.read_size
ClosedPublic

Authored by tsoome on Nov 10 2016, 1:49 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 11, 3:35 PM
Unknown Object (File)
Mon, Nov 11, 3:12 PM
Unknown Object (File)
Mon, Nov 11, 9:28 AM
Unknown Object (File)
Sun, Nov 3, 7:26 PM
Unknown Object (File)
Fri, Oct 25, 2:01 AM
Unknown Object (File)
Wed, Oct 23, 9:27 PM
Unknown Object (File)
Thu, Oct 17, 9:11 AM
Unknown Object (File)
Wed, Oct 16, 2:35 AM
Subscribers

Details

Summary

Implement simple value check and feedback.

Diff Detail

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

Event Timeline

tsoome retitled this revision from to libstand: verify value provided by nfs.read_size.
tsoome updated this object.
tsoome edited the test plan for this revision. (Show Details)
tsoome added reviewers: allanjude, imp.

Should be *env == '\0' ...

julian added a reviewer: julian.
julian added a subscriber: julian.

looks reasonable, but am unsure of all the possible cases for *end given garbage input

This revision is now accepted and ready to land.Nov 10 2016, 2:32 PM
tsoome edited edge metadata.

Add notification about resetting the value for nfs_read_size.

This revision now requires review to proceed.Nov 11 2016, 6:32 PM
tsoome edited edge metadata.

Factored out the set_nfs_read_size(), as the r305588 did miss the fact
we have not one but two versions of nfs_getrootfh() and we need to set
the nfs_read_size in both.

Since we can ignore the user provided value, reset the environment
with actually used value so we will not get the repeated messages about
bad value.

rpokala requested changes to this revision.Mar 15 2017, 9:04 PM
rpokala added inline comments.
lib/libstand/nfs.c
228 ↗(On Diff #23192)

nfs_read_size is (int); while strtol() returns (long); cast accordingly.

229 ↗(On Diff #23192)

Is it legal to check for non-zero errno? I thought errno in general is only set to a non-zero value of failure, but not set to zero on success. So, a previous failure would set errno to non-zero, and it would stay non-zero even if the getenv() succeeded.

This revision now requires changes to proceed.Mar 15 2017, 9:04 PM
tsoome edited edge metadata.
tsoome marked an inline comment as done.

Typo in errno name and casting to int.

lib/libstand/nfs.c
228 ↗(On Diff #23192)

well, the compiler should take care, but I do not mind anyhow:)

229 ↗(On Diff #23192)

I set it 0 at line 227 (modulo typo;), so w have it set 0 just before the call to strtol.

lib/libstand/nfs.c
229 ↗(On Diff #23192)

Right, but I'm not sure that's actually legal. I know in some contexts errno is actually a function-like macro or something wacky, so for example different threads don't stomp on it. Granted, that might not be relevant in the context of the bootloader. :-)

In any case, the rule I learned is "never set errno to zero, only to non-zero on failure".

lib/libstand/nfs.c
229 ↗(On Diff #23192)

Well yes, standalone boot is a special environment and as here we run as one big single threaded app, there is nothing to reset it for us and since libstand does not reset it either, we can have errno set anywhere else and not in strtol() so we can end up having errno == ERANGE from anywhere but strtol() itself:)

This revision is now accepted and ready to land.Mar 15 2017, 9:44 PM
This revision was automatically updated to reflect the committed changes.