Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SGWT.mobile - URI Builder may cause infinite loop

    Using SGWT.mobile release from 23.01.12.

    For creating a query out of the POST parameters, the class URIBuilder.java includes the following loop (starting line 180):

    Code:
                for (; pos < qsEndPos && (pos = uri.indexOf(prefix, pos)) != -1; prevPos = pos) {
                    assert pos >= 1;
                    if (uri.charAt(pos - 1) == '&' || uri.charAt(pos - 1) == '?') {
                        int ampPos = uri.indexOf('&', pos + prefix.length());
    
                        sb.append(uri, prevPos, pos);
    
                        if (ampPos != -1 && ampPos < qsEndPos) {
                            pos = ampPos + 1;
                        } else {
                            pos = qsEndPos;
                            sb.deleteCharAt(sb.length() - 1);
                        }
                        continue;
                    }
                    sb.append(uri, prevPos, pos);
                }
    A problem may occur with the first line. indexOf() searches the URI for the first occurence of the given prefix. If that prefix is also part of another parameter (example parameters: car, mycar), the loop ends up in infinity.
    A solution is to use lastIndexOf() instead.

    cheers,
    Markus

    #2
    Thanks for pointing this out, it's fixed for the next nightly.

    Comment

    Working...
    X