static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_t len)

{

    char *mechname = malloc(len + 1);

    if (!mechname) {

        VNC_DEBUG("Out of memory reading mechname\n");

        vnc_client_error(vs);

    }

    strncpy(mechname, (char*)data, len);

    mechname[len] = '\0';

    VNC_DEBUG("Got client mechname '%s' check against '%s'\n",

              mechname, vs->sasl.mechlist);



    if (strncmp(vs->sasl.mechlist, mechname, len) == 0) {

        if (vs->sasl.mechlist[len] != '\0' &&

            vs->sasl.mechlist[len] != ',') {

            VNC_DEBUG("One %d", vs->sasl.mechlist[len]);

            vnc_client_error(vs);

            return -1;

        }

    } else {

        char *offset = strstr(vs->sasl.mechlist, mechname);

        VNC_DEBUG("Two %p\n", offset);

        if (!offset) {

            vnc_client_error(vs);

            return -1;

        }

        VNC_DEBUG("Two '%s'\n", offset);

        if (offset[-1] != ',' ||

            (offset[len] != '\0'&&

             offset[len] != ',')) {

            vnc_client_error(vs);

            return -1;

        }

    }



    free(vs->sasl.mechlist);

    vs->sasl.mechlist = mechname;



    VNC_DEBUG("Validated mechname '%s'\n", mechname);

    vnc_read_when(vs, protocol_client_auth_sasl_start_len, 4);

    return 0;

}

static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_t len)

{

    char *mechname = malloc(len + 1);

    if (!mechname) {

        VNC_DEBUG("Out of memory reading mechname\n");

        vnc_client_error(vs);

    }

    strncpy(mechname, (char*)data, len);

    mechname[len] = '\0';

    VNC_DEBUG("Got client mechname '%s' check against '%s'\n",

              mechname, vs->sasl.mechlist);



    if (strncmp(vs->sasl.mechlist, mechname, len) == 0) {

        if (vs->sasl.mechlist[len] != '\0' &&

            vs->sasl.mechlist[len] != ',') {

            VNC_DEBUG("One %d", vs->sasl.mechlist[len]);

            vnc_client_error(vs);

            return -1;

        }

    } else {

        char *offset = strstr(vs->sasl.mechlist, mechname);

        VNC_DEBUG("Two %p\n", offset);

        if (!offset) {

            vnc_client_error(vs);

            return -1;

        }

        VNC_DEBUG("Two '%s'\n", offset);

        if (offset[-1] != ',' ||

            (offset[len] != '\0'&&

             offset[len] != ',')) {

            vnc_client_error(vs);

            return -1;

        }

    }



    free(vs->sasl.mechlist);

    vs->sasl.mechlist = mechname;



    VNC_DEBUG("Validated mechname '%s'\n", mechname);

    vnc_read_when(vs, protocol_client_auth_sasl_start_len, 4);

    return 0;

}

            vnc_client_error(vs);             return -1;             vnc_client_error(vs);             return -1;             vnc_client_error(vs);             return -1;
static int FUNC_0(VncState *VAR_0, uint8_t *VAR_1, size_t VAR_2)

{

    char *VAR_3 = malloc(VAR_2 + 1);

    if (!VAR_3) {

        VNC_DEBUG("Out of memory reading VAR_3\n");

        vnc_client_error(VAR_0);

    }

    strncpy(VAR_3, (char*)VAR_1, VAR_2);

    VAR_3[VAR_2] = '\0';

    VNC_DEBUG("Got client VAR_3 '%s' check against '%s'\n",

              VAR_3, VAR_0->sasl.mechlist);



    if (strncmp(VAR_0->sasl.mechlist, VAR_3, VAR_2) == 0) {

        if (VAR_0->sasl.mechlist[VAR_2] != '\0' &&

            VAR_0->sasl.mechlist[VAR_2] != ',') {

            VNC_DEBUG("One %d", VAR_0->sasl.mechlist[VAR_2]);

            vnc_client_error(VAR_0);

            return -1;

        }

    } else {

        char *VAR_4 = strstr(VAR_0->sasl.mechlist, VAR_3);

        VNC_DEBUG("Two %p\n", VAR_4);

        if (!VAR_4) {

            vnc_client_error(VAR_0);

            return -1;

        }

        VNC_DEBUG("Two '%s'\n", VAR_4);

        if (VAR_4[-1] != ',' ||

            (VAR_4[VAR_2] != '\0'&&

             VAR_4[VAR_2] != ',')) {

            vnc_client_error(VAR_0);

            return -1;

        }

    }



    free(VAR_0->sasl.mechlist);

    VAR_0->sasl.mechlist = VAR_3;



    VNC_DEBUG("Validated VAR_3 '%s'\n", VAR_3);

    vnc_read_when(VAR_0, protocol_client_auth_sasl_start_len, 4);

    return 0;

}

static int FUNC_0(VncState *VAR_0, uint8_t *VAR_1, size_t VAR_2)
{ char *VAR_3 = malloc(VAR_2 + 1); if (!VAR_3) { VNC_DEBUG("Out of memory reading VAR_3\n"); vnc_client_error(VAR_0); } strncpy(VAR_3, (char*)VAR_1, VAR_2); VAR_3[VAR_2] = '\0'; VNC_DEBUG("Got client VAR_3 '%s' check against '%s'\n",
VAR_3, VAR_0->sasl.mechlist); if (strncmp(VAR_0->sasl.mechlist, VAR_3, VAR_2) == 0) { if (VAR_0->sasl.mechlist[VAR_2] != '\0' &&
VAR_0->sasl.mechlist[VAR_2] != ',') { VNC_DEBUG("One %d", VAR_0->sasl.mechlist[VAR_2]); vnc_client_error(VAR_0); return -1; } } else { char *VAR_4 = strstr(VAR_0->sasl.mechlist, VAR_3); VNC_DEBUG("Two %p\n", VAR_4); if (!VAR_4) { vnc_client_error(VAR_0); return -1; } VNC_DEBUG("Two '%s'\n", VAR_4); if (VAR_4[-1] != ',' ||
(VAR_4[VAR_2] != '\0'&&
VAR_4[VAR_2] != ',')) { vnc_client_error(VAR_0); return -1; } } free(VAR_0->sasl.mechlist); VAR_0->sasl.mechlist = VAR_3; VNC_DEBUG("Validated VAR_3 '%s'\n", VAR_3); vnc_read_when(VAR_0, protocol_client_auth_sasl_start_len, 4); return 0; }