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°7213 - PHP 8.1: Migrate remaining usages of md5() with null value #608

Merged
merged 2 commits into from Feb 14, 2024

Conversation

Molkobain
Copy link
Member

@Molkobain Molkobain commented Feb 2, 2024

Base information

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

Symptom (bug)

Deprecation notice in the logs

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

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_data property of the \ormDocument 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 the coalesce operator (??) to use '' instead of null in the md5().

My opinion was that the 2 usages are for fingerprint / signature / cache buster, so we should return a signature even for an empty content as when the content would change, it signature / fingerprint will as well.

  • \ormDocument::GetSignature():
    • Used to generate the secret so a document can be accessed via a URL without authentication
    • Also used to invalidate browser cache if the document content has changed
  • AttributeBlob::Fingerprint()
    • Used to compare 2 document, so if both are empty, generating the same MD5 through an empty string will be fine

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 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 self-assigned this Feb 2, 2024
@Molkobain Molkobain changed the base branch from develop to support/3.1 February 2, 2024 16:14
@piRGoif
Copy link
Contributor

piRGoif commented Feb 5, 2024

\ormDocument::GetSignature is used in multiple places to build URL to the content.
\AttributeBlob::Fingerprint is used in \DBObjectSetComparator::ComputeFingerprints
So for the second use, having the same generated signature for both null and empty string values should be ok.

@Molkobain
Copy link
Member Author

Accepted during support PRs review

@Molkobain
Copy link
Member Author

Accepted during functional review

@Molkobain Molkobain merged commit 922a842 into support/3.1 Feb 14, 2024
1 check passed
@Molkobain Molkobain deleted the issue/7213-php81-md5-ormdocument branch February 14, 2024 18:27
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
3 participants