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.37M|{
  129|  1.37M|    return BerDecoder_decodeLengthRecursive(buffer, length, bufPos, maxBufPos, 0, 50);
  130|  1.37M|}
BerDecoder_decodeUint32:
  151|   105k|{
  152|   105k|    uint32_t value = 0;
  153|       |
  154|   105k|    int i;
  155|   236k|    for (i = 0; i < intLen; i++)
  ------------------
  |  Branch (155:17): [True: 134k, False: 102k]
  ------------------
  156|   134k|    {
  157|   134k|        value <<= 8;
  158|   134k|        value += buffer[bufPos + i];
  159|       |
  160|   134k|        if (i == 3)
  ------------------
  |  Branch (160:13): [True: 3.18k, False: 131k]
  ------------------
  161|  3.18k|            break; /* only accept up to 4 bytes for uint32 */
  162|   134k|    }
  163|       |
  164|   105k|    return value;
  165|   105k|}
BerDecoder_decodeInt32:
  169|  22.9k|{
  170|  22.9k|    if ((intlen <= 0) || (intlen > 4))
  ------------------
  |  Branch (170:9): [True: 17.1k, False: 5.79k]
  |  Branch (170:26): [True: 210, False: 5.58k]
  ------------------
  171|  17.3k|        return 0;
  172|       |
  173|  5.58k|    uint32_t value;
  174|  5.58k|    int i;
  175|       |
  176|  5.58k|    bool isNegative = ((buffer[bufPos] & 0x80) == 0x80);
  177|       |
  178|  5.58k|    if (isNegative)
  ------------------
  |  Branch (178:9): [True: 3.46k, False: 2.12k]
  ------------------
  179|  3.46k|        value = -0xffffffff; /* initialize to all 1s for -1 */
  180|  2.12k|    else
  181|  2.12k|        value = 0;
  182|       |
  183|  11.3k|    for (i = 0; i < intlen; i++)
  ------------------
  |  Branch (183:17): [True: 5.78k, False: 5.58k]
  ------------------
  184|  5.78k|    {
  185|  5.78k|        value <<= 8;
  186|  5.78k|        value += buffer[bufPos + i];
  187|  5.78k|    }
  188|       |
  189|  5.58k|    return (int32_t)value;
  190|  22.9k|}
BerDecoder_decodeOID:
  256|  19.4k|{
  257|  19.4k|    int startPos = bufPos;
  258|  19.4k|    int currentArc = 0;
  259|       |
  260|       |    /* clear all arcs */
  261|  19.4k|    int i;
  262|   213k|    for (i = 0; i < 10; i++)
  ------------------
  |  Branch (262:17): [True: 194k, False: 19.4k]
  ------------------
  263|   194k|        oid->arc[i] = 0;
  264|       |
  265|       |    /* parse first two arcs */
  266|  19.4k|    if (length > 0)
  ------------------
  |  Branch (266:9): [True: 6.26k, False: 13.1k]
  ------------------
  267|  6.26k|    {
  268|  6.26k|        oid->arc[0] = buffer[bufPos] / 40;
  269|  6.26k|        oid->arc[1] = buffer[bufPos] % 40;
  270|       |
  271|  6.26k|        currentArc = 2;
  272|  6.26k|        bufPos++;
  273|  6.26k|    }
  274|       |
  275|       |    /* parse remaining arcs */
  276|  25.0k|    while ((bufPos - startPos < length) && (currentArc < 10))
  ------------------
  |  Branch (276:12): [True: 5.68k, False: 19.3k]
  |  Branch (276:44): [True: 5.66k, False: 25]
  ------------------
  277|  5.66k|    {
  278|  5.66k|        oid->arc[currentArc] = oid->arc[currentArc] << 7;
  279|       |
  280|  5.66k|        if (buffer[bufPos] < 0x80)
  ------------------
  |  Branch (280:13): [True: 4.54k, False: 1.11k]
  ------------------
  281|  4.54k|            oid->arc[currentArc++] += buffer[bufPos];
  282|  1.11k|        else
  283|  1.11k|            oid->arc[currentArc] += (buffer[bufPos] & 0x7f);
  284|       |
  285|  5.66k|        bufPos++;
  286|  5.66k|    }
  287|       |
  288|  19.4k|    oid->arcCount = currentArc;
  289|  19.4k|}
ber_decode.c:BerDecoder_decodeLengthRecursive:
   75|  11.7M|{
   76|  11.7M|    if (bufPos >= maxBufPos)
  ------------------
  |  Branch (76:9): [True: 274, False: 11.7M]
  ------------------
   77|    274|        return -1;
   78|       |
   79|  11.7M|    uint8_t len1 = buffer[bufPos++];
   80|       |
   81|  11.7M|    if (len1 & 0x80)
  ------------------
  |  Branch (81:9): [True: 345k, False: 11.3M]
  ------------------
   82|   345k|    {
   83|   345k|        int lenLength = len1 & 0x7f;
   84|       |
   85|   345k|        if (lenLength == 0)
  ------------------
  |  Branch (85:13): [True: 47.4k, False: 297k]
  ------------------
   86|  47.4k|        { /* indefinite length form */
   87|  47.4k|            *length = getIndefiniteLength(buffer, bufPos, maxBufPos, depth, maxDepth);
   88|  47.4k|        }
   89|   297k|        else if (lenLength < 4)
  ------------------
  |  Branch (89:18): [True: 297k, False: 29]
  ------------------
   90|   297k|        {
   91|   297k|            *length = 0;
   92|       |
   93|   297k|            int i;
   94|   596k|            for (i = 0; i < lenLength; i++)
  ------------------
  |  Branch (94:25): [True: 299k, False: 297k]
  ------------------
   95|   299k|            {
   96|   299k|                if (bufPos >= maxBufPos)
  ------------------
  |  Branch (96:21): [True: 9, False: 298k]
  ------------------
   97|      9|                    return -1;
   98|       |
   99|   298k|                if (bufPos + (*length) > maxBufPos)
  ------------------
  |  Branch (99:21): [True: 2, False: 298k]
  ------------------
  100|      2|                    return -1;
  101|       |
  102|   298k|                *length <<= 8;
  103|   298k|                *length += buffer[bufPos++];
  104|   298k|            }
  105|   297k|        }
  106|     29|        else
  107|     29|        {
  108|       |            /* only accept a maximum of 3 length bytes*/
  109|     29|            return -1;
  110|     29|        }
  111|   345k|    }
  112|  11.3M|    else
  113|  11.3M|    {
  114|  11.3M|        *length = len1;
  115|  11.3M|    }
  116|       |
  117|  11.7M|    if (*length < 0)
  ------------------
  |  Branch (117:9): [True: 1.34k, False: 11.7M]
  ------------------
  118|  1.34k|        return -1;
  119|       |
  120|  11.7M|    if (bufPos + (*length) > maxBufPos)
  ------------------
  |  Branch (120:9): [True: 88, False: 11.7M]
  ------------------
  121|     88|        return -1;
  122|       |
  123|  11.7M|    return bufPos;
  124|  11.7M|}
ber_decode.c:getIndefiniteLength:
   32|  47.4k|{
   33|  47.4k|    depth++;
   34|       |
   35|  47.4k|    if (depth > maxDepth)
  ------------------
  |  Branch (35:9): [True: 1, False: 47.4k]
  ------------------
   36|      1|        return -1;
   37|       |
   38|  47.4k|    int length = 0;
   39|       |
   40|  10.3M|    while (bufPos < maxBufPos)
  ------------------
  |  Branch (40:12): [True: 10.3M, False: 43]
  ------------------
   41|  10.3M|    {
   42|  10.3M|        if ((buffer[bufPos] == 0) && ((bufPos + 1) < maxBufPos) && (buffer[bufPos + 1] == 0))
  ------------------
  |  Branch (42:13): [True: 516k, False: 9.87M]
  |  Branch (42:38): [True: 516k, False: 16]
  |  Branch (42:68): [True: 46.1k, False: 469k]
  ------------------
   43|  46.1k|        {
   44|  46.1k|            return length + 2;
   45|  46.1k|        }
   46|  10.3M|        else
   47|  10.3M|        {
   48|  10.3M|            length++;
   49|       |
   50|  10.3M|            if ((buffer[bufPos++] & 0x1f) == 0x1f)
  ------------------
  |  Branch (50:17): [True: 434k, False: 9.91M]
  ------------------
   51|   434k|            {
   52|       |                /* handle extended tags */
   53|   434k|                bufPos++;
   54|   434k|                length++;
   55|   434k|            }
   56|       |
   57|  10.3M|            int subLength = -1;
   58|       |
   59|  10.3M|            int newBufPos = BerDecoder_decodeLengthRecursive(buffer, &subLength, bufPos, maxBufPos, depth, maxDepth);
   60|       |
   61|  10.3M|            if (newBufPos == -1)
  ------------------
  |  Branch (61:17): [True: 1.30k, False: 10.3M]
  ------------------
   62|  1.30k|                return -1;
   63|       |
   64|  10.3M|            length += subLength + newBufPos - bufPos;
   65|       |
   66|  10.3M|            bufPos = newBufPos + subLength;
   67|  10.3M|        }
   68|  10.3M|    }
   69|       |
   70|     43|    return -1;
   71|  47.4k|}

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: 219, False: 1.09k]
  ------------------
  494|    219|    {
  495|    219|        if (DEBUG_ACSE)
  ------------------
  |  |   32|    219|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 219]
  |  |  ------------------
  ------------------
  496|      0|            printf("ACSE: AcseConnection_parseMessage: invalid ACSE message!\n");
  497|       |
  498|    219|        return ACSE_ERROR;
  499|    219|    }
  500|       |
  501|  1.09k|    switch (messageType)
  502|  1.09k|    {
  503|    686|    case 0x60:
  ------------------
  |  Branch (503:5): [True: 686, False: 412]
  ------------------
  504|    686|        indication = parseAarqPdu(self, buffer, bufPos, bufPos + len);
  505|    686|        break;
  506|    403|    case 0x61:
  ------------------
  |  Branch (506:5): [True: 403, False: 695]
  ------------------
  507|    403|        indication = parseAarePdu(self, buffer, bufPos, bufPos + len);
  508|    403|        break;
  509|      1|    case 0x62: /* A_RELEASE.request RLRQ-apdu */
  ------------------
  |  Branch (509:5): [True: 1, False: 1.09k]
  ------------------
  510|      1|        indication = ACSE_RELEASE_REQUEST;
  511|      1|        break;
  512|      3|    case 0x63: /* A_RELEASE.response RLRE-apdu */
  ------------------
  |  Branch (512:5): [True: 3, False: 1.09k]
  ------------------
  513|      3|        indication = ACSE_RELEASE_RESPONSE;
  514|      3|        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.09k]
  ------------------
  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|    686|{
  284|    686|    if (DEBUG_ACSE)
  ------------------
  |  |   32|    686|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 686]
  |  |  ------------------
  ------------------
  285|      0|        printf("ACSE: parse AARQ PDU\n");
  286|       |
  287|    686|    uint8_t* authValue = NULL;
  288|    686|    int authValueLen = 0;
  289|    686|    uint8_t* authMechanism = NULL;
  290|    686|    int authMechLen = 0;
  291|    686|    bool userInfoValid = false;
  292|       |
  293|   508k|    while (bufPos < maxBufPos)
  ------------------
  |  Branch (293:12): [True: 507k, False: 569]
  ------------------
  294|   507k|    {
  295|   507k|        uint8_t tag = buffer[bufPos++];
  296|   507k|        int len;
  297|       |
  298|   507k|        bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  299|       |
  300|   507k|        if (bufPos < 0)
  ------------------
  |  Branch (300:13): [True: 67, False: 507k]
  ------------------
  301|     67|        {
  302|     67|            if (DEBUG_ACSE)
  ------------------
  |  |   32|     67|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 67]
  |  |  ------------------
  ------------------
  303|      0|                printf("ACSE: Invalid PDU!\n");
  304|     67|            return ACSE_ASSOCIATE_FAILED;
  305|     67|        }
  306|       |
  307|   507k|        if (len == 0)
  ------------------
  |  Branch (307:13): [True: 18.6k, False: 489k]
  ------------------
  308|  18.6k|            continue;
  309|       |
  310|   489k|        if (bufPos + len > maxBufPos)
  ------------------
  |  Branch (310:13): [True: 0, False: 489k]
  ------------------
  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|   489k|        switch (tag)
  318|   489k|        {
  319|      0|        case 0xa1: /* application context name */
  ------------------
  |  Branch (319:9): [True: 0, False: 489k]
  ------------------
  320|      0|            bufPos += len;
  321|      0|            break;
  322|       |
  323|    328|        case 0xa2: /* called AP title */
  ------------------
  |  Branch (323:9): [True: 328, False: 488k]
  ------------------
  324|    328|            bufPos += len;
  325|    328|            break;
  326|      0|        case 0xa3: /* called AE qualifier */
  ------------------
  |  Branch (326:9): [True: 0, False: 489k]
  ------------------
  327|      0|            bufPos += len;
  328|      0|            break;
  329|       |
  330|  27.0k|        case 0xa6: /* calling AP title */
  ------------------
  |  Branch (330:9): [True: 27.0k, False: 461k]
  ------------------
  331|  27.0k|            {
  332|  27.0k|                if (len >= 2 && buffer[bufPos] == 0x06)
  ------------------
  |  Branch (332:21): [True: 21.3k, False: 5.69k]
  |  Branch (332:33): [True: 19.9k, False: 1.39k]
  ------------------
  333|  19.9k|                {
  334|       |                    /* ap-title-form2 */
  335|       |
  336|  19.9k|                    int innerLength = buffer[bufPos + 1];
  337|       |
  338|  19.9k|                    if ((innerLength >= 0) && (innerLength == len - 2))
  ------------------
  |  Branch (338:25): [True: 19.9k, False: 0]
  |  Branch (338:47): [True: 19.4k, False: 537]
  ------------------
  339|  19.4k|                        BerDecoder_decodeOID(buffer, bufPos + 2, innerLength, &(self->applicationReference.apTitle));
  340|  19.9k|                }
  341|  27.0k|            }
  342|  27.0k|            bufPos += len;
  343|  27.0k|            break;
  344|       |
  345|  31.7k|        case 0xa7: /* calling AE qualifier */
  ------------------
  |  Branch (345:9): [True: 31.7k, False: 457k]
  ------------------
  346|  31.7k|            {
  347|  31.7k|                if (len >= 2 && buffer[bufPos] == 0x02)
  ------------------
  |  Branch (347:21): [True: 31.2k, False: 491]
  |  Branch (347:33): [True: 27.1k, False: 4.13k]
  ------------------
  348|  27.1k|                {
  349|       |                    /* ae-qualifier-form2 */
  350|       |
  351|  27.1k|                    int innerLength = buffer[bufPos + 1];
  352|       |
  353|  27.1k|                    if ((innerLength >= 0) && (innerLength == len - 2))
  ------------------
  |  Branch (353:25): [True: 27.1k, False: 0]
  |  Branch (353:47): [True: 22.9k, False: 4.16k]
  ------------------
  354|  22.9k|                        self->applicationReference.aeQualifier = BerDecoder_decodeInt32(buffer, innerLength, bufPos + 2);
  355|  27.1k|                }
  356|  31.7k|            }
  357|  31.7k|            bufPos += len;
  358|  31.7k|            break;
  359|       |
  360|      0|        case 0x8a: /* sender ACSE requirements */
  ------------------
  |  Branch (360:9): [True: 0, False: 489k]
  ------------------
  361|      0|            bufPos += len;
  362|      0|            break;
  363|       |
  364|    397|        case 0x8b: /* (authentication) mechanism name */
  ------------------
  |  Branch (364:9): [True: 397, False: 488k]
  ------------------
  365|    397|            authMechLen = len;
  366|    397|            authMechanism = buffer + bufPos;
  367|    397|            bufPos += len;
  368|    397|            break;
  369|       |
  370|    746|        case 0xac: /* authentication value */
  ------------------
  |  Branch (370:9): [True: 746, False: 488k]
  ------------------
  371|    746|            bufPos++;
  372|       |
  373|    746|            bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  374|    746|            if (bufPos < 0)
  ------------------
  |  Branch (374:17): [True: 2, False: 744]
  ------------------
  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|    744|            authValueLen = len;
  382|    744|            authValue = buffer + bufPos;
  383|    744|            bufPos += len;
  384|    744|            break;
  385|       |
  386|  6.42k|        case 0xbe: /* user information */
  ------------------
  |  Branch (386:9): [True: 6.42k, False: 482k]
  ------------------
  387|  6.42k|            if (buffer[bufPos] != 0x28)
  ------------------
  |  Branch (387:17): [True: 1.18k, False: 5.24k]
  ------------------
  388|  1.18k|            {
  389|  1.18k|                if (DEBUG_ACSE)
  ------------------
  |  |   32|  1.18k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 1.18k]
  |  |  ------------------
  ------------------
  390|      0|                    printf("ACSE: invalid user info\n");
  391|  1.18k|                bufPos += len;
  392|  1.18k|            }
  393|  5.24k|            else
  394|  5.24k|            {
  395|  5.24k|                bufPos++;
  396|       |
  397|  5.24k|                bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  398|       |
  399|  5.24k|                if (bufPos < 0)
  ------------------
  |  Branch (399:21): [True: 4, False: 5.24k]
  ------------------
  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.24k|                bufPos = parseUserInformation(self, buffer, bufPos, bufPos + len, &userInfoValid);
  407|       |
  408|  5.24k|                if (bufPos < 0)
  ------------------
  |  Branch (408:21): [True: 44, False: 5.19k]
  ------------------
  409|     44|                {
  410|     44|                    if (DEBUG_ACSE)
  ------------------
  |  |   32|     44|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 44]
  |  |  ------------------
  ------------------
  411|      0|                        printf("ACSE: Invalid PDU!\n");
  412|     44|                    return ACSE_ASSOCIATE_FAILED;
  413|     44|                }
  414|  5.24k|            }
  415|  6.37k|            break;
  416|       |
  417|  6.37k|        case 0x00: /* indefinite length end tag -> ignore */
  ------------------
  |  Branch (417:9): [True: 5.35k, False: 483k]
  ------------------
  418|  5.35k|            break;
  419|       |
  420|   416k|        default: /* ignore unknown tag */
  ------------------
  |  Branch (420:9): [True: 416k, False: 72.0k]
  ------------------
  421|   416k|            if (DEBUG_ACSE)
  ------------------
  |  |   32|   416k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 416k]
  |  |  ------------------
  ------------------
  422|      0|                printf("ACSE: parseAarqPdu: unknown tag %02x\n", tag);
  423|       |
  424|   416k|            bufPos += len;
  425|   416k|            break;
  426|   489k|        }
  427|   489k|    }
  428|       |
  429|    569|    if (checkAuthentication(self, authMechanism, authMechLen, authValue, authValueLen) == false)
  ------------------
  |  Branch (429:9): [True: 0, False: 569]
  ------------------
  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|    569|    if (userInfoValid == false)
  ------------------
  |  Branch (437:9): [True: 558, False: 11]
  ------------------
  438|    558|    {
  439|    558|        if (DEBUG_ACSE)
  ------------------
  |  |   32|    558|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 558]
  |  |  ------------------
  ------------------
  440|      0|            printf("ACSE: parseAarqPdu: user info invalid!\n");
  441|       |
  442|    558|        return ACSE_ASSOCIATE_FAILED;
  443|    558|    }
  444|       |
  445|     11|    return ACSE_ASSOCIATE;
  446|    569|}
acse.c:parseUserInformation:
  119|  9.12k|{
  120|  9.12k|    if (DEBUG_ACSE)
  ------------------
  |  |   32|  9.12k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 9.12k]
  |  |  ------------------
  ------------------
  121|      0|        printf("ACSE: parseUserInformation %i %i\n", bufPos, maxBufPos);
  122|       |
  123|  9.12k|    bool hasindirectReference = false;
  124|  9.12k|    bool isDataValid = false;
  125|       |
  126|   194k|    while (bufPos < maxBufPos)
  ------------------
  |  Branch (126:12): [True: 185k, False: 9.03k]
  ------------------
  127|   185k|    {
  128|   185k|        uint8_t tag = buffer[bufPos++];
  129|   185k|        int len;
  130|       |
  131|   185k|        bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  132|       |
  133|   185k|        if ((bufPos < 0) || (bufPos + len > maxBufPos))
  ------------------
  |  Branch (133:13): [True: 88, False: 185k]
  |  Branch (133:29): [True: 0, False: 185k]
  ------------------
  134|     88|        {
  135|     88|            *userInfoValid = false;
  136|     88|            return -1;
  137|     88|        }
  138|       |
  139|   185k|        if (len == 0)
  ------------------
  |  Branch (139:13): [True: 23.4k, False: 161k]
  ------------------
  140|  23.4k|            continue;
  141|       |
  142|   161k|        switch (tag)
  143|   161k|        {
  144|       |
  145|   102k|        case 0x02: /* indirect-reference */
  ------------------
  |  Branch (145:9): [True: 102k, False: 58.8k]
  ------------------
  146|   102k|            self->nextReference = BerDecoder_decodeUint32(buffer, len, bufPos);
  147|   102k|            bufPos += len;
  148|   102k|            hasindirectReference = true;
  149|   102k|            break;
  150|       |
  151|  2.94k|        case 0xa0: /* encoding */
  ------------------
  |  Branch (151:9): [True: 2.94k, False: 158k]
  ------------------
  152|  2.94k|            isDataValid = true;
  153|       |
  154|  2.94k|            self->userDataBufferSize = len;
  155|  2.94k|            self->userDataBuffer = buffer + bufPos;
  156|       |
  157|  2.94k|            bufPos += len;
  158|       |
  159|  2.94k|            break;
  160|       |
  161|  55.9k|        default: /* ignore unknown tag */
  ------------------
  |  Branch (161:9): [True: 55.9k, False: 105k]
  ------------------
  162|  55.9k|            bufPos += len;
  163|   161k|        }
  164|   161k|    }
  165|       |
  166|  9.03k|    if (DEBUG_ACSE)
  ------------------
  |  |   32|  9.03k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 9.03k]
  |  |  ------------------
  ------------------
  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.03k|    if (hasindirectReference && isDataValid)
  ------------------
  |  Branch (175:9): [True: 5.58k, False: 3.44k]
  |  Branch (175:33): [True: 473, False: 5.11k]
  ------------------
  176|    473|        *userInfoValid = true;
  177|  8.56k|    else
  178|  8.56k|        *userInfoValid = false;
  179|       |
  180|  9.03k|    return bufPos;
  181|  9.12k|}
acse.c:checkAuthentication:
   84|    569|{
   85|    569|    self->securityToken = NULL;
   86|       |
   87|    569|    if (self->authenticator != NULL)
  ------------------
  |  Branch (87:9): [True: 0, False: 569]
  ------------------
   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|    569|    else
  114|    569|        return true;
  115|    569|}
acse.c:parseAarePdu:
  185|    403|{
  186|    403|    if (DEBUG_ACSE)
  ------------------
  |  |   32|    403|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 403]
  |  |  ------------------
  ------------------
  187|      0|        printf("ACSE: parse AARE PDU\n");
  188|       |
  189|    403|    bool userInfoValid = false;
  190|       |
  191|    403|    uint32_t result = 99;
  192|       |
  193|   665k|    while (bufPos < maxBufPos)
  ------------------
  |  Branch (193:12): [True: 665k, False: 293]
  ------------------
  194|   665k|    {
  195|   665k|        uint8_t tag = buffer[bufPos++];
  196|   665k|        int len;
  197|       |
  198|   665k|        bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  199|       |
  200|   665k|        if (bufPos < 0)
  ------------------
  |  Branch (200:13): [True: 58, False: 665k]
  ------------------
  201|     58|        {
  202|     58|            if (DEBUG_ACSE)
  ------------------
  |  |   32|     58|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 58]
  |  |  ------------------
  ------------------
  203|      0|                printf("ACSE: Invalid PDU!\n");
  204|     58|            return ACSE_ERROR;
  205|     58|        }
  206|       |
  207|   665k|        if (len == 0)
  ------------------
  |  Branch (207:13): [True: 15.4k, False: 650k]
  ------------------
  208|  15.4k|            continue;
  209|       |
  210|   650k|        if (bufPos + len > maxBufPos)
  ------------------
  |  Branch (210:13): [True: 0, False: 650k]
  ------------------
  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|   650k|        switch (tag)
  218|   650k|        {
  219|      8|        case 0xa1: /* application context name */
  ------------------
  |  Branch (219:9): [True: 8, False: 650k]
  ------------------
  220|      8|            bufPos += len;
  221|      8|            break;
  222|       |
  223|  2.40k|        case 0xa2: /* result */
  ------------------
  |  Branch (223:9): [True: 2.40k, False: 647k]
  ------------------
  224|  2.40k|            bufPos++;
  225|       |
  226|  2.40k|            bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  227|  2.40k|            if (bufPos < 0)
  ------------------
  |  Branch (227:17): [True: 4, False: 2.40k]
  ------------------
  228|      4|                return ACSE_ERROR;
  229|       |
  230|  2.40k|            result = BerDecoder_decodeUint32(buffer, len, bufPos);
  231|       |
  232|  2.40k|            bufPos += len;
  233|  2.40k|            break;
  234|       |
  235|      1|        case 0xa3: /* result source diagnostic */
  ------------------
  |  Branch (235:9): [True: 1, False: 650k]
  ------------------
  236|      1|            bufPos += len;
  237|      1|            break;
  238|       |
  239|  4.51k|        case 0xbe: /* user information */
  ------------------
  |  Branch (239:9): [True: 4.51k, False: 645k]
  ------------------
  240|  4.51k|            if (buffer[bufPos] != 0x28)
  ------------------
  |  Branch (240:17): [True: 633, False: 3.88k]
  ------------------
  241|    633|            {
  242|    633|                if (DEBUG_ACSE)
  ------------------
  |  |   32|    633|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 633]
  |  |  ------------------
  ------------------
  243|      0|                    printf("ACSE: invalid user info\n");
  244|    633|                bufPos += len;
  245|    633|            }
  246|  3.88k|            else
  247|  3.88k|            {
  248|  3.88k|                bufPos++;
  249|       |
  250|  3.88k|                bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
  251|  3.88k|                if (bufPos < 0)
  ------------------
  |  Branch (251:21): [True: 4, False: 3.87k]
  ------------------
  252|      4|                    return ACSE_ERROR;
  253|       |
  254|  3.87k|                bufPos = parseUserInformation(self, buffer, bufPos, bufPos + len, &userInfoValid);
  255|  3.87k|                if (bufPos < 0)
  ------------------
  |  Branch (255:21): [True: 44, False: 3.83k]
  ------------------
  256|     44|                    return ACSE_ERROR;
  257|  3.87k|            }
  258|  4.46k|            break;
  259|       |
  260|  4.46k|        case 0x00: /* indefinite length end tag -> ignore */
  ------------------
  |  Branch (260:9): [True: 3.99k, False: 646k]
  ------------------
  261|  3.99k|            break;
  262|       |
  263|   639k|        default: /* ignore unknown tag */
  ------------------
  |  Branch (263:9): [True: 639k, False: 10.9k]
  ------------------
  264|   639k|            if (DEBUG_ACSE)
  ------------------
  |  |   32|   639k|#define DEBUG_ACSE 0
  |  |  ------------------
  |  |  |  Branch (32:20): [Folded, False: 639k]
  |  |  ------------------
  ------------------
  265|      0|                printf("ACSE: parseAarePdu: unknown tag %02x\n", tag);
  266|       |
  267|   639k|            bufPos += len;
  268|   639k|            break;
  269|   650k|        }
  270|   650k|    }
  271|       |
  272|    293|    if (!userInfoValid)
  ------------------
  |  Branch (272:9): [True: 277, False: 16]
  ------------------
  273|    277|        return ACSE_ERROR;
  274|       |
  275|     16|    if (result != 0)
  ------------------
  |  Branch (275:9): [True: 15, False: 1]
  ------------------
  276|     15|        return ACSE_ASSOCIATE_FAILED;
  277|       |
  278|      1|    return ACSE_ASSOCIATE;
  279|     16|}

