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

Division by 0 in header_authenticated.php #3154

Closed
enginelesscc opened this issue Oct 1, 2024 · 3 comments
Closed

Division by 0 in header_authenticated.php #3154

enginelesscc opened this issue Oct 1, 2024 · 3 comments
Labels

Comments

@enginelesscc
Copy link

Info

I initially wanted to open a PR but the guidelines got me a bit unsure given this affects v5 only while v6 is lua now and doesnt have the affected code..

But I found it may still be useful to post for anyone currently affected until v6 is released.

The simple fix for this is here:

pi-hole/web/commit/bbcf9fa857002010d3c61c04f90a35ec6c31cea2

Versions

  • Pi-hole: v5.18.3
  • AdminLTE: v5.21
  • FTL: v5.25.2

Platform

  • OS and version: Debian Sid
  • Platform: LXD/Incus container

Expected behavior

Functional Webinterface / data validation

Actual behavior / bug

/proc/meminfo may return no data in a linux container (in my case: incus), causing the $data array to be incomplete.
This resulted in a division by 0 error trying to divide by non-existant $meminfo['MemTotal'].
This meant pihole-web was unusable (error 500).

Steps to reproduce

n/A

Debug Token

n/A

Screenshots

n/A

Additional context

n/A

@rdwebdesign
Copy link
Member

Thank you for the information.

Reading the code, it's obvious that a "Division by 0" will happen if $meminfo['MemTotal'] is zero (nice catch), but to be honest, you are probably the only user facing this issue, because we've never received similar complaints.

It is very unlikely that there will be another v5 release. As you noticed, the current code in development branch is for Pi-hole v6.

I will keep this issue open until we release v6, so other users can use your fix, if needed.


Why did you change line 44?
This is not needed to fix the issue and I don't think it will be possible to have less than 4 lines if /proc/meminfo exists.

@enginelesscc
Copy link
Author

Why did you change line 44?

Because an empty /proc/meminfo results in an array(1) { [0] = "" }.

Meaning the previous > 0 check was always evaluating to true.

Therefore I made the assumption more specific to contain at-least as many elements as accessed. (So we hit our else branch here setting -1)

The max() is an additional case to avoid err 500 if /proc/meminfo returns bogus data.

Both changes seemed valid to me^

Copy link
Contributor

github-actions bot commented Nov 1, 2024

This issue is stale because it has been open 30 days with no activity. Please comment or update this issue or it will be closed in 5 days.

@github-actions github-actions bot added the stale label Nov 1, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants