Skip to content

Avoid strlen(null) call on undefined "idvisitor" property #22991

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

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

mbrodala
Copy link
Contributor

@mbrodala mbrodala commented Jan 28, 2025

The "idvisitor" property can be undefined/null, this must be taken into account to avoid this error:

strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /.../core/Tracker/Visit.php on line 583

Description:

Please include a description of this change and which issue it fixes. If no issue exists yet please include context and what problem it solves.

Review

The "idvisitor" property can be undefined/null, this must be taken into account to avoid this error:

> strlen(): Passing null to parameter matomo-org#1 ($string) of type string is deprecated in /.../core/Tracker/Visit.php on line 583
@michalkleiner
Copy link
Contributor

Hi @mbrodala. Thanks for creating the PR. Can you share some more information on under what circumstance the visitorid can be null or undefined? Do we rather need to ensure it's never set as empty or undefined to the visit properties?

@mbrodala
Copy link
Contributor Author

We are tracking a regular page view request and saw this message in the matomo.php response/output. It's a server-side request without any client data, so no cookies or similar.

There are various other checks in this class to avoid an empty/undefined idvisitor property, so I assume this is an expected case.

Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

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

Good find @mbrodala and yeah, I can confirm other places in the class do do a check for the visit property to not be empty. We can adjust the code so the check is done in a similar way here as well.

This is more in line with other locations in this class.

Co-authored-by: Michal Kleiner <mk@011.nz>
@michalkleiner michalkleiner added Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review c: Tracking For issues related to getting tracking data into Matomo. labels Jan 28, 2025
@michalkleiner michalkleiner added this to the 5.3.0 milestone Jan 28, 2025
Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'll merge this once the tests finish green.

@sgiehl sgiehl merged commit 0e9af13 into matomo-org:5.x-dev Feb 3, 2025
22 of 26 checks passed
@mbrodala mbrodala deleted the patch-1 branch February 3, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. c: Tracking For issues related to getting tracking data into Matomo. Needs Review PRs that need a code review
Development

Successfully merging this pull request may close these issues.

3 participants