libaacs | branch: master | npzacs <npz...@gmail.com> | Thu Jan 14 11:21:11 2016 
+0200| [ae8499ae6adea11f8569bd173bae342b491f36c1] | committer: npzacs

Check allocs

> http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=ae8499ae6adea11f8569bd173bae342b491f36c1
---

 src/file/keydbcfg.c |   24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/file/keydbcfg.c b/src/file/keydbcfg.c
index 669d010..a3c34c9 100644
--- a/src/file/keydbcfg.c
+++ b/src/file/keydbcfg.c
@@ -94,9 +94,12 @@ static char *_load_file(FILE *fp)
         return NULL;
     }
 
-    data      = malloc(file_size + 1);
-    read_size = fread(data, 1, file_size, fp);
+    data = malloc(file_size + 1);
+    if (!data) {
+        return NULL;
+    }
 
+    read_size = fread(data, 1, file_size, fp);
     if (read_size != file_size) {
         BD_DEBUG(DBG_FILE, "Error reading file\n");
         X_FREE(data);
@@ -208,7 +211,7 @@ static int _parse_pk_file(config_file *cf, FILE *fp)
                 BD_DEBUG(DBG_FILE, "Found processing key %s\n", str);
 
                 pk_list *e = calloc(1, sizeof(pk_list));
-
+                if (e) {
                 hexstring_to_hex_array(e->key, 16, str);
 
                 if (_is_duplicate_pk(cf->pkl, e->key)) {
@@ -220,6 +223,7 @@ static int _parse_pk_file(config_file *cf, FILE *fp)
                 }
 
                 result++;
+                }
             }
             X_FREE(str);
 
@@ -268,6 +272,7 @@ static int _parse_cert_file(config_file *cf, FILE *fp)
             BD_DEBUG(DBG_FILE, "Found certificate: %s %s\n", host_priv_key, 
host_cert);
 
             cert_list  *e = calloc(1, sizeof(cert_list));
+            if (e) {
             hexstring_to_hex_array(e->host_priv_key, 20, host_priv_key);
             hexstring_to_hex_array(e->host_cert, 92, host_cert);
 
@@ -279,6 +284,7 @@ static int _parse_cert_file(config_file *cf, FILE *fp)
                 cf->host_cert_list = e;
                 result = 1;
             }
+            }
         }
         X_FREE(host_priv_key);
         X_FREE(host_cert);
@@ -362,13 +368,13 @@ int keycache_save(const char *type, const uint8_t 
*disc_id, const uint8_t *key,
 {
     int result = 0;
     char *file = _keycache_file(type, disc_id);
+    char *key_str = calloc(2, len + 1);
 
-    if (file) {
+    if (file && key_str) {
         if (_mkpath(file)) {
             FILE *fp = fopen(file, "w");
 
             if (fp) {
-                char *key_str = calloc(1, len*2 + 1);
                 hex_array_to_hexstring(key_str, key, len);
 
                 if (fwrite(key_str, 1, len*2, fp) == len*2) {
@@ -379,15 +385,15 @@ int keycache_save(const char *type, const uint8_t 
*disc_id, const uint8_t *key,
                     BD_DEBUG(DBG_FILE, "Error writing to %s\n", file);
                 }
 
-                free(key_str);
 
                 fclose(fp);
             }
         }
-
-        X_FREE(file);
     }
 
+    X_FREE(key_str);
+    X_FREE(file);
+
     return result;
 }
 
@@ -404,7 +410,7 @@ int keycache_find(const char *type, const uint8_t *disc_id, 
uint8_t *key, unsign
 
             BD_DEBUG(DBG_FILE, "Reading %s\n", file);
 
-            if (fread(key_str, 1, len*2, fp) == len*2) {
+            if (key_str && fread(key_str, 1, len*2, fp) == len*2) {
 
                 result = hexstring_to_hex_array(key, len, key_str);
                 if (!result) {

_______________________________________________
libaacs-devel mailing list
libaacs-devel@videolan.org
https://mailman.videolan.org/listinfo/libaacs-devel

Reply via email to