Skip to content

iOS crash: NULL pointer dereference in handleMarkerClick due to nil marker.snippet #559

@christian-apollo

Description

@christian-apollo

Bug Description

Tapping a GMSMarker whose snippet property is nil causes a crash on iOS due to a null pointer dereference in _platform_strlen.

Steps to Reproduce

  1. Add a marker to the map without setting a snippet (only position, title, etc.).
  2. Tap the marker.
  3. App crashes.

Crash Stack Trace

Crashed: com.apple.main-thread
0  libsystem_platform.dylib       _platform_strlen + 4
1  ApolloScooters                 std::__1::basic_string<char, ...>::basic_string(char const*) + 63
2  ApolloScooters                 -[NavView handleMarkerClick:] + 350 (NavView.mm:350)
3  ApolloScooters                 -[NavViewController mapView:didTapMarker:] + 311 (NavViewController.mm:311)
4  CoreFoundation                 ...
7  ApolloScooters                 -[GMSDelegateForward forwardInvocation:]
10 ApolloScooters                 -[GMSMapView didTapMarker:]

Root Cause

In NavView.mm, both handleMarkerClick: and handleMarkerInfoWindowTapped: pass [marker.snippet UTF8String] directly to a std::string field in the event struct.

When marker.snippet is nil (the default for GMSMarker), Objective-C nil messaging returns NULL from UTF8String. The std::string(const char*) constructor then calls strlen(NULL), which is undefined behavior and crashes in _platform_strlen.

marker.title is already correctly guarded with a nil check on the lines above, but marker.snippet is not:

// title — correctly guarded ✓
marker.title != nil ? [marker.title UTF8String] : "",
marker.opacity,
marker.rotation,
// snippet — NOT guarded ✗ → crash when nil
[marker.snippet UTF8String],

Suggested Fix

Add the same nil guard used for title to snippet in both methods:

- [marker.snippet UTF8String],
+ marker.snippet != nil ? [marker.snippet UTF8String] : "",

This needs to be applied in two places in NavView.mm:

  • handleMarkerInfoWindowTapped: (line ~337)
  • handleMarkerClick: (line ~349)

Environment

  • @googlemaps/react-native-navigation-sdk version: 0.14.2
  • Platform: iOS (arm64)
  • React Native: 0.83.4

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions