diff --git a/mfapi/mfconn.c b/mfapi/mfconn.c index 93fca58..09b2756 100644 --- a/mfapi/mfconn.c +++ b/mfapi/mfconn.c @@ -156,6 +156,10 @@ const char *mfconn_create_call_signature(mfconn * conn, const char *url, signature_raw = strdup_printf("%d%s%s%s", (conn->secret_key % 256), conn->secret_time, api, args); + if (signature_raw == NULL) { + fprintf(stderr, "strdup_printf failed\n"); + return NULL; + } MD5((const unsigned char *)signature_raw, strlen(signature_raw), signature_enc); @@ -239,6 +243,11 @@ const char *mfconn_create_signed_get(mfconn * conn, int ssl, // append api GET args to api request api_request = (char *)realloc(api_request, bytes_to_alloc); + if (api_request == NULL) { + fprintf(stderr, "cannot allocate memory\n"); + return NULL; + } + strncat(api_request, api_args, api_args_len); strcat(api_request, signature); diff --git a/utils/strings.c b/utils/strings.c index 4849678..e17f7e0 100644 --- a/utils/strings.c +++ b/utils/strings.c @@ -42,6 +42,10 @@ char *strdup_printf(char *fmt, ...) bytes_to_allocate++; ret_str = (char *)malloc(bytes_to_allocate * sizeof(char)); + if (ret_str == NULL) { + fprintf(stderr, "failed to allocate memory\n"); + return NULL; + } va_start(ap, fmt); bytes_to_allocate = vsnprintf(ret_str, bytes_to_allocate, fmt, ap); diff --git a/valgrind.supp b/valgrind.supp index c63204e..d2fccd6 100644 --- a/valgrind.supp +++ b/valgrind.supp @@ -58,11 +58,58 @@ ... fun:curl_multi_perform fun:curl_easy_perform - fun:http_post_buf - fun:mfconn_api_user_get_session_token - fun:mfconn_create - fun:mfshell_cmd_auth - fun:mfshell_exec - fun:mfshell_parse_commands - fun:main + ... +} +{ + libcurl #1 + Memcheck:Leak + ... + fun:curl_global_init + fun:curl_easy_init + ... +} +{ + libcurl #2 + Memcheck:Cond + ... + fun:curl_multi_perform + fun:curl_easy_perform + ... +} +{ + libcurl #3 + Memcheck:Value8 + fun:Curl_raw_toupper + ... +} +{ + libcrypto + Memcheck:Leak + ... + fun:curl_multi_perform + fun:curl_easy_perform + ... +} +{ + openssl + Memcheck:Leak + fun:malloc + fun:CRYPTO_malloc + ... + fun:ssl_verify_cert_chain + ... +} +{ + jansson #1 + Memcheck:Cond + ... + obj:*/libjansson.so* + ... +} +{ + jansson #2 + Memcheck:Value8 + ... + obj:*/libjansson.so* + ... }