diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-22 14:46:02 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-22 14:46:02 +0800 |
commit | 3cdd73a26962359742748b4048bdb842fe0e82ca (patch) | |
tree | 34acdb5dd0a4a36a20fc3da00398c3bac5a83ff4 | |
parent | 2bb484914b6118c5c9ace2d4b8aab6b28c9782b3 (diff) |
Fix query length
-rw-r--r-- | shopify.c | 6 |
1 files changed, 2 insertions, 4 deletions
@@ -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); |