Skip to content

security: Add NULL check to nmea_validate_checksum() #60

@gdellis

Description

@gdellis

Problem

nmea_validate_checksum() in firmware/main/nmea_parser.hpp:78 passes nmea to memchr() without checking if it's NULL first:

inline bool
nmea_validate_checksum (const char* nmea, size_t len) {
    const char* checksum_ptr = (const char*)memchr (nmea, '*', len);

If nmea is NULL, this is undefined behavior. While nmea_parse() checks len < 6 || nmea[0] != '$', if nmea is NULL then nmea[0] would be UB before that check.

Severity

LOW - Only reachable if caller passes NULL, which current callers don't do.

Suggested Fix

Add NULL check at start of function:

inline bool
nmea_validate_checksum (const char* nmea, size_t len) {
    if (!nmea) {
        return false;
    }
    // ... rest of function

This is a pre-existing issue noted in PR #53 review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions