Skip to content

[Device, kindle] early return if kindleGetCurrentProfile() is nil - #14219

Merged
Frenzie merged 4 commits into
koreader:masterfrom
Commodore64user:network-fix
Aug 28, 2025
Merged

Frenzie merged 4 commits into
koreader:masterfrom
Commodore64user:network-fix

Conversation

@Commodore64user

@Commodore64user Commodore64user commented Aug 24, 2025 •

Copy link
Copy Markdown
Member

bug fix

  • Improved error handling in NetworkMgr:getCurrentNetwork() to safely return an empty table if kindleGetCurrentProfile() is nil, preventing possible nil dereference issues.

@NiLuJe needs to bless this one.

fixes #14215


This change is Reviewable

@Frenzie Frenzie added this to the 2025.10 milestone Aug 24, 2025
@NiLuJe

NiLuJe commented Aug 24, 2025 •

Copy link
Copy Markdown
Member

The wpaclient backend seems to be returning nil, err tuples in this case, so I'd rather not deviate from that API and fix it on the other end?

(And, well, honor that bit of API in case of errors here, too).

@NiLuJe

NiLuJe commented Aug 24, 2025

Copy link
Copy Markdown
Member

c.f.,

function WpaSupplicant:getCurrentNetwork()
local wcli, err = WpaClient.new(self.wpa_supplicant.ctrl_interface)
if wcli == nil then
return nil, T(CLIENT_INIT_ERR_MSG, err)
end
-- Start by checking the status before looking for the CURRENT flag...
local nw
nw, err = wcli:getConnectedNetwork()
logger.dbg("WpaSupplicant:getCurrentNetwork: Connected network:", nw and nw or err)
-- Then fall back to the flag check...
if nw == nil then
nw, err = wcli:getCurrentNetwork()
logger.dbg("WpaSupplicant:getCurrentNetwork: Current network:", nw and nw or err)
end
wcli:close()
if nw ~= nil then
nw.ssid = decodeSSID(nw.ssid)
end
return nw
end

Which would imply we just need a nil guard, but we should be able to return nil here, instead of an empty table.

Comment thread frontend/device/kindle/device.lua Outdated
Comment on lines 462 to 463
if not kindleGetCurrentProfile() then return {} end
return { ssid = kindleGetCurrentProfile().essid }

@NiLuJe NiLuJe Aug 24, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not kindleGetCurrentProfile() then return {} end
return { ssid = kindleGetCurrentProfile().essid }
local nw = kindleGetCurrentProfile()
if nw ~= nil then
return { ssid = nw.essid }
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something along those lines (untested).

@NiLuJe NiLuJe Aug 24, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly with fancy debug logging like the WpaClient imp ;o).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fancy enough now?

Comment thread frontend/device/kindle/device.lua Outdated
Comment on lines +462 to +468
local nw = kindleGetCurrentProfile()
if nw ~= nil then
logger.dbg("NetworkMgr:getCurrentNetwork: Current network found")
return { ssid = nw.essid }
end
logger.dbg("NetworkMgr:getCurrentNetwork: No current network profile found")
return nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we normally do this the other way around? (if nil then early return, continue with non-nil)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but I didn't want to make @NiLuJe angry ;)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agreed; the layout in WpaClient is weird for some reason ;).

Comment thread frontend/device/kindle/device.lua Outdated
logger.dbg("NetworkMgr:getCurrentNetwork: No current network profile found")
return nil
end
logger.dbg("NetworkMgr:getCurrentNetwork: Current network found")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could even print nw (or possibly just nw.essid, since IIRC that's the only key in there anyway) ;o).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any potentially incriminating info there, we should be privacy conscious no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an SSID; if people are worried about that, they're probably in the wrong place ;).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fun fact: I have seen people with SSIDs that include their [partial] address and/or family names, no joke. Do we really gain anything from knowing Little Timmy's "stay off my wifi"?

return { ssid = kindleGetCurrentProfile().essid }
local nw = kindleGetCurrentProfile()
if nw == nil then
logger.dbg("NetworkMgr:getCurrentNetwork: No current network profile found")

@Frenzie Frenzie Aug 24, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one says profile and the other doesn't. 👼

@Frenzie
Frenzie merged commit 1ad234d into koreader:master Aug 28, 2025
@Commodore64user
Commodore64user deleted the network-fix branch August 28, 2025 23:24
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

performing my 'turn wifi on' gesture when the wifi is already on crashes koreader.

3 participants