Merge pull request #12060 from akallabeth/json-fix

Json fix
This commit is contained in:
akallabeth
2025-12-10 15:50:33 +01:00
committed by GitHub
5 changed files with 43 additions and 11 deletions

View File

@@ -244,7 +244,8 @@ static BOOL aad_get_nonce(rdpAad* aad)
json = WINPR_JSON_ParseWithLength((const char*)response, response_length);
if (!json)
{
WLog_Print(aad->log, WLOG_ERROR, "Failed to parse nonce response");
WLog_Print(aad->log, WLOG_ERROR, "Failed to parse nonce response: %s",
WINPR_JSON_GetErrorPtr());
goto fail;
}
@@ -536,7 +537,11 @@ static int aad_parse_state_initial(rdpAad* aad, wStream* s)
json = WINPR_JSON_ParseWithLength(jstr, jlen);
if (!json)
{
WLog_Print(aad->log, WLOG_ERROR, "WINPR_JSON_ParseWithLength failed: %s",
WINPR_JSON_GetErrorPtr());
goto fail;
}
if (!json_get_const_string(aad->log, json, "ts_nonce", &ts_nonce))
goto fail;
@@ -561,7 +566,11 @@ static int aad_parse_state_auth(rdpAad* aad, wStream* s)
json = WINPR_JSON_ParseWithLength(jstr, jlength);
if (!json)
{
WLog_Print(aad->log, WLOG_ERROR, "WINPR_JSON_ParseWithLength: %s",
WINPR_JSON_GetErrorPtr());
goto fail;
}
if (!json_get_number(aad->log, json, "authentication_result", &result))
goto fail;
@@ -851,8 +860,9 @@ char* freerdp_utils_aad_get_access_token(wLog* log, const char* data, size_t len
WINPR_JSON* json = WINPR_JSON_ParseWithLength(data, length);
if (!json)
{
WLog_Print(log, WLOG_ERROR, "Failed to parse access token response [got %" PRIuz " bytes",
length);
WLog_Print(log, WLOG_ERROR,
"Failed to parse access token response [got %" PRIuz " bytes: %s", length,
WINPR_JSON_GetErrorPtr());
goto cleanup;
}
@@ -1026,7 +1036,8 @@ WINPR_JSON* freerdp_utils_aad_get_wellknown(wLog* log, const char* base, const c
free(response);
if (!json)
WLog_Print(log, WLOG_ERROR, "failed to parse response as JSON");
WLog_Print(log, WLOG_ERROR, "failed to parse response as JSON: %s",
WINPR_JSON_GetErrorPtr());
return json;
}

View File

@@ -954,7 +954,8 @@ static BOOL arm_fill_gateway_parameters(rdpArm* arm, const char* message, size_t
BOOL status = FALSE;
if (!json)
{
WLog_Print(arm->log, WLOG_ERROR, "Response data is not valid JSON");
WLog_Print(arm->log, WLOG_ERROR, "Response data is not valid JSON: %s",
WINPR_JSON_GetErrorPtr());
return FALSE;
}
@@ -1078,8 +1079,7 @@ static BOOL arm_handle_bad_request(rdpArm* arm, const HttpResponse* response, BO
if (json == NULL)
{
const char* error_ptr = WINPR_JSON_GetErrorPtr();
if (error_ptr != NULL)
WLog_Print(arm->log, WLOG_ERROR, "NullPoException: %s", error_ptr);
WLog_Print(arm->log, WLOG_ERROR, "WINPR_JSON_ParseWithLength: %s", error_ptr);
return FALSE;
}

View File

@@ -288,6 +288,8 @@ BOOL freerdp_http_request(const char* url, const char* body, long* status_code,
}
}
WLog_Print(log, WLOG_DEBUG, "response[%" PRIuz "]:\n%s", *response_length,
(const char*)(*response));
ret = TRUE;
out:

View File

@@ -595,7 +595,12 @@ WINPR_PRAGMA_DIAG_POP
// WARNING: *do not* use thread-local storage for new code because it is not portable
// It is only used for VirtualChannelInit, and all FreeRDP channels use VirtualChannelInitEx
// The old virtual channel API is only realistically used on Windows where TLS is available
#if defined _WIN32 || defined __CYGWIN__
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
!defined(__STDC_NO_THREADS__) // C11
#include <threads.h>
#define WINPR_TLS thread_local
#elif defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define WINPR_TLS __thread
#else

View File

@@ -30,6 +30,8 @@
#error "The library detected is too old, need >= 2.13.0"
#endif
static WINPR_TLS char lasterror[256] = { 0 };
#if defined(WITH_DEBUG_JANSSON)
#include "../log.h"
#define TAG WINPR_TAG("jansson")
@@ -94,16 +96,28 @@ int WINPR_JSON_version(char* buffer, size_t len)
return _snprintf(buffer, len, "jansson %s", jansson_version_str());
}
static WINPR_JSON* updateError(WINPR_JSON* json, const json_error_t* error)
{
lasterror[0] = '\0';
if (!json)
(void)_snprintf(lasterror, sizeof(lasterror), "[%d:%d:%d] %s [%s]", error->line,
error->column, error->position, error->text, error->source);
return json;
}
WINPR_JSON* WINPR_JSON_Parse(const char* value)
{
json_error_t error = { 0 };
return revcast(json_loads(value, JSON_DECODE_ANY, &error));
WINPR_JSON* json = revcast(json_loads(value, JSON_DECODE_ANY, &error));
return updateError(json, &error);
}
WINPR_JSON* WINPR_JSON_ParseWithLength(const char* value, size_t buffer_length)
{
json_error_t error = { 0 };
return revcast(json_loadb(value, buffer_length, JSON_DECODE_ANY, &error));
const size_t slen = strnlen(value, buffer_length);
WINPR_JSON* json = revcast(json_loadb(value, slen, JSON_DECODE_ANY, &error));
return updateError(json, &error);
}
void WINPR_JSON_Delete(WINPR_JSON* item)
@@ -147,7 +161,7 @@ BOOL WINPR_JSON_HasObjectItem(const WINPR_JSON* object, const char* string)
const char* WINPR_JSON_GetErrorPtr(void)
{
return NULL;
return lasterror;
}
const char* WINPR_JSON_GetStringValue(WINPR_JSON* item)