Skip to content

tlshd/quic.c: quic_session_set_alpns() has no bound check on the ALPN count #165

Description

@warter666

quic_session_set_alpns() parses alpn_data into a fixed-size stack array without checking count against the array capacity:

gnutls_datum_t alpns[TLSHD_QUIC_MAX_ALPNS_LEN / 2];   /* 64 entries */
char *alpn = strtok(alpn_data, ",");
int count = 0;
while (alpn) {
    ...
    alpns[count].data = ...;
    count++;
    ...
}

Today this is safe only by a size coincidence: conn->alpns is char[128], so at most 64 single-character, comma-separated tokens fit (127 chars + NUL). But nothing enforces that relationship - if TLSHD_QUIC_MAX_ALPNS_LEN is ever raised, or the caller's buffer is filled differently (e.g. a longer ALPN string from a future config source), the loop overflows alpns.

Suggested fix:

while (alpn) {
    if (count >= (int)(sizeof(alpns) / sizeof(alpns[0])))
        break;   /* or log + fail */
    ...
}

Happy to send a patch if contributions are accepted without an OCA; otherwise please consider this a report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions