From 3cdd73a26962359742748b4048bdb842fe0e82ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Thu, 22 Sep 2022 14:46:02 +0800 Subject: Fix query length --- shopify.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/shopify.c b/shopify.c index e27d43e..de4c1a7 100644 --- a/shopify.c +++ b/shopify.c @@ -221,13 +221,11 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, } shop_len = strlen(shop); char *query = NULL; - size_t query_len = 0; for (int i = 0; i < nparams; i++) { const char *key = params[i].key; const char *val = params[i].val; if (strcmp(key, "hmac")) { - if (query) - query_len = strlen(query); + size_t query_len = query ? strlen(query) : 0; bool ampersand_len = i != nparams - 1; query = realloc(query, query_len + strlen(key) + strlen("=") + strlen(val) @@ -254,7 +252,7 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, gcry_mac_open(&hd, GCRY_MAC_HMAC_SHA256, GCRY_MAC_FLAG_SECURE, NULL); gcry_mac_setkey(hd, api_secret_key, strlen(api_secret_key)); - gcry_mac_write(hd, query, query_len); + gcry_mac_write(hd, query, strlen(query)); static size_t hmacsha256_len = 32; unsigned char hmacsha256[hmacsha256_len]; gcry_mac_read(hd, hmacsha256, &hmacsha256_len); -- cgit v1.2.3