Code Review
/
src
/
app-framework-main.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
wgtpkg-unit: improve naming (minor)
[src/app-framework-main.git]
/
src
/
wgtpkg-certs.c
diff --git
a/src/wgtpkg-certs.c
b/src/wgtpkg-certs.c
index
1d8b976
..
0db72eb
100644
(file)
--- a/
src/wgtpkg-certs.c
+++ b/
src/wgtpkg-certs.c
@@
-1,5
+1,7
@@
/*
/*
- Copyright 2015 IoT.bzh
+ Copyright 2015, 2016, 2017 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@
-15,13
+17,14
@@
*/
*/
-#include <syslog.h>
#include <openssl/x509.h>
#include <openssl/x509.h>
-#include "wgtpkg.h"
+#include "verbose.h"
+#include "wgtpkg-certs.h"
+#include "wgtpkg-base64.h"
struct x509l {
struct x509l {
-
int
count;
+
unsigned
count;
X509 **certs;
};
X509 **certs;
};
@@
-29,9
+32,10
@@
static struct x509l certificates = { .count = 0, .certs = NULL };
static int add_certificate_x509(X509 *x)
{
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) {
if (!p) {
-
syslog(LOG_ERR,
"reallocation failed for certificate");
+
ERROR(
"reallocation failed for certificate");
return -1;
}
certificates.certs = p;
return -1;
}
certificates.certs = p;
@@
-39,16
+43,16
@@
static int add_certificate_x509(X509 *x)
return 0;
}
return 0;
}
-static int add_certificate_bin(const char *bin,
in
t len)
+static int add_certificate_bin(const char *bin,
size_
t len)
{
int rc;
const char *b, *e;
b = bin;
e = bin + len;
{
int rc;
const char *b, *e;
b = bin;
e = bin + len;
- while (
len
) {
+ while (
b < e
) {
X509 *x = d2i_X509(NULL, (const unsigned char **)&b, e-b);
if (x == NULL) {
X509 *x = d2i_X509(NULL, (const unsigned char **)&b, e-b);
if (x == NULL) {
-
syslog(LOG_ERR,
"d2i_X509 failed");
+
ERROR(
"d2i_X509 failed");
return -1;
}
rc = add_certificate_x509(x);
return -1;
}
rc = add_certificate_x509(x);
@@
-63,12
+67,15
@@
static int add_certificate_bin(const char *bin, int len)
int add_certificate_b64(const char *b64)
{
char *d;
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);
}
free(d);
}
- return
l
;
+ return
rc
;
}
void clear_certificates()
}
void clear_certificates()