Suitecrm: Division by zero in ListViewSmarty.php

Created on 25 Sep 2019  路  5Comments  路  Source: salesagility/SuiteCRM

Issue

I noticed this warning in my PHP error logs today:

PHP Warning: Division by zero in /Users/connorshea/code/sites/SuiteCRM/include/ListView/ListViewSmarty.php on line 145

Because of the change in 8f0701459e0cd448fc2e2d1546df065fd173ef97, the $adjustment variable can now be 0, which makes $this->displayColumns[$name]['width'] = floor(((int)$this->displayColumns[$name]['width']) / $adjustment); create a division-by-zero error.

Expected Behavior

No division by zero.

Actual Behavior

PHP Warning: Division by zero in /Users/connorshea/code/sites/SuiteCRM/include/ListView/ListViewSmarty.php on line 145

Possible Fix

Change this:

$this->displayColumns[$name]['width'] = floor(((int)$this->displayColumns[$name]['width']) / $adjustment);

to this:

if ($adjustment === 0) {
    $this->displayColumns[$name]['width'] = 0;
} else {
    $this->displayColumns[$name]['width'] = floor(((int)$this->displayColumns[$name]['width']) / $adjustment);
}

Steps to Reproduce

  1. Go to the Admin panel.
  2. Go to "OAuth clients and tokens".
  3. You're now at the page that should have the issue.
  4. You may need to create a client/token for this error to occur, so if you don't see the 'division by zero' error in your PHP error log at this point, try that and then go back to the list view.

Context

Warnings are annoying :)

I think the reason this occurs on the OAuth clients/tokens page specifically is because there are no widths defined, so it'd work for any module with columns that have no explicit width:

https://github.com/salesagility/SuiteCRM/blob/df18433e4bd429ecd754953a6354e38f37893efd/modules/OAuth2Clients/metadata/listviewdefs.php#L46-L62

Your Environment

  • SuiteCRM Version used: SuiteCRM 7.10.19
  • Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Firefox 70
  • Environment name and version (e.g. MySQL, PHP 7): MySQL 5.7, PHP 7.2
  • Operating System and version (e.g Ubuntu 16.04): macOS Mojave 10.14.6
Moderate Fix Proposed Bug

All 5 comments

Hey! I'd like to work on that if it's ok with you. :)

@Kishlin go for it!

Messed up with the branches a bit but PR is now up. :D
https://github.com/salesagility/SuiteCRM/pull/7950

This should be marked as 'resolved in next release'

This is resolved now.

Was this page helpful?
0 / 5 - 0 ratings