Opened 2 years ago

Closed 2 years ago

#13522 closed bug (invalid)

BNetworkAddress::SetTo() doesn't store some error cases.

Reported by: anevilyak Owned by: pulkomandy
Priority: normal Milestone: Unscheduled
Component: Kits/Network Kit Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description (last modified by anevilyak)

In several of BNetworkAddress's SetTo variants, there are error conditions that are returned, but not stored on fStatus. Consequently, if the address was set via the constructor, these errors may go undetected by subsequent calls to InitCheck().

For instance, at http://cgit.haiku-os.org/haiku/tree/src/kits/network/libnetapi/NetworkAddress.cpp#n165

If either Resolver.Get() or Resolver->InitCheck() fail, the result is not stored on fStatus.

Since the above example is consistent across every SetTo() that requires the use of the resolver, I was uncertain if the behavior was deliberate for that case, and thought it best to report it.

Change History (3)

comment:1 by anevilyak, 2 years ago

Description: modified (diff)
Owner: changed from nobody to pulkomandy
Status: newassigned

comment:2 by pulkomandy, 2 years ago

The reasoning for this code is that when SetTo fails in these cases, the object preserves its previous state. So, SetTo failed, but the object is still valid (or invalid) with the data that was in it before.

The constructors using this SetTo method do set fStatus with the SetTo return value, so InitCheck can be used safely in that case.

There isn't really a need to preserve this behavior, in case of errors in SetTo, we could then call Unset() and set fStatus to the error code, allowing use of SetTo + InitCheck.

comment:3 by anevilyak, 2 years ago

Resolution: invalid
Status: assignedclosed

I overlooked that, my mistake. Some of the constructors blindly call SetTo and rely on it to handle fStatus, didn't see that these don't.

Note: See TracTickets for help on using tickets.