LLVMFuzzerTestOneInput:
    4|  1.31k|{
    5|  1.31k|    AcseConnection acseConnection;
    6|  1.31k|    AcseConnection_init(&acseConnection, NULL, NULL, NULL);
    7|       |
    8|  1.31k|    ByteBuffer* acseBuffer = ByteBuffer_create(NULL, size);
    9|  1.31k|    ByteBuffer_append(acseBuffer, data, size);
   10|  1.31k|    AcseConnection_parseMessage(&acseConnection, acseBuffer);
   11|       |    
   12|  1.31k|    ByteBuffer_destroy(acseBuffer);
   13|  1.31k|    return 0;
   14|  1.31k|}

Memory_calloc:
   43|  2.63k|{
   44|  2.63k|    void* memory = calloc(nmemb, size);
   45|       |
   46|  2.63k|    if (memory == NULL)
  ------------------
  |  Branch (46:9): [True: 0, False: 2.63k]
  ------------------
   47|      0|        noMemoryAvailableHandler();
   48|       |
   49|  2.63k|    return memory;
   50|  2.63k|}
Memory_free:
   65|  2.63k|{
   66|  2.63k|    free(memb);
   67|  2.63k|}

ByteBuffer_create:
   29|  1.31k|{
   30|  1.31k|    if (self == NULL)
  ------------------
  |  Branch (30:9): [True: 1.31k, False: 0]
  ------------------
   31|  1.31k|    {
   32|  1.31k|        self = (ByteBuffer*)GLOBAL_CALLOC(1, sizeof(ByteBuffer));
  ------------------
  |  |   20|  1.31k|#define GLOBAL_CALLOC(nmemb, size) Memory_calloc(nmemb, size)
  ------------------
   33|  1.31k|    }
   34|       |
   35|  1.31k|    if (self)
  ------------------
  |  Branch (35:9): [True: 1.31k, False: 0]
  ------------------
   36|  1.31k|    {
   37|  1.31k|        self->buffer = (uint8_t*)GLOBAL_CALLOC(maxSize, sizeof(uint8_t));
  ------------------
  |  |   20|  1.31k|#define GLOBAL_CALLOC(nmemb, size) Memory_calloc(nmemb, size)
  ------------------
   38|       |
   39|  1.31k|        if (self->buffer == NULL)
  ------------------
  |  Branch (39:13): [True: 0, False: 1.31k]
  ------------------
   40|      0|        {
   41|      0|            GLOBAL_FREEMEM(self);
  ------------------
  |  |   23|      0|#define GLOBAL_FREEMEM(ptr)        Memory_free(ptr)
  ------------------
   42|      0|            self = NULL;
   43|      0|        }
   44|  1.31k|        else
   45|  1.31k|        {
   46|  1.31k|            self->maxSize = maxSize;
   47|  1.31k|            self->size = 0;
   48|  1.31k|        }
   49|  1.31k|    }
   50|       |
   51|  1.31k|    return self;
   52|  1.31k|}
ByteBuffer_destroy:
   56|  1.31k|{
   57|  1.31k|    GLOBAL_FREEMEM(self->buffer);
  ------------------
  |  |   23|  1.31k|#define GLOBAL_FREEMEM(ptr)        Memory_free(ptr)
  ------------------
   58|  1.31k|    GLOBAL_FREEMEM(self);
  ------------------
  |  |   23|  1.31k|#define GLOBAL_FREEMEM(ptr)        Memory_free(ptr)
  ------------------
   59|  1.31k|}
ByteBuffer_append:
   71|  1.31k|{
   72|  1.31k|    if (self->size + dataSize <= self->maxSize)
  ------------------
  |  Branch (72:9): [True: 1.31k, False: 0]
  ------------------
   73|  1.31k|    {
   74|  1.31k|        memcpy(self->buffer + self->size, data, dataSize);
   75|  1.31k|        self->size += dataSize;
   76|  1.31k|        return dataSize;
   77|  1.31k|    }
   78|      0|    else
   79|      0|    {
   80|      0|        return -1;
   81|      0|    }
   82|  1.31k|}

BerDecoder_decodeLength:
  128|  1.59M|{
  129|  1.59M|    return BerDecoder_decodeLengthRecursive(buffer, length, bufPos, maxBufPos, 0, 50);
  130|  1.59M|}
BerDecoder_decodeUint32:
  151|   113k|{
  152|   113k|    uint32_t value = 0;
  153|       |
  154|   113k|    int i;
  155|   252k|    for (i = 0; i < intLen; i++)
  ------------------
  |  Branch (155:17): [True: 142k, False: 110k]
  ------------------
  156|   142k|    {
  157|   142k|        value <<= 8;
  158|   142k|        value += buffer[bufPos + i];
  159|       |
  160|   142k|        if (i == 3)
  ------------------
  |  Branch (160:13): [True: 2.90k, False: 139k]
  ------------------
  161|  2.90k|            break; /* only accept up to 4 bytes for uint32 */
  162|   142k|    }
  163|       |
  164|   113k|    return value;
  165|   113k|}
BerDecoder_decodeInt32:
  169|  23.7k|{
  170|  23.7k|    if ((intlen <= 0) || (intlen > 4))
  ------------------
  |  Branch (170:9): [True: 16.9k, False: 6.76k]
  |  Branch (170:26): [True: 207, False: 6.55k]
  ------------------
  171|  17.1k|        return 0;
  172|       |
  173|  6.55k|    uint32_t value;
  174|  6.55k|    int i;
  175|       |
  176|  6.55k|    bool isNegative = ((buffer[bufPos] & 0x80) == 0x80);
  177|       |
  178|  6.55k|    if (isNegative)
  ------------------
  |  Branch (178:9): [True: 4.73k, False: 1.81k]
  ------------------
  179|  4.73k|        value = -0xffffffff; /* initialize to all 1s for -1 */
  180|  1.81k|    else
  181|  1.81k|        value = 0;
  182|       |
  183|  13.3k|    for (i = 0; i < intlen; i++)
  ------------------
  |  Branch (183:17): [True: 6.74k, False: 6.55k]
  ------------------
  184|  6.74k|    {
  185|  6.74k|        value <<= 8;
  186|  6.74k|        value += buffer[bufPos + i];
  187|  6.74k|    }
  188|       |
  189|  6.55k|    return (int32_t)value;
  190|  23.7k|}
BerDecoder_decodeOID:
  256|  28.6k|{
  257|  28.6k|    int startPos = bufPos;
  258|  28.6k|    int currentArc = 0;
  259|       |
  260|       |    /* clear all arcs */
  261|  28.6k|    int i;
  262|   315k|    for (i = 0; i < 10; i++)
  ------------------
  |  Branch (262:17): [True: 286k, False: 28.6k]
  ------------------
  263|   286k|        oid->arc[i] = 0;
  264|       |
  265|       |    /* parse first two arcs */
  266|  28.6k|    if (length > 0)
  ------------------
  |  Branch (266:9): [True: 16.5k, False: 12.1k]
  ------------------
  267|  16.5k|    {
  268|  16.5k|        oid->arc[0] = buffer[bufPos] / 40;
  269|  16.5k|        oid->arc[1] = buffer[bufPos] % 40;
  270|       |
  271|  16.5k|        currentArc = 2;
  272|  16.5k|        bufPos++;
  273|  16.5k|    }
  274|       |
  275|       |    /* parse remaining arcs */
  276|  34.3k|    while ((bufPos - startPos < length) && (currentArc < 10))
  ------------------
  |  Branch (276:12): [True: 5.67k, False: 28.6k]
  |  Branch (276:44): [True: 5.65k, False: 16]
  ------------------
  277|  5.65k|    {
  278|  5.65k|        oid->arc[currentArc] = oid->arc[currentArc] << 7;
  279|       |
  280|  5.65k|        if (buffer[bufPos] < 0x80)
  ------------------
  |  Branch (280:13): [True: 4.47k, False: 1.17k]
  ------------------
  281|  4.47k|            oid->arc[currentArc++] += buffer[bufPos];
  282|  1.17k|        else
  283|  1.17k|            oid->arc[currentArc] += (buffer[bufPos] & 0x7f);
  284|       |
  285|  5.65k|        bufPos++;
  286|  5.65k|    }
  287|       |
  288|  28.6k|    oid->arcCount = currentArc;
  289|  28.6k|}
ber_decode.c:BerDecoder_decodeLengthRecursive:
   75|  12.1M|{
   76|  12.1M|    if (bufPos >= maxBufPos)
  ------------------
  |  Branch (76:9): [True: 275, False: 12.1M]
  ------------------
   77|    275|        return -1;
   78|       |
   79|  12.1M|    uint8_t len1 = buffer[bufPos++];
   80|       |
   81|  12.1M|    if (len1 & 0x80)
  ------------------
  |  Branch (81:9): [True: 328k, False: 11.8M]
  ------------------
   82|   328k|    {
   83|   328k|        int lenLength = len1 & 0x7f;
   84|       |
   85|   328k|        if (lenLength == 0)
  ------------------
  |  Branch (85:13): [True: 55.0k, False: 273k]
  ------------------
   86|  55.0k|        { /* indefinite length form */
   87|  55.0k|            *length = getIndefiniteLength(buffer, bufPos, maxBufPos, depth, maxDepth);
   88|  55.0k|        }
   89|   273k|        else if (lenLength < 4)
  ------------------
  |  Branch (89:18): [True: 273k, False: 42]
  ------------------
   90|   273k|        {
   91|   273k|            *length = 0;
   92|       |
   93|   273k|            int i;
   94|   548k|            for (i = 0; i < lenLength; i++)
  ------------------
  |  Branch (94:25): [True: 275k, False: 273k]
  ------------------
   95|   275k|            {
   96|   275k|                if (bufPos >= maxBufPos)
  ------------------
  |  Branch (96:21): [True: 12, False: 275k]
  ------------------
   97|     12|                    return -1;
   98|       |
   99|   275k|                if (bufPos + (*length) > maxBufPos)
  ------------------
  |  Branch (99:21): [True: 1, False: 275k]
  ------------------
  100|      1|                    return -1;
  101|       |
  102|   275k|                *length <<= 8;
  103|   275k|                *length += buffer[bufPos++];
  104|   275k|            }
  105|   273k|        }
  106|     42|        else
  107|     42|        {
  108|       |            /* only accept a maximum of 3 length bytes*/
  109|     42|            return -1;
  110|     42|        }
  111|   328k|    }
  112|  11.8M|    else
  113|  11.8M|    {
  114|  11.8M|        *length = len1;
  115|  11.8M|    }
  116|       |
  117|  12.1M|    if (*length < 0)
  ------------------
  |  Branch (117:9): [True: 1.45k, False: 12.1M]
  ------------------
  118|  1.45k|        return -1;
  119|       |
  120|  12.1M|    if (bufPos + (*length) > maxBufPos)
  ------------------
  |  Branch (120:9): [True: 85, False: 12.1M]
  ------------------
  121|     85|        return -1;
  122|       |
  123|  12.1M|    return bufPos;
  124|  12.1M|}
ber_decode.c:getIndefiniteLength:
   32|  55.0k|{
   33|  55.0k|    depth++;
   34|       |
   35|  55.0k|    if (depth > maxDepth)
  ------------------
  |  Branch (35:9): [True: 1, False: 55.0k]
  ------------------
   36|      1|        return -1;
   37|       |
   38|  55.0k|    int length = 0;
   39|       |
   40|  10.6M|    while (bufPos < maxBufPos)
  ------------------
  |  Branch (40:12): [True: 10.6M, False: 40]
  ------------------
   41|  10.6M|    {
   42|  10.6M|        if ((buffer[bufPos] == 0) && ((bufPos + 1) < maxBufPos) && (buffer[bufPos + 1] == 0))
  ------------------
  |  Branch (42:13): [True: 512k, False: 10.1M]
  |  Branch (42:38): [True: 512k, False: 21]
  |  Branch (42:68): [True: 53.5k, False: 459k]
  ------------------
   43|  53.5k|        {
   44|  53.5k|            return length + 2;
   45|  53.5k|        }
   46|  10.5M|        else
   47|  10.5M|        {
   48|  10.5M|            length++;
   49|       |
   50|  10.5M|            if ((buffer[bufPos++] & 0x1f) == 0x1f)
  ------------------
  |  Branch (50:17): [True: 427k, False: 10.1M]
  ------------------
   51|   427k|            {
   52|       |                /* handle extended tags */
   53|   427k|                bufPos++;
   54|   427k|                length++;
   55|   427k|            }
   56|       |
   57|  10.5M|            int subLength = -1;
   58|       |
   59|  10.5M|            int newBufPos = BerDecoder_decodeLengthRecursive(buffer, &subLength, bufPos, maxBufPos, depth, maxDepth);
   60|       |
   61|  10.5M|            if (newBufPos == -1)
  ------------------
  |  Branch (61:17): [True: 1.41k, False: 10.5M]
  ------------------
   62|  1.41k|                return -1;
   63|       |
   64|  10.5M|            length += subLength + newBufPos - bufPos;
   65|       |
   66|  10.5M|            bufPos = newBufPos + subLength;
   67|  10.5M|        }
   68|  10.6M|    }
   69|       |
   70|     40|    return -1;
   71|  55.0k|}

AcseConnection_init:
  450|  1.31k|{
  451|  1.31k|    self->state = idle;
  452|  1.31k|    self->nextReference = 0;
  453|  1.31k|    self->userDataBuffer = NULL;
  454|  1.31k|    self->userDataBufferSize = 0;
  455|  1.31k|    self->authenticator = authenticator;
  456|  1.31k|    self->authenticatorParameter = parameter;
  457|       |
  458|       |#if (CONFIG_MMS_SUPPORT_TLS == 1)
  459|       |    self->tlsSocket = tlsSocket;
  460|       |#else
  461|  1.31k|    (void)tlsSocket;
  462|  1.31k|#endif
  463|       |
  464|  1.31k|    memset(&(self->applicationReference), 0,
  465|  1.31k|            sizeof(self->applicationReference));
  466|  1.31k|}
AcseConnection_parseMessage:
  470|  1.31k|{
  471|  1.31k|    AcseIndication indication = ACSE_ERROR;
  472|       |
  473|  1.31k|    if (message == NULL || message->size < 1)
  ------------------
  |  Branch (473:9): [True: 0, False: 1.31k]
  |  Branch (473:28): [True: 0, False: 1.31k]
  ------------------
  474|      0|    {
  475|      0|        if (DEBUG_ACSE)
  ------------------
  |  |   32|      0|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 0]
  |  |  ------------------
  ------------------
  476|      0|            printf("ACSE: invalid message - no payload\n");
  477|       |
  478|      0|        return ACSE_ERROR;
  479|      0|    }
  480|       |
  481|  1.31k|    uint8_t* buffer = message->buffer;
  482|       |
  483|  1.31k|    int messageSize = message->size;
  484|       |
  485|  1.31k|    int bufPos = 0;
  486|       |
  487|  1.31k|    uint8_t messageType = buffer[bufPos++];
  488|       |
  489|  1.31k|    int len;
  490|       |
  491|  1.31k|    bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, messageSize);
  492|       |
  493|  1.31k|    if (bufPos < 0)
  ------------------
  |  Branch (493:9): [True: 227, False: 1.09k]
  ------------------
  494|    227|    {
  495|    227|        if (DEBUG_ACSE)
  ------------------
  |  |   32|    227|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 227]
  |  |  ------------------
  ------------------
  496|      0|            printf("ACSE: AcseConnection_parseMessage: invalid ACSE message!\n");
  497|       |
  498|    227|        return ACSE_ERROR;
  499|    227|    }
  500|       |
  501|  1.09k|    switch (messageType)
  502|  1.09k|    {
  503|    688|    case 0x60:
  ------------------
  |  Branch (503:5): [True: 688, False: 404]
  ------------------
  504|    688|        indication = parseAarqPdu(self, buffer, bufPos, bufPos + len);
  505|    688|        break;
  506|    396|    case 0x61:
  ------------------
  |  Branch (506:5): [True: 396, False: 696]
  ------------------
  507|    396|        indication = parseAarePdu(self, buffer, bufPos, bufPos + len);
  508|    396|        break;
  509|      2|    case 0x62: /* A_RELEASE.request RLRQ-apdu */
  ------------------
  |  Branch (509:5): [True: 2, False: 1.09k]
  ------------------
  510|      2|        indication = ACSE_RELEASE_REQUEST;
  511|      2|        break;
  512|      1|    case 0x63: /* A_RELEASE.response RLRE-apdu */
  ------------------
  |  Branch (512:5): [True: 1, False: 1.09k]
  ------------------
  513|      1|        indication = ACSE_RELEASE_RESPONSE;
  514|      1|        break;
  515|      1|    case 0x64: /* A_ABORT */
  ------------------
  |  Branch (515:5): [True: 1, False: 1.09k]
  ------------------
  516|      1|        indication = ACSE_ABORT;
  517|      1|        break;
  518|      1|    case 0x00: /* indefinite length end tag -> ignore */
  ------------------
  |  Branch (518:5): [True: 1, False: 1.09k]
  ------------------
  519|      1|        break;
  520|      3|    default:
  ------------------
  |  Branch (520:5): [True: 3, False: 1.08k]
  ------------------
  521|      3|        if (DEBUG_ACSE)
  ------------------
  |  |   32|      3|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 3]
  |  |  ------------------
  ------------------
  522|      0|            printf("ACSE: Unknown ACSE message\n");
  523|      3|        indication = ACSE_ERROR;
  524|      3|        break;
  525|  1.09k|    }
  526|       |
  527|  1.09k|    return indication;
  528|  1.09k|}
acse.c:parseAarqPdu:
  283|    688|{
  284|    688|    if (DEBUG_ACSE)
  ------------------
  |  |   32|    688|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 688]
  |  |  ------------------
  ------------------
  285|      0|        printf("ACSE: parse AARQ PDU\n");
  286|       |
  287|    688|    uint8_t* authValue = NULL;
  288|    688|    int authValueLen = 0;
  289|    688|    uint8_t* authMechanism = NULL;
  290|    688|    int authMechLen = 0;
  291|    688|    bool userInfoValid = false;
  292|       |
  293|   552k|    while (bufPos < maxBufPos)
  ------------------
  |  Branch (293:12): [True: 552k, False: 572]
  ------------------
  294|   552k|    {
  295|   552k|        uint8_t tag = buffer[bufPos++];
  296|   552k|        int len;
  297|       |
  298|   552k|        bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  299|       |
  300|   552k|        if (bufPos < 0)
  ------------------
  |  Branch (300:13): [True: 68, False: 552k]
  ------------------
  301|     68|        {
  302|     68|            if (DEBUG_ACSE)
  ------------------
  |  |   32|     68|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 68]
  |  |  ------------------
  ------------------
  303|      0|                printf("ACSE: Invalid PDU!\n");
  304|     68|            return ACSE_ASSOCIATE_FAILED;
  305|     68|        }
  306|       |
  307|   552k|        if (len == 0)
  ------------------
  |  Branch (307:13): [True: 22.5k, False: 529k]
  ------------------
  308|  22.5k|            continue;
  309|       |
  310|   529k|        if (bufPos + len > maxBufPos)
  ------------------
  |  Branch (310:13): [True: 0, False: 529k]
  ------------------
  311|      0|        {
  312|      0|            if (DEBUG_ACSE)
  ------------------
  |  |   32|      0|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 0]
  |  |  ------------------
  ------------------
  313|      0|                printf("ACSE: Invalid PDU!\n");
  314|      0|            return ACSE_ASSOCIATE_FAILED;
  315|      0|        }
  316|       |
  317|   529k|        switch (tag)
  318|   529k|        {
  319|      2|        case 0xa1: /* application context name */
  ------------------
  |  Branch (319:9): [True: 2, False: 529k]
  ------------------
  320|      2|            bufPos += len;
  321|      2|            break;
  322|       |
  323|  1.02k|        case 0xa2: /* called AP title */
  ------------------
  |  Branch (323:9): [True: 1.02k, False: 528k]
  ------------------
  324|  1.02k|            bufPos += len;
  325|  1.02k|            break;
  326|      1|        case 0xa3: /* called AE qualifier */
  ------------------
  |  Branch (326:9): [True: 1, False: 529k]
  ------------------
  327|      1|            bufPos += len;
  328|      1|            break;
  329|       |
  330|  36.5k|        case 0xa6: /* calling AP title */
  ------------------
  |  Branch (330:9): [True: 36.5k, False: 493k]
  ------------------
  331|  36.5k|            {
  332|  36.5k|                if (len >= 2 && buffer[bufPos] == 0x06)
  ------------------
  |  Branch (332:21): [True: 31.1k, False: 5.41k]
  |  Branch (332:33): [True: 29.3k, False: 1.72k]
  ------------------
  333|  29.3k|                {
  334|       |                    /* ap-title-form2 */
  335|       |
  336|  29.3k|                    int innerLength = buffer[bufPos + 1];
  337|       |
  338|  29.3k|                    if ((innerLength >= 0) && (innerLength == len - 2))
  ------------------
  |  Branch (338:25): [True: 29.3k, False: 0]
  |  Branch (338:47): [True: 28.6k, False: 708]
  ------------------
  339|  28.6k|                        BerDecoder_decodeOID(buffer, bufPos + 2, innerLength, &(self->applicationReference.apTitle));
  340|  29.3k|                }
  341|  36.5k|            }
  342|  36.5k|            bufPos += len;
  343|  36.5k|            break;
  344|       |
  345|  33.4k|        case 0xa7: /* calling AE qualifier */
  ------------------
  |  Branch (345:9): [True: 33.4k, False: 496k]
  ------------------
  346|  33.4k|            {
  347|  33.4k|                if (len >= 2 && buffer[bufPos] == 0x02)
  ------------------
  |  Branch (347:21): [True: 32.9k, False: 540]
  |  Branch (347:33): [True: 28.3k, False: 4.63k]
  ------------------
  348|  28.3k|                {
  349|       |                    /* ae-qualifier-form2 */
  350|       |
  351|  28.3k|                    int innerLength = buffer[bufPos + 1];
  352|       |
  353|  28.3k|                    if ((innerLength >= 0) && (innerLength == len - 2))
  ------------------
  |  Branch (353:25): [True: 28.3k, False: 0]
  |  Branch (353:47): [True: 23.7k, False: 4.56k]
  ------------------
  354|  23.7k|                        self->applicationReference.aeQualifier = BerDecoder_decodeInt32(buffer, innerLength, bufPos + 2);
  355|  28.3k|                }
  356|  33.4k|            }
  357|  33.4k|            bufPos += len;
  358|  33.4k|            break;
  359|       |
  360|      0|        case 0x8a: /* sender ACSE requirements */
  ------------------
  |  Branch (360:9): [True: 0, False: 529k]
  ------------------
  361|      0|            bufPos += len;
  362|      0|            break;
  363|       |
  364|    432|        case 0x8b: /* (authentication) mechanism name */
  ------------------
  |  Branch (364:9): [True: 432, False: 529k]
  ------------------
  365|    432|            authMechLen = len;
  366|    432|            authMechanism = buffer + bufPos;
  367|    432|            bufPos += len;
  368|    432|            break;
  369|       |
  370|    639|        case 0xac: /* authentication value */
  ------------------
  |  Branch (370:9): [True: 639, False: 529k]
  ------------------
  371|    639|            bufPos++;
  372|       |
  373|    639|            bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  374|    639|            if (bufPos < 0)
  ------------------
  |  Branch (374:17): [True: 2, False: 637]
  ------------------
  375|      2|            {
  376|      2|                if (DEBUG_ACSE)
  ------------------
  |  |   32|      2|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 2]
  |  |  ------------------
  ------------------
  377|      0|                    printf("ACSE: Invalid PDU!\n");
  378|      2|                return ACSE_ASSOCIATE_FAILED;
  379|      2|            }
  380|       |
  381|    637|            authValueLen = len;
  382|    637|            authValue = buffer + bufPos;
  383|    637|            bufPos += len;
  384|    637|            break;
  385|       |
  386|  8.07k|        case 0xbe: /* user information */
  ------------------
  |  Branch (386:9): [True: 8.07k, False: 521k]
  ------------------
  387|  8.07k|            if (buffer[bufPos] != 0x28)
  ------------------
  |  Branch (387:17): [True: 2.76k, False: 5.30k]
  ------------------
  388|  2.76k|            {
  389|  2.76k|                if (DEBUG_ACSE)
  ------------------
  |  |   32|  2.76k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 2.76k]
  |  |  ------------------
  ------------------
  390|      0|                    printf("ACSE: invalid user info\n");
  391|  2.76k|                bufPos += len;
  392|  2.76k|            }
  393|  5.30k|            else
  394|  5.30k|            {
  395|  5.30k|                bufPos++;
  396|       |
  397|  5.30k|                bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  398|       |
  399|  5.30k|                if (bufPos < 0)
  ------------------
  |  Branch (399:21): [True: 4, False: 5.30k]
  ------------------
  400|      4|                {
  401|      4|                    if (DEBUG_ACSE)
  ------------------
  |  |   32|      4|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 4]
  |  |  ------------------
  ------------------
  402|      0|                        printf("ACSE: Invalid PDU!\n");
  403|      4|                    return ACSE_ASSOCIATE_FAILED;
  404|      4|                }
  405|       |
  406|  5.30k|                bufPos = parseUserInformation(self, buffer, bufPos, bufPos + len, &userInfoValid);
  407|       |
  408|  5.30k|                if (bufPos < 0)
  ------------------
  |  Branch (408:21): [True: 42, False: 5.26k]
  ------------------
  409|     42|                {
  410|     42|                    if (DEBUG_ACSE)
  ------------------
  |  |   32|     42|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 42]
  |  |  ------------------
  ------------------
  411|      0|                        printf("ACSE: Invalid PDU!\n");
  412|     42|                    return ACSE_ASSOCIATE_FAILED;
  413|     42|                }
  414|  5.30k|            }
  415|  8.02k|            break;
  416|       |
  417|  8.02k|        case 0x00: /* indefinite length end tag -> ignore */
  ------------------
  |  Branch (417:9): [True: 5.30k, False: 524k]
  ------------------
  418|  5.30k|            break;
  419|       |
  420|   444k|        default: /* ignore unknown tag */
  ------------------
  |  Branch (420:9): [True: 444k, False: 85.4k]
  ------------------
  421|   444k|            if (DEBUG_ACSE)
  ------------------
  |  |   32|   444k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 444k]
  |  |  ------------------
  ------------------
  422|      0|                printf("ACSE: parseAarqPdu: unknown tag %02x\n", tag);
  423|       |
  424|   444k|            bufPos += len;
  425|   444k|            break;
  426|   529k|        }
  427|   529k|    }
  428|       |
  429|    572|    if (checkAuthentication(self, authMechanism, authMechLen, authValue, authValueLen) == false)
  ------------------
  |  Branch (429:9): [True: 0, False: 572]
  ------------------
  430|      0|    {
  431|      0|        if (DEBUG_ACSE)
  ------------------
  |  |   32|      0|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 0]
  |  |  ------------------
  ------------------
  432|      0|            printf("ACSE: parseAarqPdu: check authentication failed!\n");
  433|       |
  434|      0|        return ACSE_ASSOCIATE_FAILED;
  435|      0|    }
  436|       |
  437|    572|    if (userInfoValid == false)
  ------------------
  |  Branch (437:9): [True: 561, False: 11]
  ------------------
  438|    561|    {
  439|    561|        if (DEBUG_ACSE)
  ------------------
  |  |   32|    561|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 561]
  |  |  ------------------
  ------------------
  440|      0|            printf("ACSE: parseAarqPdu: user info invalid!\n");
  441|       |
  442|    561|        return ACSE_ASSOCIATE_FAILED;
  443|    561|    }
  444|       |
  445|     11|    return ACSE_ASSOCIATE;
  446|    572|}
acse.c:parseUserInformation:
  119|  9.64k|{
  120|  9.64k|    if (DEBUG_ACSE)
  ------------------
  |  |   32|  9.64k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 9.64k]
  |  |  ------------------
  ------------------
  121|      0|        printf("ACSE: parseUserInformation %i %i\n", bufPos, maxBufPos);
  122|       |
  123|  9.64k|    bool hasindirectReference = false;
  124|  9.64k|    bool isDataValid = false;
  125|       |
  126|   196k|    while (bufPos < maxBufPos)
  ------------------
  |  Branch (126:12): [True: 186k, False: 9.55k]
  ------------------
  127|   186k|    {
  128|   186k|        uint8_t tag = buffer[bufPos++];
  129|   186k|        int len;
  130|       |
  131|   186k|        bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  132|       |
  133|   186k|        if ((bufPos < 0) || (bufPos + len > maxBufPos))
  ------------------
  |  Branch (133:13): [True: 87, False: 186k]
  |  Branch (133:29): [True: 0, False: 186k]
  ------------------
  134|     87|        {
  135|     87|            *userInfoValid = false;
  136|     87|            return -1;
  137|     87|        }
  138|       |
  139|   186k|        if (len == 0)
  ------------------
  |  Branch (139:13): [True: 21.5k, False: 165k]
  ------------------
  140|  21.5k|            continue;
  141|       |
  142|   165k|        switch (tag)
  143|   165k|        {
  144|       |
  145|   110k|        case 0x02: /* indirect-reference */
  ------------------
  |  Branch (145:9): [True: 110k, False: 54.4k]
  ------------------
  146|   110k|            self->nextReference = BerDecoder_decodeUint32(buffer, len, bufPos);
  147|   110k|            bufPos += len;
  148|   110k|            hasindirectReference = true;
  149|   110k|            break;
  150|       |
  151|  2.17k|        case 0xa0: /* encoding */
  ------------------
  |  Branch (151:9): [True: 2.17k, False: 162k]
  ------------------
  152|  2.17k|            isDataValid = true;
  153|       |
  154|  2.17k|            self->userDataBufferSize = len;
  155|  2.17k|            self->userDataBuffer = buffer + bufPos;
  156|       |
  157|  2.17k|            bufPos += len;
  158|       |
  159|  2.17k|            break;
  160|       |
  161|  52.3k|        default: /* ignore unknown tag */
  ------------------
  |  Branch (161:9): [True: 52.3k, False: 112k]
  ------------------
  162|  52.3k|            bufPos += len;
  163|   165k|        }
  164|   165k|    }
  165|       |
  166|  9.55k|    if (DEBUG_ACSE)
  ------------------
  |  |   32|  9.55k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 9.55k]
  |  |  ------------------
  ------------------
  167|      0|    {
  168|      0|        if (!hasindirectReference)
  ------------------
  |  Branch (168:13): [True: 0, False: 0]
  ------------------
  169|      0|            printf("ACSE: User data has no indirect reference!\n");
  170|       |
  171|      0|        if (!isDataValid)
  ------------------
  |  Branch (171:13): [True: 0, False: 0]
  ------------------
  172|      0|            printf("ACSE: No valid user data\n");
  173|      0|    }
  174|       |
  175|  9.55k|    if (hasindirectReference && isDataValid)
  ------------------
  |  Branch (175:9): [True: 5.65k, False: 3.89k]
  |  Branch (175:33): [True: 598, False: 5.06k]
  ------------------
  176|    598|        *userInfoValid = true;
  177|  8.95k|    else
  178|  8.95k|        *userInfoValid = false;
  179|       |
  180|  9.55k|    return bufPos;
  181|  9.64k|}
acse.c:checkAuthentication:
   84|    572|{
   85|    572|    self->securityToken = NULL;
   86|       |
   87|    572|    if (self->authenticator != NULL)
  ------------------
  |  Branch (87:9): [True: 0, False: 572]
  ------------------
   88|      0|    {
   89|      0|        AcseAuthenticationMechanism mechanism = checkAuthMechanismName(authMechanism, authMechLen);
   90|       |
   91|      0|        if (mechanism == ACSE_AUTH_NONE)
  ------------------
  |  Branch (91:13): [True: 0, False: 0]
  ------------------
   92|      0|        {
   93|       |#if (CONFIG_MMS_SUPPORT_TLS == 1)
   94|       |            if (self->tlsSocket)
   95|       |            {
   96|       |                int certLen;
   97|       |
   98|       |                uint8_t* certBuf = TLSSocket_getPeerCertificate(self->tlsSocket, &certLen);
   99|       |
  100|       |                if (certBuf) {
  101|       |                    mechanism = ACSE_AUTH_TLS;
  102|       |                    authValue = certBuf;
  103|       |                    authValueLen = certLen;
  104|       |                }
  105|       |
  106|       |            }
  107|       |#endif /* (CONFIG_MMS_SUPPORT_TLS == 1) */
  108|       |
  109|      0|        }
  110|       |
  111|      0|        return authenticateClient(self, mechanism, authValue, authValueLen);
  112|      0|    }
  113|    572|    else
  114|    572|        return true;
  115|    572|}
acse.c:parseAarePdu:
  185|    396|{
  186|    396|    if (DEBUG_ACSE)
  ------------------
  |  |   32|    396|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 396]
  |  |  ------------------
  ------------------
  187|      0|        printf("ACSE: parse AARE PDU\n");
  188|       |
  189|    396|    bool userInfoValid = false;
  190|       |
  191|    396|    uint32_t result = 99;
  192|       |
  193|   840k|    while (bufPos < maxBufPos)
  ------------------
  |  Branch (193:12): [True: 839k, False: 283]
  ------------------
  194|   839k|    {
  195|   839k|        uint8_t tag = buffer[bufPos++];
  196|   839k|        int len;
  197|       |
  198|   839k|        bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  199|       |
  200|   839k|        if (bufPos < 0)
  ------------------
  |  Branch (200:13): [True: 64, False: 839k]
  ------------------
  201|     64|        {
  202|     64|            if (DEBUG_ACSE)
  ------------------
  |  |   32|     64|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 64]
  |  |  ------------------
  ------------------
  203|      0|                printf("ACSE: Invalid PDU!\n");
  204|     64|            return ACSE_ERROR;
  205|     64|        }
  206|       |
  207|   839k|        if (len == 0)
  ------------------
  |  Branch (207:13): [True: 18.3k, False: 821k]
  ------------------
  208|  18.3k|            continue;
  209|       |
  210|   821k|        if (bufPos + len > maxBufPos)
  ------------------
  |  Branch (210:13): [True: 0, False: 821k]
  ------------------
  211|      0|        {
  212|      0|            if (DEBUG_ACSE)
  ------------------
  |  |   32|      0|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 0]
  |  |  ------------------
  ------------------
  213|      0|                printf("ACSE: Invalid PDU!\n");
  214|      0|            return ACSE_ERROR;
  215|      0|        }
  216|       |
  217|   821k|        switch (tag)
  218|   821k|        {
  219|      9|        case 0xa1: /* application context name */
  ------------------
  |  Branch (219:9): [True: 9, False: 821k]
  ------------------
  220|      9|            bufPos += len;
  221|      9|            break;
  222|       |
  223|  3.07k|        case 0xa2: /* result */
  ------------------
  |  Branch (223:9): [True: 3.07k, False: 818k]
  ------------------
  224|  3.07k|            bufPos++;
  225|       |
  226|  3.07k|            bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  227|  3.07k|            if (bufPos < 0)
  ------------------
  |  Branch (227:17): [True: 2, False: 3.07k]
  ------------------
  228|      2|                return ACSE_ERROR;
  229|       |
  230|  3.07k|            result = BerDecoder_decodeUint32(buffer, len, bufPos);
  231|       |
  232|  3.07k|            bufPos += len;
  233|  3.07k|            break;
  234|       |
  235|      0|        case 0xa3: /* result source diagnostic */
  ------------------
  |  Branch (235:9): [True: 0, False: 821k]
  ------------------
  236|      0|            bufPos += len;
  237|      0|            break;
  238|       |
  239|  5.04k|        case 0xbe: /* user information */
  ------------------
  |  Branch (239:9): [True: 5.04k, False: 816k]
  ------------------
  240|  5.04k|            if (buffer[bufPos] != 0x28)
  ------------------
  |  Branch (240:17): [True: 705, False: 4.34k]
  ------------------
  241|    705|            {
  242|    705|                if (DEBUG_ACSE)
  ------------------
  |  |   32|    705|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 705]
  |  |  ------------------
  ------------------
  243|      0|                    printf("ACSE: invalid user info\n");
  244|    705|                bufPos += len;
  245|    705|            }
  246|  4.34k|            else
  247|  4.34k|            {
  248|  4.34k|                bufPos++;
  249|       |
  250|  4.34k|                bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  251|  4.34k|                if (bufPos < 0)
  ------------------
  |  Branch (251:21): [True: 2, False: 4.33k]
  ------------------
  252|      2|                    return ACSE_ERROR;
  253|       |
  254|  4.33k|                bufPos = parseUserInformation(self, buffer, bufPos, bufPos + len, &userInfoValid);
  255|  4.33k|                if (bufPos < 0)
  ------------------
  |  Branch (255:21): [True: 45, False: 4.29k]
  ------------------
  256|     45|                    return ACSE_ERROR;
  257|  4.33k|            }
  258|  4.99k|            break;
  259|       |
  260|  4.99k|        case 0x00: /* indefinite length end tag -> ignore */
  ------------------
  |  Branch (260:9): [True: 4.97k, False: 816k]
  ------------------
  261|  4.97k|            break;
  262|       |
  263|   808k|        default: /* ignore unknown tag */
  ------------------
  |  Branch (263:9): [True: 808k, False: 13.1k]
  ------------------
  264|   808k|            if (DEBUG_ACSE)
  ------------------
  |  |   32|   808k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 808k]
  |  |  ------------------
  ------------------
  265|      0|                printf("ACSE: parseAarePdu: unknown tag %02x\n", tag);
  266|       |
  267|   808k|            bufPos += len;
  268|   808k|            break;
  269|   821k|        }
  270|   821k|    }
  271|       |
  272|    283|    if (!userInfoValid)
  ------------------
  |  Branch (272:9): [True: 265, False: 18]
  ------------------
  273|    265|        return ACSE_ERROR;
  274|       |
  275|     18|    if (result != 0)
  ------------------
  |  Branch (275:9): [True: 16, False: 2]
  ------------------
  276|     16|        return ACSE_ASSOCIATE_FAILED;
  277|       |
  278|      2|    return ACSE_ASSOCIATE;
  279|     18|}

