<commit_before>#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pwd.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <openssl/bn.h>
#include <openssl/pem.h>
#include <openssl/x509.h>

extern int match_user(X509 * x509, const char *login)
{
	char filename[PATH_MAX];
	struct passwd *pw;
	int found;
	BIO *in;

	if (!x509)
		return -1;

	if (!login)
		return -1;

	pw = getpwnam(login);
	if (!pw || !pw->pw_dir)
		return -1;

	snprintf(filename, PATH_MAX, "%s/.eid/authorized_certificates",
		 pw->pw_dir);

	in = BIO_new(BIO_s_file());
	if (!in)
		return -1;

	if (BIO_read_filename(in, filename) != 1) {
		syslog(LOG_ERR, "BIO_read_filename from %s failed\n", filename);
		return -1;
	}

	found = 0;
	for (;;) {
		X509 *cert = PEM_read_bio_X509(in, NULL, 0, NULL);
		if (!cert) {
			break;
		}
		if (X509_cmp(cert, x509) == 0) {
			found = 1;
		}
		X509_free(cert);
		if (found) {
			break;
		}
	}
	BIO_free(in);

	return found;
}
<commit_msg>reuse memory when parsing authorized_certificates<commit_after>#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pwd.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <openssl/bn.h>
#include <openssl/pem.h>
#include <openssl/x509.h>

extern int match_user(X509 * x509, const char *login)
{
	char filename[PATH_MAX];
	struct passwd *pw;
	int found;
	BIO *in;
	X509 *cert;

	if (!x509)
		return -1;

	if (!login)
		return -1;

	pw = getpwnam(login);
	if (!pw || !pw->pw_dir)
		return -1;

	snprintf(filename, PATH_MAX, "%s/.eid/authorized_certificates",
		 pw->pw_dir);

	in = BIO_new(BIO_s_file());
	if (!in)
		return -1;

	if (BIO_read_filename(in, filename) != 1) {
		syslog(LOG_ERR, "BIO_read_filename from %s failed\n", filename);
		return -1;
	}

	found = 0;
	for (cert = PEM_read_bio_X509(in, NULL, 0, NULL);
			cert != NULL;
			cert = PEM_read_bio_X509(in, &cert, 0, NULL)) {
		if (X509_cmp(cert, x509) == 0) {
			found = 1;
			break;
		}
	}
	if (cert) {
		X509_free(cert);
	}
	BIO_free(in);

	return found;
}

{'fraction_non_alphanumeric': 0.17503519474425153, 'fraction_numerical': 0.03660253402158611, 'mean_word_length': 3.8126410835214446, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5130504', 'n_tokens_mistral': 1059, 'n_tokens_neox': 927, 'n_words': 213}