Changeset 653 for trunk/sx/sasl_gsasl.c

Show
Ignore:
Timestamp:
09/08/08 18:04:44 (5 months ago)
Author:
smoku
Message:

Checking return value of gsasl_base64_to/from(). Fixes #242

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/sx/sasl_gsasl.c

    r652 r653  
    336336        } else { 
    337337            /* decode and process */ 
    338             gsasl_base64_from(in, inlen, &buf, &buflen); 
     338            ret = gsasl_base64_from(in, inlen, &buf, &buflen); 
     339            if (ret != GSASL_OK) { 
     340                _sx_debug(ZONE, "gsasl_base64_from failed, no sasl for this conn; (%d): %s", ret, gsasl_strerror(ret)); 
     341                _sx_nad_write(s, _sx_sasl_failure(s, _sasl_err_MALFORMED_REQUEST), 0); 
     342            } 
    339343        } 
    340344 
     
    351355    else { 
    352356        /* decode and process */ 
    353         gsasl_base64_from(in, inlen, &buf, &buflen); 
     357        ret = gsasl_base64_from(in, inlen, &buf, &buflen); 
     358        if (ret != GSASL_OK) { 
     359            _sx_debug(ZONE, "gsasl_base64_from failed, no sasl for this conn; (%d): %s", ret, gsasl_strerror(ret)); 
     360            _sx_nad_write(s, _sx_sasl_failure(s, _sasl_err_MALFORMED_REQUEST), 0); 
     361        } 
     362 
    354363        if(!sd) { 
    355364            _sx_debug(ZONE, "response send before auth request enabling mechanism (decoded: %.*s)", buflen, buf); 
     
    385394 
    386395        /* encode the challenge */ 
    387         gsasl_base64_to(out, outlen, &buf, &buflen); 
     396        ret = gsasl_base64_to(out, outlen, &buf, &buflen); 
    388397         
     398        if (ret == GSASL_OK) { 
     399            _sx_nad_write(s, _sx_sasl_challenge(s, buf, buflen), 0); 
     400            free(buf); 
     401        } 
     402 
    389403        if(out != NULL) free(out); 
    390  
    391         _sx_nad_write(s, _sx_sasl_challenge(s, buf, buflen), 0); 
    392  
    393         free(buf); 
    394404 
    395405        return; 
     
    414424 
    415425    /* decode the response */ 
    416     gsasl_base64_from(in, inlen, &buf, &buflen); 
    417     _sx_debug(ZONE, "decoded data: %.*s", buflen, buf); 
    418  
    419     /* process the data */ 
    420     ret = gsasl_step(sd, buf, buflen, &out, &outlen); 
    421     if(buf != NULL) free(buf); 
    422  
    423     /* in progress */ 
    424     if(ret == GSASL_OK || ret == GSASL_NEEDS_MORE) { 
    425         _sx_debug(ZONE, "sasl handshake in progress (response: %.*s)", outlen, out); 
    426  
    427         /* encode the response */ 
    428         gsasl_base64_to(out, outlen, &buf, &buflen); 
    429  
     426    ret = gsasl_base64_from(in, inlen, &buf, &buflen); 
     427 
     428    if (ret == GSASL_OK) { 
     429        _sx_debug(ZONE, "decoded data: %.*s", buflen, buf); 
     430     
     431        /* process the data */ 
     432        ret = gsasl_step(sd, buf, buflen, &out, &outlen); 
     433        if(buf != NULL) free(buf); 
     434     
     435        /* in progress */ 
     436        if(ret == GSASL_OK || ret == GSASL_NEEDS_MORE) { 
     437            _sx_debug(ZONE, "sasl handshake in progress (response: %.*s)", outlen, out); 
     438     
     439            /* encode the response */ 
     440            ret = gsasl_base64_to(out, outlen, &buf, &buflen); 
     441     
     442            if (ret == GSASL_OK) { 
     443                _sx_nad_write(s, _sx_sasl_response(s, buf, buflen), 0); 
     444                if(buf != NULL) free(buf); 
     445            } 
     446     
     447            if(out != NULL) free(out); 
     448     
     449            return; 
     450        } 
     451     
    430452        if(out != NULL) free(out); 
    431  
    432         _sx_nad_write(s, _sx_sasl_response(s, buf, buflen), 0); 
    433  
    434         if(buf != NULL) free(buf); 
    435  
    436         return; 
    437     } 
    438  
    439     if(out != NULL) free(out); 
     453    } 
    440454 
    441455    /* its over */ 
     
    804818 
    805819    /* encode the challenge */ 
    806     gsasl_base64_to(out, outlen, &buf, &buflen); 
     820    ret = gsasl_base64_to(out, outlen, &buf, &buflen); 
     821    if(ret != GSASL_OK) { 
     822        _sx_debug(ZONE, "gsasl_base64_to failed, not authing; (%d): %s", ret, gsasl_strerror(ret)); 
     823 
     824        gsasl_finish(sd); 
     825 
     826        return 1; 
     827    } 
    807828    free(out); 
    808829