Java-OCA-OCPP icon indicating copy to clipboard operation
Java-OCA-OCPP copied to clipboard

Validation crash in setIdTag in StopTransaction

Open emilm opened this issue 2 years ago • 1 comments

idtag in stoptransaction is optional , so ModelUtil.validate() will check string != null . If it is null, it will return false. When ModelUtil.validate() returns false, then idTag.length() crashes. How many more cases of this could there be?

  /**
   * Optional. This contains the identifier which requested to stop the charging. It is optional
   * because a Charge Point may terminate charging without the presence of an idTag, e.g. in case of
   * a reset. A Charge Point SHALL send the idTag if known.
   *
   * @param idTag a String with max length 20
   */
  @XmlElement
  public void setIdTag(String idTag) {
    if (!ModelUtil.validate(idTag, 20)) {
      throw new PropertyConstraintException(idTag.length(), "Exceeded limit of 20 chars");
    }

    this.idTag = idTag;
  }

My proposal is to add if idTag != null && in the check:

  if (idTag != null && !ModelUtil.validate(idTag, 20)) { ... 

emilm avatar Feb 10 '23 22:02 emilm

Took the liberty of doing a quick pullrequest based on your suggestion :)

mmauksch avatar Aug 17 '23 11:08 mmauksch