# HG changeset patch # User Olaf Wintermann # Date 1443976515 -7200 # Node ID a316613205dcce9e8d7a56e0dc72e82f6be1c5c5 # Parent 37fb12574acd34ce8093044675bbf90b14c35c54 fixed some memory leaks, content verification and dav info diff -r 37fb12574acd -r a316613205dc dav/main.c --- a/dav/main.c Sun Oct 04 15:57:40 2015 +0200 +++ b/dav/main.c Sun Oct 04 18:35:15 2015 +0200 @@ -1077,9 +1077,11 @@ printf("name: %s\n", res->name); printf("path: %s\n", res->path); - char *url = util_path_to_url(sn, res->path); + char *server = util_url_base(sn->base_url); + char *url = util_concat_path(server, res->href); printf("url: %s\n", url); free(url); + free(server); if(res->iscollection) { printf("type: collection\n"); diff -r 37fb12574acd -r a316613205dc libidav/resource.c --- a/libidav/resource.c Sun Oct 04 15:57:40 2015 +0200 +++ b/libidav/resource.c Sun Oct 04 18:35:15 2015 +0200 @@ -650,10 +650,11 @@ // check encryption AESDecrypter *dec = NULL; + DavKey *key = NULL; if(DAV_DECRYPT_CONTENT(sn)) { char *keyname = dav_get_property_ns(res, DAV_NS, "crypto-key"); if(keyname) { - DavKey *key = dav_context_get_key(sn->context, keyname); + key = dav_context_get_key(sn->context, keyname); if(key) { dec = aes_decrypter_new(key, stream, write_fnc); stream = dec; @@ -686,13 +687,13 @@ curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); if(ret == CURLE_OK && (status >= 200 && status < 300)) { int verify_failed = 0; - if(DAV_DECRYPT_CONTENT(sn)) { + if(DAV_DECRYPT_CONTENT(sn) && key) { // try to verify the content char *res_hash = dav_get_property_ns(res, DAV_NS, "crypto-hash"); if(res_hash) { size_t len = 0; - char *dec_hash = aes_decrypt(res_hash, &len, sn->key); + char *dec_hash = aes_decrypt(res_hash, &len, key); char *hex_hash = util_hexstr(dec_hash, 32); if(strcmp(hash, hex_hash)) { verify_failed = 1; @@ -701,6 +702,9 @@ free(hex_hash); } } + if(hash) { + free(hash); + } if(verify_failed) { res->session->error = DAV_CONTENT_VERIFICATION_ERROR; @@ -710,6 +714,9 @@ res->session->error = DAV_OK; return 0; } else { + if(hash) { + free(hash); + } dav_session_set_error(res->session, ret, status); return 1; } diff -r 37fb12574acd -r a316613205dc libidav/session.c --- a/libidav/session.c Sun Oct 04 15:57:40 2015 +0200 +++ b/libidav/session.c Sun Oct 04 18:35:15 2015 +0200 @@ -304,9 +304,12 @@ ucx_buffer_puts(href, random_name); free(random_name); } - } + + // cleanup + free(elm.ptr); } + free(elms); // if necessary add a path separator if(p.ptr[p.length-1] == '/') { diff -r 37fb12574acd -r a316613205dc libidav/utils.c --- a/libidav/utils.c Sun Oct 04 15:57:40 2015 +0200 +++ b/libidav/utils.c Sun Oct 04 18:35:15 2015 +0200 @@ -87,6 +87,35 @@ } } +char* util_url_base(char *url) { + sstr_t u = sstr(url); + int len = u.length; + int slashcount = 0; + int slmax; + if(len > 7 && !strncasecmp(url, "http://", 7)) { + slmax = 3; + } else if(len > 8 && !strncasecmp(url, "https://", 8)) { + slmax = 3; + } else { + slmax = 1; + } + char c; + int i = 0; + for(i=0;i