There is a bug in function c_find_context maybe

Asked by xygbq on 2013-09-17

hi , dear professor!

Maybe I understand errorly, I find there is a bug in function c_find_context.
some codes in this function as follow:
for( i=0; i<com->num_contexts; i++)
{
      c = comp->context[i];
      if( c && c->used && c->profile->id == profile->id)
      {
            ret = c->proflie->check_context(c, ip);
             if( ret == -1)
             {
                   c = (struct c_context*) -1;
                   break; /* I do not understand why beak out the loop here, maybe in the comp->context array there is another comp->context[i] fill the condition as ( c && c->used && c->profile->id == profile->id), if there is, maybe that's the context we want to find, so we shouldn't beak out here, isn't it? */
              }
      .
      .
      .
}

Question information

Language:
English Edit question
Status:
Solved
For:
rohc Edit question
Assignee:
No assignee Edit question
Solved by:
xygbq
Solved:
2013-09-19
Last query:
2013-09-19
Last reply:
2013-09-17

Hello,

There is no bug. If c->profile->check_context(c, ip) returns -1, it means that the profile is unable to compress the packet. In such case, all next c->profile->check_context(c, ip) calls will return -1 too, so better break the loop.

Such a case may happen if you try to compress a malformed packet for example. If so, another compression profile is used instead of the current one, eg. the Uncompressed profile that accepts any packet (even non-IP packets).

Regards,
Didier

Note: you're using one 1.5.x version of the library (this code changed since then), you might want to read the source code of newer versions (1.6.1) or even the dev branch if you want to make some modifications on the library.

xygbq (39452929-g) said : #2

Hi, dear professor,

 If c->profile->check_context(c, ip) returns -1, it doesn't mean that the profile is unable to compress the packet, it means that the profile in this context is unable to compress the packet, but there may be the same profile in another context can compress the ip packet. eg.function c_esp_check_context will return -1 because the number of ip headers is not the same as in the context, but you can't say there isn't another context
which has the fit profile has the same number of ip headers as in the ip packet.

Hello,

> If c->profile->check_context(c, ip) returns -1, it doesn't mean that
> the profile is unable to compress the packet, it means that the profile
> in this context is unable to compress the packet,

No, it doesn't mean that. Please check the code and the description of the c_ip_check_context() or c_esp_check_context() functions for example. Return code 1 means that profile and context match. Return code 0 means that profile matches but context don't. Return code -1 means that profile and context do not match.

Snippet of code:
 * @return 1 if the IP/ESP packet belongs to the context,
 * 0 if it does not belong to the context and
 * -1 if the profile cannot compress it or an error occurs

> but there may be the same profile in another context can compress
> the ip packet. eg.function c_esp_check_context will return -1 because
> the number of ip headers is not the same as in the context, but you
> can't say there isn't another context which has the fit profile has the
> same number of ip headers as in the ip packet.

That's true for return code 0 (goto bad_context), not for return code -1 (goto error).

Regards,
Didier

xygbq (39452929-g) said : #4

hi, DP,

I got it, Thanks very much! you are right,there is no bug in this function.