Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58919204 authored by Gopalakrishnan Nallasamy's avatar Gopalakrishnan Nallasamy
Browse files

ASessionDescription:Invalid index in Parse()

Usage of find("=") at line 143 is redundant as equalPos would be 1 always because of the
conditional check at lines,
79        if (line.size() < 2 || line.c_str()[1] != '=') {
80          return false;
        }

However, keeping the find("=") code as it is because in case if someone changes line 79/80 later,
still the code at 143 should be robust. Hence added a conditional check
to make return false when equalPos < 0.

Bug: 111681250

Test: Clean up code.

Change-Id: I8bd90da39e2df8ede8bab5712911bcf0fbe28a8a
parent 02a8b88c
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -141,6 +141,12 @@ bool ASessionDescription::parse(const void *data, size_t size) {
                AString key, value;
                AString key, value;


                ssize_t equalPos = line.find("=");
                ssize_t equalPos = line.find("=");
                /* The condition 'if (line.size() < 2 || line.c_str()[1] != '=')' a few lines above
                 * ensures '=' is at position 1.  However for robustness we do the following check.
                 */
                if (equalPos < 0) {
                    return false;
                }


                key = AString(line, 0, equalPos + 1);
                key = AString(line, 0, equalPos + 1);
                value = AString(line, equalPos + 1, line.size() - equalPos - 1);
                value = AString(line, equalPos + 1, line.size() - equalPos - 1);