Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(windows): fix crash in GetCellularGeneration for some LTE network adapters #660

Merged
merged 1 commit into from Mar 29, 2023

Conversation

aironefr
Copy link
Contributor

Overview

Some users are facing this crash: 0xC0000005: Access violation reading location 0x0000000000000000.
When inspecting crash dump, last stack trace in RNCNetInfo is RNCNetInfo.cpp:62

Root cause

These impacted users had LTE network adapter cards marked as LteAdvanced | Custom which isn't support by current RNCNetInfo implementation as dataClass wasn't treated as an enum supporting flags.

So nullptr was assigned to std::optional<std::string> and since the optional object is considered initialized when assigning nullptr then when dereferencing the value, it led to null pointer exception.

Fix

  • Use std::nullopt instead of nullptr for unknown class types.
  • Don't use switch but use bitwise comparison to detect class type

Crash

image

Test Plan

Quickly reproed the crash then verified std::nullopt works.
We already applied this patch to our application and rolled it out to our users who validated the fix.

Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

I'm not sure I like the change from switch/case to if/else if/else (just aesthetically - but if it's functional okay), but I love people that post PRs that contain triaged bug fixes and code working in production. Thank you!

@mikehardy mikehardy merged commit 7e1c7fb into react-native-netinfo:master Mar 29, 2023
2 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 29, 2023
## [9.3.8](v9.3.7...v9.3.8) (2023-03-29)

### Bug Fixes

* **windows:** fix crash in GetCellularGeneration for some LTE network adapters ([#660](#660)) ([7e1c7fb](7e1c7fb))
@matt-oakes
Copy link
Collaborator

🎉 This PR is included in version 9.3.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants