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

N°7212 - PHP 8.1: Migrate remaining usages of strlen() with null value #607

Merged
merged 1 commit into from Feb 14, 2024

Conversation

Molkobain
Copy link
Member

Base information

Question Answer
Related to a SourceForge thead / Another PR / Combodo ticket? Combodo N°7212, mentioned in #600
Type of change? Bug fix

Symptom (bug)

Deprecation notice in the logs

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/core/ormcaselog.class.inc.php on line 172

Reproduction procedure (bug)

No real use case so far, only programatically with the following delta.

  1. On iTop 3.1.0
  2. With PHP 8.1.0
  3. Apply following delta
  4. Create new User Request
  5. Change urgency to trigger a ComputeValues
  6. Check that notice is present either in iTop logs or the network panel of the browser
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
  <classes>
    <class id="UserRequest" _delta="must_exist">
      <methods>
        <method id="ComputeValues" _delta="force">
          <static>false</static>
          <access>public</access>
          <type>Overload-DBObject</type>
          <code>
<![CDATA[
public function ComputeValues()
{
  $oLog = new ormCaseLog(null);
  $oLog->GetAsArray();
  $oLog->GetAsEmailHtml();
  $oLog->GetAsSimpleHtml();
  $oLog->GetAsHTML();

  $oDoc = new ormDocument();
  $oDoc->GetSignature();

  parent::ComputeValues();
}
]]>
          </code>
        </method>
      </methods>
    </class>
  </classes>
</itop_design>

Cause (bug)

In some cases, the $m_sLog part of the \ormCaseLog can be null and cause this. But how it can be null is not clear yet.

Proposed solution (bug and enhancement)

Protect code by using \utils::StrLen() instead which was done with that exact purpose in mind.

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have tested all changes I made on an iTop instance
  • Would a unit test be relevant and have I added it?
  • Is the PR clear and detailled enough so anyone can understand digging in the code?

Checklist of things to do before PR is ready to merge

None

@Molkobain Molkobain self-assigned this Feb 2, 2024
@Molkobain Molkobain added bug Something isn't working core internal Work made by Combodo labels Feb 2, 2024
@Molkobain Molkobain added this to the 3.1.2 milestone Feb 2, 2024
@Molkobain Molkobain changed the base branch from develop to support/3.1 February 2, 2024 16:14
@Molkobain
Copy link
Member Author

Accepted during functional review

@Molkobain Molkobain merged commit 0483cea into support/3.1 Feb 14, 2024
1 check failed
@Molkobain Molkobain deleted the issue/7212-php81-strlen-ormcaselog branch February 14, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core internal Work made by Combodo
Projects
None yet
2 participants