Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000260 [Yate - Yet Another Telephony Engine] engine minor have not tried 2011-05-13 18:08 2011-05-13 19:40
Reporter folarte View Status public  
Assigned To
Priority normal Resolution open  
Status new   Product Version SVN
Summary 0000260: Encoding / decoding of messages is not coherent.
Description When developing a conector for the extmodule system y browsed at the engin/Message.cpp to gain understanding in the exact way to make %-escaping and noticed this:

void Message::commonEncode(String& str) const
{
    str << msgEscape() << ":" << m_return.msgEscape();
    unsigned n = length();
    for (unsigned i = 0; i < n; i++) {
        NamedString *s = getParam(i);
        if (s)
            str << ":" << s->name().msgEscape('=') << "=" << s->msgEscape();
    }
}

Here the name-value params pair are escaped before being joined by =, but a little below, in

int Message::commonDecode(const char* str, int offs)

I've found:

        chunk = chunk.msgUnescape(&err);
        if (err >= 0)
            return offs+err;
        int pos = chunk.find('=');
        switch (pos) {
            case -1:
                clearParam(chunk);
                break;
            case 0:
                return offs+err;
            default:
                setParam(chunk.substr(0,pos),chunk.substr(pos+1));
        }

that the whole chunk is unescaped before being split. From my understanding of the code this could lead to an incoherency if I encode 'A=B' => 'C' it will be escaped to 'A%UB=C' then unescaped to 'A=B=C' and decoded as 'A' => 'B=C'.

This is a very minor problem, if it is, as no '=' are normally found on the names, but given that the code goes to the trouble of unescaping the name I thought it would be better to report it.

I'm not confortable enough to try to patch the Message class, but I think it can be solved easily by doing

        int pos = chunk.find('=');
        switch (pos) {
            case -1:
                chunk = chunk.msgUnescape(&err);
                if (err >= 0)
                    return offs+err;
                clearParam(chunk);
                break;
            case 0:
                // return offs+err;
                return offs;
            default:
                String name=chunk.substr(0,pos).msgUnscape(&err);
                if (err>=0)
                     return offs+err;
                String value=chunk.substr(pos+1).msgUnscape(&err);
                if (err>=0)
                     return offs+pos+1+err;
                setParam(name, value);
        }

that is, posponing unescaping until after splitting.


Additional Information Seen in Yate 3.3.2 sources, combo only lets me choose 1, 2 or SVN
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0000375)
folarte (reporter)
2011-05-13 19:40

Misread 125 in ascii chart, used octal instead of dec. '=' escapes to '%}' not '%U', makes no difference in the spirit of the report.

- Issue History
Date Modified Username Field Change
2011-05-13 18:08 folarte New Issue
2011-05-13 19:40 folarte Note Added: 0000375


Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker