[PATCH] get_interfaces() return early causes segfault in winbind
David Mulder
dmulder at suse.com
Thu Oct 25 18:46:34 UTC 2018
How about this instead:
above */
int get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces)
{
- struct iface_struct *ifaces;
+ struct iface_struct *ifaces = NULL;
int total, i, j;
total = _get_interfaces(mem_ctx, &ifaces);
/* If we have an error, no interface or just one we can leave */
if (total <= 1) {
+ *pifaces = ifaces;
return total;
}
Initialize ifaces to NULL, then always set pifaces to ifaces? The
initialization is necessary since _get_interfaces() returns without
changing ifaces if there are no interfaces.
On 10/25/2018 12:31 PM, Volker Lendecke via samba-technical wrote:
> On Thu, Oct 25, 2018 at 09:18:53AM -0600, David Mulder via samba-technical wrote:
>> Regression caused by da68a1b2f417ec82ea4ed3e7a4d867cef8ca8f93.
>>
>> If we return early, be sure to point pifaces to the returned ifaces if
>> we have 1 return. Otherwise winbind segfaults in load_interfaces() if
>> there is only 1 interface, because we say there is 1 interface, but
>> ifaces is NULL (load_interfaces() tries to smb_memdup NULL of iface size 1).
>>
>> Seen on a machine where dhcp was slow to return, so winbind crashed on
>> started due to lo being the only interface available on start.
>>
>> Please review and push if ok!
> Looks right. A little stylistic comment:
>
>> - if (total <= 1) {
>> + if (total <= 0) {
>> + return total;
>> + } else if (total == 1) {
>> + *pifaces = ifaces;
> Can we just remove the "else"? We do the early return in the first
> clause, we don't need an "else".
>
> Volker
>
--
David Mulder
SUSE Labs Software Engineer - Samba
dmulder at suse.com
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lib-socket-If-returning-early-set-ifaces.patch
Type: text/x-patch
Size: 1103 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20181025/dab7c9ea/0001-lib-socket-If-returning-early-set-ifaces.bin>
More information about the samba-technical
mailing list