Menu

#5 Error in decodeCharacters

1.0
closed
None
2017-03-31
2017-03-15
Anonymous
No

There is an error in the function "decodeCharacters" in file AbstractDecoderChannel.c, if STRING_REPRESENTATION_ASCII is used.
After decoding all characters, the array will be null terminated by adding '\0' to the last position. If the decoding length is equal to the size of the array this null termination will be written to another memory area which does not belong to the array. You should save one byte more for each array or save the array without null termination because the length is already known.

Discussion

  • Daniel Peintner

    Daniel Peintner - 2017-03-20

    Hi,

    I can confirm this issue.

    When decodeCharacters() is called through decodeStringOnly this extraChar (null terminator) is handled properly. Calling decodeCharacters() directly cannot handle it given that there is no information about the size (just about the length).

    Your are right that the null terminator is not necessary but many people are used to use printf (or similar functions) that require '\0'.

    Having that said, I am in favor of extending the decodeCharacters() call by size also.

    Any thoughts?

    Thanks,

    -- Daniel

     
  • Vera Müller

    Vera Müller - 2017-03-21

    Hi,

    that is right that in decodeStringOnly() the null termination is handled properly. But this function is not called from the decoding functions in the v2gEXIDatatypesDecoder.c file. All decoding functions call directly decodeCharacters().

    If you extend the decodeCharacters by a size, you have to make sure that the string arrays allocate one byte more than the maximum length of the string. Or you just add the null termination if the maximum size is not reached and not return with an error otherwise (but than printf will not work).

    Best regards,
    Vera

     
  • Daniel Peintner

    Daniel Peintner - 2017-03-21

    Hi Vera,

    Thanks for your feedback.

    The "internal" solution so far is to that decodeCharacters() requires to pass the size of the char array also. The internal code reports an error IF the null terminator does not fit into the available space (similar as it was done for decodeStringOnly()).

    I will run some further tests and update the code.. (will also update this ticket once the commti took place)

    Thanks,

    -- Daniel

     
  • Daniel Peintner

    Daniel Peintner - 2017-03-21
    • status: open --> accepted
    • assigned_to: Daniel Peintner
     
  • Daniel Peintner

    Daniel Peintner - 2017-03-21
    • status: accepted --> closed
     
  • Vera Müller

    Vera Müller - 2017-03-22

    Hi,

    thanks for updating the code.
    But now I have the problem, that if I want to decode for example an EVSEID with 37 characters (this is the maxLength), the decoding function returns an error because the length is out of bounds. But according to the scheme 37 characters should be supported.

    Best regards,
    Vera

     
  • Daniel Peintner

    Daniel Peintner - 2017-03-22

    Hi,

    Thanks for pointing me to this issue again. I will change the according #define's as the one you alluded for EVSEID as follows.

    From

    define v2gAC_BidirectionalControlResType_EVSEID_CHARACTERS_SIZE 37

    to

    define v2gAC_BidirectionalControlResType_EVSEID_CHARACTERS_SIZE + EXTRA_CHAR

    EXTRA_CHAR will be set 0 or 1 depending on whether we use ASCII and need null terminator or UCS without any extra char.

    I think this resolves the issue. What do you think?

    Thanks,

    -- Daniel

     
  • Daniel Peintner

    Daniel Peintner - 2017-03-22
    • status: closed --> pending
     
  • Vera Müller

    Vera Müller - 2017-03-22

    Hi Daniel,

    I think that would be a good solution.

    Best regards,
    Vera

     
  • Daniel Peintner

    Daniel Peintner - 2017-03-23

    Hi Vera,

    I did check-in the afore discussed solution.
    Please let me know whether this resolves your issue.

    -- Daniel

    P.S. Note: The structure & naming of the project and its functions has been changed also a bit

     
  • Vera Müller

    Vera Müller - 2017-03-31

    Hi Daniel,

    thanks for fixing this problem. This resolves my issue :)

    • Vera
     
  • Daniel Peintner

    Daniel Peintner - 2017-03-31

    Thank you!

     
  • Daniel Peintner

    Daniel Peintner - 2017-03-31
    • status: pending --> closed
     

Log in to post a comment.