[OpenSIPS-Devel] [OpenSIPS/opensips] 156460: Fix a rather obscure copy-n-paste bug in the diges...

Liviu Chircu noreply at github.com
Fri Sep 18 09:57:58 EST 2020


  Branch: refs/heads/master
  Home:   https://github.com/OpenSIPS/opensips
  Commit: 156460ee9658802823e184911ae62339562f2926
      https://github.com/OpenSIPS/opensips/commit/156460ee9658802823e184911ae62339562f2926
  Author: Maksym Sobolyev <sobomax at sippysoft.com>
  Date:   2020-09-17 (Thu, 17 Sep 2020)

  Changed paths:
    M parser/digest/digest_parser.c

  Log Message:
  -----------
  Fix a rather obscure copy-n-paste bug in the digest parser causing
"Digestn" to be accepted just as well as "Digest" would, however if
the header happens to overflow to the next line right after that,
i.e.:

Authorization: Digest[CRLF]
 username="opensipit2020"...

The header would fail to be parsed at LF. Use is_ws() macro here, don't
reinvent a wheel.


  Commit: 659b32939d16c318fa21b9ce4b33b25b99312ca7
      https://github.com/OpenSIPS/opensips/commit/659b32939d16c318fa21b9ce4b33b25b99312ca7
  Author: Maksym Sobolyev <sobomax at sippysoft.com>
  Date:   2020-09-17 (Thu, 17 Sep 2020)

  Changed paths:
    M trim.h
    M ut.h

  Log Message:
  -----------
  Use is_ws() in two more places where appropriate.


  Commit: d3b071a2d7792b7e6091dea11b36d9edba8c8bc7
      https://github.com/OpenSIPS/opensips/commit/d3b071a2d7792b7e6091dea11b36d9edba8c8bc7
  Author: Maksym Sobolyev <sobomax at sippysoft.com>
  Date:   2020-09-17 (Thu, 17 Sep 2020)

  Changed paths:
    M trim.h

  Log Message:
  -----------
  Steal highly optimizable and smart algorithm to do LWS detection
invented by the clang project. It does LWS detection in just a
handful instructions and no branches, as compared to the dozen
instructions and 4 branches currently.

Some info on how it works here:

https://pdimov.github.io/blog/2020/07/19/llvm-and-memchr/

==== C code ===
int
is_ws_original(char cp)
{

    return ((cp == ' ') || (cp == '\r') || (cp == 'n') || (cp == '\t') || (cp == ','));
}

int
is_ws_new(unsigned char ch)
{
    const unsigned int mask = (1 << (' ' - 1)) | (1 << ('\r' - 1)) |
        (1 << ('\n' - 1)) | (1 << ('\t' - 1));
    ch--;
    return ch < ' ' && ((1 << ch) & mask);
}
==== Compiled, latest clang/trunk, -O2, x86_64 ====
is_ws_original:                         # @is_ws_original
        mov     eax, 1
        cmp     dil, 32
        ja      .LBB6_1
        movzx   ecx, dil
        movabs  rdx, 4294976000
        bt      rdx, rcx
        jb      .LBB6_4
.LBB6_1:
        cmp     dil, 110
        jne     .LBB6_2
.LBB6_4:
        ret
.LBB6_2:
        xor     eax, eax
        cmp     dil, 44
        sete    al
        ret

is_ws_new:                              # @is_ws_new
        add     dil, -1
        cmp     dil, 32
        setb    al
        movzx   ecx, dil
        mov     edx, -2147478784
        bt      edx, ecx
        setb    cl
        and     cl, al
        movzx   eax, cl
        ret
====


  Commit: baddd32e2fd6cb43dd8b55f8a9f494fbd506d403
      https://github.com/OpenSIPS/opensips/commit/baddd32e2fd6cb43dd8b55f8a9f494fbd506d403
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2020-09-18 (Fri, 18 Sep 2020)

  Changed paths:
    M parser/digest/digest_parser.c
    M trim.h
    M ut.h

  Log Message:
  -----------
  Merge pull request #2253 from sippy/master_2020

Fix a rather obscure copy-n-paste bug in the digest parser


Compare: https://github.com/OpenSIPS/opensips/compare/f17737985e65...baddd32e2fd6



More information about the Devel mailing list