diff options
Diffstat (limited to 'contrib/unbound/smallapp/unbound-anchor.c')
-rw-r--r-- | contrib/unbound/smallapp/unbound-anchor.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/contrib/unbound/smallapp/unbound-anchor.c b/contrib/unbound/smallapp/unbound-anchor.c index 708731a09dd8..55d363da70bb 100644 --- a/contrib/unbound/smallapp/unbound-anchor.c +++ b/contrib/unbound/smallapp/unbound-anchor.c @@ -382,7 +382,7 @@ read_cert_file(const char* file) STACK_OF(X509)* sk; FILE* in; int content = 0; - char buf[128]; + long flen; if(file == NULL || strcmp(file, "") == 0) { return NULL; } @@ -399,6 +399,11 @@ read_cert_file(const char* file) #endif return NULL; } + if(fseek(in, 0, SEEK_END) < 0) + printf("%s fseek: %s\n", file, strerror(errno)); + flen = ftell(in); + if(fseek(in, 0, SEEK_SET) < 0) + printf("%s fseek: %s\n", file, strerror(errno)); while(!feof(in)) { X509* x = PEM_read_X509(in, NULL, NULL, NULL); if(x == NULL) { @@ -414,8 +419,9 @@ read_cert_file(const char* file) exit(0); } content = 1; - /* read away newline after --END CERT-- */ - if(!fgets(buf, (int)sizeof(buf), in)) + /* feof may not be true yet, but if the position is + * at end of file, stop reading more certificates. */ + if(ftell(in) == flen) break; } fclose(in); |