Hi all, before I go and fill a bug report I want to check if I'm doing something wrong here. Attached is a simple C program I wrote (based on the examples in the documentation) whose only purpose is to load a certificate. While trying to use this program on the attached certificate, the program segfaults and gdb shows that the segfault happened in the asn1_der_decoding function.
Does anyone has a suggestion where I might be wrong? BTW, I'm using gnutls shipped with Fedora 10. I'm speculating that the problem might be the use of UTF-8 character set in the certificate, but I'm not certain. Thanks for help, SG
#include <stdio.h>
#include <gnutls/x509.h>
#include <glib.h>
gnutls_datum_t *load_file(const char *file)
{
FILE *f;
size_t filelen, size;
void *ptr = NULL;
gnutls_datum_t *loaded_file = NULL;
if ((f = fopen(file, "r")) != NULL) {
if (fseek(f, 0, SEEK_END) != 0) {
perror("fseek");
goto out;
}
if ((filelen = ftell(f)) < 0) {
perror("ftell");
goto out;
}
if (fseek(f, 0, SEEK_SET) != 0) {
perror("fseek");
goto out;
}
ptr = g_malloc(filelen);
if ((size = fread(ptr, 1, filelen, f)) < filelen) {
if (size < 0)
perror("fread");
goto out;
}
loaded_file = g_malloc0(sizeof(gnutls_datum_t));
loaded_file->data = ptr;
loaded_file->size = filelen;
out:
fclose(f);
} else
perror ("fopen");
return loaded_file;
}
void unload_file(gnutls_datum_t *file)
{
g_free(file->data);
g_free(file);
}
int main(int argc, char **argv)
{
gnutls_x509_crt_t crt;
gnutls_datum_t *crt_file = NULL;
int ret;
if (argc != 2) {
fprintf (stderr, "Usage: %s <certificate>\n", argv[0]);
return 1;
}
if ((crt_file = load_file(argv[1])) == NULL)
return 1;
gnutls_x509_crt_init(&crt);
ret = gnutls_x509_crt_import(crt, crt_file, GNUTLS_X509_FMT_DER);
unload_file(crt_file);
if (ret < 0) {
fprintf(stderr, "Error: %s\n", gnutls_strerror(ret));
return 1;
}
}
cert.pem
Description: application/x509-ca-cert
_______________________________________________ Help-gnutls mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gnutls
