[core,aad] clean up some mistakes

This commit is contained in:
Armin Novak 2023-03-09 21:13:51 +01:00 committed by akallabeth
parent 69aa1ff9db
commit 47ad94e4f9

View File

@ -153,11 +153,13 @@ static SSIZE_T stream_sprintf(wStream* s, const char* fmt, ...)
if (rc < 0) if (rc < 0)
return rc; return rc;
if (!Stream_EnsureRemainingCapacity(s, (size_t)rc)) if (!Stream_EnsureRemainingCapacity(s, (size_t)rc + 1))
return -1; return -1;
char* ptr = Stream_PointerAs(s, char); char* ptr = Stream_PointerAs(s, char);
const int rc2 = vsnprintf(ptr, rc, fmt, ap); va_start(ap, fmt);
const int rc2 = vsnprintf(ptr, rc + 1, fmt, ap);
va_end(ap);
if (rc != rc2) if (rc != rc2)
return -23; return -23;
if (!Stream_SafeSeek(s, (size_t)rc2)) if (!Stream_SafeSeek(s, (size_t)rc2))
@ -206,6 +208,7 @@ static BOOL json_get_object(wLog* wlog, cJSON* json, const char* key, cJSON** ob
WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NULL", key); WLog_Print(wlog, WLOG_ERROR, "[json] object for key '%s' is NULL", key);
return FALSE; return FALSE;
} }
*obj = prop;
return TRUE; return TRUE;
} }
@ -224,7 +227,6 @@ static BOOL json_get_number(wLog* wlog, cJSON* json, const char* key, double* re
*result = cJSON_GetNumberValue(prop); *result = cJSON_GetNumberValue(prop);
rc = TRUE; rc = TRUE;
fail: fail:
cJSON_Delete(prop);
return rc; return rc;
} }
@ -252,7 +254,6 @@ static BOOL json_get_const_string(wLog* wlog, cJSON* json, const char* key, cons
rc = str != NULL; rc = str != NULL;
fail: fail:
cJSON_Delete(prop);
return rc; return rc;
} }
@ -373,7 +374,7 @@ static BOOL aad_read_and_extract_token_from_json(rdpAad* aad, BIO* bio)
rc = TRUE; rc = TRUE;
fail: fail:
free(buffer); free(buffer);
cJSON_free(json); cJSON_Delete(json);
return rc; return rc;
} }
@ -401,7 +402,7 @@ static BOOL aad_read_and_extrace_nonce_from_json(rdpAad* aad, BIO* bio)
rc = TRUE; rc = TRUE;
fail: fail:
free(buffer); free(buffer);
cJSON_free(json); cJSON_Delete(json);
return rc; return rc;
} }
@ -459,7 +460,7 @@ int aad_client_begin(rdpAad* aad)
} }
aad->hostname = _strdup(hostname); aad->hostname = _strdup(hostname);
if (aad->hostname) if (!aad->hostname)
{ {
WLog_Print(aad->log, WLOG_ERROR, "_strdup(FreeRDP_ServerHostname) == NULL"); WLog_Print(aad->log, WLOG_ERROR, "_strdup(FreeRDP_ServerHostname) == NULL");
return -1; return -1;
@ -498,7 +499,7 @@ int aad_client_begin(rdpAad* aad)
goto fail; goto fail;
/* Construct and send the token request message */ /* Construct and send the token request message */
if (aad_send_token_request(aad, bio, auth_code)) if (!aad_send_token_request(aad, bio, auth_code))
goto fail; goto fail;
/* Extract the access token from the JSON response */ /* Extract the access token from the JSON response */
@ -614,7 +615,7 @@ static char* aad_final_digest(rdpAad* aad, EVP_MD_CTX* ctx)
goto fail; goto fail;
} }
size_t fsiglen = 0; size_t fsiglen = siglen;
const int dsf2 = EVP_DigestSignFinal(ctx, (BYTE*)buffer, &fsiglen); const int dsf2 = EVP_DigestSignFinal(ctx, (BYTE*)buffer, &fsiglen);
if (dsf2 <= 0) if (dsf2 <= 0)
{ {
@ -742,7 +743,7 @@ static int aad_parse_state_initial(rdpAad* aad, wStream* s)
ret = aad_send_auth_request(aad, ts_nonce); ret = aad_send_auth_request(aad, ts_nonce);
fail: fail:
cJSON_free(json); cJSON_Delete(json);
return ret; return ret;
} }
@ -772,7 +773,7 @@ static int aad_parse_state_auth(rdpAad* aad, wStream* s)
aad->state = AAD_STATE_FINAL; aad->state = AAD_STATE_FINAL;
rc = 1; rc = 1;
fail: fail:
cJSON_free(json); cJSON_Delete(json);
return rc; return rc;
} }