GHashTableIter iter;
gpointer key = NULL;
gpointer value = NULL;
+ int header_len = 0;
if (!header->hash_table)
return NULL;
g_hash_table_iter_init(&iter, header->hash_table);
while (g_hash_table_iter_next(&iter, &key, &value)) {
- header_str = (gchar *)malloc(sizeof(gchar) * (strlen(key) + 1 + 1 + strlen(value) + 1));
- sprintf(header_str, "%s: %s", (gchar*)key, (gchar*)value);
+ header_len = sizeof(gchar) * (strlen(key) + 1 + 1 + strlen(value) + 1);
+ header_str = (gchar *)malloc(header_len);
+ if (header_str == NULL)
+ return NULL;
+
+ snprintf(header_str, header_len, "%s: %s", (gchar*)key, (gchar*)value);
DBG("Header Field: %s\n", header_str);
header->header_list = curl_slist_append(header->header_list, header_str);
+
free(header_str);
}
http_transaction_set_ready_to_write(transaction, TRUE);
http_transaction_request_write_body(transaction, post_msg);
- sprintf(field_value, "%d", (int)strlen(post_msg));
+ snprintf(field_value, sizeof(field_value), "%d", (int)strlen(post_msg));
printf("[dbg] post size (%s)\n", field_value);
http_transaction_header_add_field(transaction, "Content-Length", field_value);