X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgtpkg-certs.c;h=66e425ee79595926954c261ead5e781c5b2c5ad9;hb=2a319cf90daa6e3b01e8139923f7073e1c9bcf28;hp=98118f9f873dd369780f01059ef3cc2752203141;hpb=e2de563d1ecb4585ce68521bd42f3ef45ac79f16;p=src%2Fapp-framework-main.git diff --git a/src/wgtpkg-certs.c b/src/wgtpkg-certs.c index 98118f9..66e425e 100644 --- a/src/wgtpkg-certs.c +++ b/src/wgtpkg-certs.c @@ -1,5 +1,7 @@ /* - Copyright 2015 IoT.bzh + Copyright (C) 2015-2019 IoT.bzh + + author: José Bollo Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,14 +17,14 @@ */ -#include #include #include "verbose.h" -#include "wgtpkg.h" +#include "wgtpkg-certs.h" +#include "wgtpkg-base64.h" struct x509l { - int count; + unsigned count; X509 **certs; }; @@ -30,7 +32,8 @@ static struct x509l certificates = { .count = 0, .certs = NULL }; static int add_certificate_x509(X509 *x) { - X509 **p = realloc(certificates.certs, (certificates.count + 1) * sizeof(X509*)); + X509 **p = realloc(certificates.certs, + (certificates.count + 1) * sizeof(X509*)); if (!p) { ERROR("reallocation failed for certificate"); return -1; @@ -40,7 +43,7 @@ static int add_certificate_x509(X509 *x) return 0; } -static int add_certificate_bin(const char *bin, int len) +static int add_certificate_bin(const char *bin, size_t len) { int rc; const char *b, *e; @@ -64,12 +67,15 @@ static int add_certificate_bin(const char *bin, int len) int add_certificate_b64(const char *b64) { char *d; - int l = base64dec(b64, &d); - if (l > 0) { - l = add_certificate_bin(d, l); + ssize_t l = base64dec(b64, &d); + int rc; + if (l < 0) + rc = -1; + else { + rc = add_certificate_bin(d, (size_t)l); free(d); } - return l; + return rc; } void clear_certificates()