Browse Source

fix regressions

Now pEpEngine EngineTests actually runs through without hanging in
endless loops.
master
David Lanzendörfer 12 months ago
parent
commit
0e4ab27f09
4 changed files with 50 additions and 87 deletions
  1. +1
    -0
      src/main.c
  2. +19
    -50
      src/netpgp.c
  3. +24
    -26
      src/reader.c
  4. +6
    -11
      src/validate.c

+ 1
- 0
src/main.c View File

@ -709,6 +709,7 @@ main(int argc, char **argv)
p.cmd = SHOW_KEYS;
break;
case 'i':
netpgp_setvar(&netpgp, "need pubkey", "1");
p.cmd = IMPORT_KEY;
break;
default:


+ 19
- 50
src/netpgp.c View File

@ -124,8 +124,7 @@ conffile(netpgp_t *netpgp, char *homedir, char *userid, size_t length)
static int
size_arrays(netpgp_t *netpgp, unsigned needed)
{
char **temp;
char **temp;
if (netpgp->size == 0) {
/* only get here first time around */
netpgp->size = needed;
@ -182,53 +181,29 @@ readkeyring(netpgp_t *netpgp,
char *filename;
char f[MAXPATHLEN];
char *homedir;
int fd;
DIR* dir;
if ((filename = netpgp_getvar(netpgp, name)) == NULL) {
homedir = netpgp_getvar(netpgp, "homedir");
/* check if homedir exists and has the right access rights
* otherwise try to fix it and throw an error if that fails
*/
DIR* dir = opendir(homedir);
dir = opendir(homedir);
if (dir) {
/* Directory exists. */
closedir(dir);
} else if (ENOENT == errno) {
/* Directory does not exist. */
fprintf(stdout, "Homedir %s doesn't exist. Creating it.\n",homedir);
int check = mkdir(homedir,0777);
// check if directory is created or not
if (!check) {
fprintf(stdout, "Directory %s created\n", homedir);
} else {
fprintf(stderr, "Unable to create homedir %s!\n",homedir);
}
return 0;
if(mkdir(homedir,0777)) return 0;
} else {
/* opendir() failed for some other reason. */
fprintf(stderr, "Accessing homedir %s doesn't work. Check access rights!\n",homedir);
return 0;
}
(void) snprintf(f, sizeof(f), "%s/%s.gpg", homedir, name);
filename = f;
}
/*
* Here we've got the problem that either the keyring doesn't exist
* OR that the access rights are wrong.
* Let's try to do some smart trouble shooting and find out, WHAT
* exactly is wrong and try to fix it.
*/
FILE *file;
if ((file = fopen(filename, "r"))) { // file exists for reading. all peachy.
fclose(file);
} else {
if(creat(filename, 0600)<0) {
return 0;
}
}
pgp_keyring_fileread(netpgp->io, pubring, secring, 0, filename);
netpgp_setvar(netpgp, name, filename);
return 1;
}
@ -268,10 +243,8 @@ netpgp_init(netpgp_t *netpgp)
char *stream;
char *results;
int coredumps;
#ifdef HAVE_SYS_RESOURCE_H
struct rlimit limit;
struct rlimit limit;
coredumps = netpgp_getvar(netpgp, "coredumps") != NULL;
if (!coredumps) {
(void) memset(&limit, 0x0, sizeof(limit));
@ -284,7 +257,7 @@ netpgp_init(netpgp_t *netpgp)
#else
coredumps = 1;
#endif
if ((io = calloc(1, sizeof(*io))) == NULL) {
if ((io = malloc(sizeof(*io))) == NULL) {
(void) fprintf(stderr, "netpgp_init: bad alloc\n");
return 0;
}
@ -315,29 +288,29 @@ netpgp_init(netpgp_t *netpgp)
netpgp->io = io;
/* warn if core dumps are enabled */
if (coredumps) {
(void) fprintf(io->errs,
"netpgp: warning: core dumps enabled\n");
(void) fprintf(io->errs, "netpgp: warning: core dumps enabled\n");
}
/* get home directory - where keyrings are in a subdir */
if ((homedir = netpgp_getvar(netpgp, "homedir")) == NULL) {
(void) fprintf(io->errs, "netpgp: bad homedir\n");
return 0;
}
if ((netpgp->pubring = calloc(1, sizeof(pgp_keyring_t))) == NULL) {
if ((netpgp->pubring = malloc(sizeof(pgp_keyring_t))) == NULL) {
(void) fprintf(io->errs, "Can't alloc pubring\n");
return 0;
}
if ((netpgp->secring = calloc(1, sizeof(pgp_keyring_t))) == NULL) {
if ((netpgp->secring = malloc(sizeof(pgp_keyring_t))) == NULL) {
(void) fprintf(io->errs, "Can't alloc secring\n");
return 0;
}
memset(netpgp->secring,0,sizeof(pgp_keyring_t));
memset(netpgp->pubring,0,sizeof(pgp_keyring_t));
if (!readkeyring(netpgp,
"pubring",
netpgp->pubring,
netpgp->secring)) {
return 0;
/* only read public keys if we need to */
if (netpgp_getvar(netpgp, "need pubkey")) {
if (!readkeyring(netpgp, "pubring", netpgp->pubring, netpgp->secring)) {
return 0;
}
}
/* if a userid has been given, we'll use it */
if ((userid = netpgp_getvar(netpgp, "userid")) == NULL) {
@ -351,10 +324,7 @@ netpgp_init(netpgp_t *netpgp)
/* only read secret keys if we need to */
if (netpgp_getvar(netpgp, "need seckey")) {
/* read the secret ring */
if (!readkeyring(netpgp,
"secring",
netpgp->pubring,
netpgp->secring)) {
if (!readkeyring(netpgp, "secring", netpgp->pubring, netpgp->secring)) {
return 0;
}
/* now, if we don't have a valid user, use the first in secring */
@ -455,8 +425,7 @@ netpgp_save_ring(netpgp_t *netpgp,
unlink(swpfile);
if ((fd = pgp_setup_file_write(&output, swpfile, 0)) < 0) {
(void) fprintf(io->errs,
"netpgp_save_%s : can't setup write for %s\n", name, swpfile);
(void) fprintf(io->errs, "netpgp_save_%s : can't setup write for %s\n", name, swpfile);
return 0;
}


+ 24
- 26
src/reader.c View File

@ -320,7 +320,7 @@ typedef struct {
uint8_t *pushback;
unsigned pushbackc;
/* armoured block headers */
pgp_headers_t headers;
pgp_headers_t headers;
} dearmour_t;
static void
@ -393,8 +393,7 @@ set_lastseen_headerline(dearmour_t *dearmour, char *hdr, pgp_error_t **errors)
}
dearmour->lastseen = lastseen;
if (pgp_get_debug_level(__FILE__)) {
printf("set header: hdr=%s, dearmour->lastseen=%d, prev=%d\n",
hdr, dearmour->lastseen, prev);
printf("set header: hdr=%s, dearmour->lastseen=%d, prev=%d\n",hdr, dearmour->lastseen, prev);
}
switch (dearmour->lastseen) {
case NONE:
@ -508,7 +507,6 @@ static void
flush(dearmour_t *dearmour, pgp_cbdata_t *cbinfo)
{
pgp_packet_t content;
if (dearmour->unarmoredc > 0) {
content.u.unarmoured_text.data = dearmour->unarmoured;
content.u.unarmoured_text.length = (unsigned)dearmour->unarmoredc;
@ -1042,7 +1040,7 @@ armoured_data_reader(pgp_stream_t *stream, void *dest_, size_t length, pgp_error
pgp_cbdata_t *cbinfo)
{
pgp_packet_t content;
dearmour_t *dearmour;
dearmour_t *dearmour;
unsigned first;
uint8_t *dest = dest_;
char buf[1024];
@ -1050,7 +1048,6 @@ armoured_data_reader(pgp_stream_t *stream, void *dest_, size_t length, pgp_error
int ret;
dearmour = pgp_reader_get_arg(readinfo);
dearmour->pushback=NULL;
saved = (int)length;
if (dearmour->eof64 && !dearmour->buffered) {
@ -1309,17 +1306,24 @@ pgp_reader_push_dearmour(pgp_stream_t *parse_info)
*/
{
dearmour_t *dearmour;
pgp_headers_t headers;
if ((dearmour = malloc(sizeof(*dearmour))) == NULL) {
(void) fprintf(stderr, "pgp_reader_push_dearmour: bad alloc\n");
} else {
dearmour->seen_nl = 1;
/*
dearmour->allow_headers_without_gap=without_gap;
dearmour->allow_no_gap=no_gap;
dearmour->allow_trailing_whitespace=trailing_whitespace;
*/
dearmour->expect_sig = 0;
dearmour->got_sig = 0;
dearmour->seen_nl=1;
dearmour->allow_headers_without_gap=1;
dearmour->allow_no_gap=0;
dearmour->allow_trailing_whitespace=1;
dearmour->pushback=NULL;
dearmour->pushbackc=0;
dearmour->expect_sig=0;
dearmour->got_sig=0;
dearmour->state=0;
dearmour->eof64=0;
dearmour->buffered=1;
dearmour->unarmoredc=0;
dearmour->lastseen=0;
dearmour->headers=headers;
pgp_reader_push(parse_info, armoured_data_reader, armoured_data_destroyer, dearmour);
}
}
@ -1334,7 +1338,6 @@ void
pgp_reader_pop_dearmour(pgp_stream_t *stream)
{
dearmour_t *dearmour;
dearmour = pgp_reader_get_arg(pgp_readinfo(stream));
free(dearmour);
pgp_reader_pop(stream);
@ -1734,12 +1737,9 @@ fd_reader(pgp_stream_t *stream, void *dest, size_t length, pgp_error_t **errors,
{
mmap_reader_t *reader;
int n;
__PGP_USED(cbinfo);
reader = pgp_reader_get_arg(readinfo);
n = (int)read(reader->fd, dest, length);
if (n == 0) {
return 0;
}
@ -1821,8 +1821,7 @@ pgp_reader_set_memory(pgp_stream_t *stream, const void *buffer,
size_t length)
{
reader_mem_t *mem;
if ((mem = calloc(1, sizeof(*mem))) == NULL) {
if ((mem = malloc(sizeof(*mem))) == NULL) {
(void) fprintf(stderr, "pgp_reader_set_memory: bad alloc\n");
} else {
mem->buffer = buffer;
@ -1929,12 +1928,12 @@ int
pgp_setup_file_write(pgp_output_t **output, const char *filename,
unsigned allow_overwrite)
{
int fd = 0;
int flags = 0;
int fd = 0;
int flags = 0;
/*
* initialise needed structures for writing to file
*/
* initialise needed structures for writing to file
*/
if (filename == NULL) {
/* write to stdout */
fd = STDOUT_FILENO;
@ -2034,12 +2033,11 @@ pgp_setup_file_read(pgp_io_t *io,
{
struct stat st;
int fd;
fd = open(filename, MMAP_BIN_FLAGS);
fd = open(filename, MMAP_BIN_FLAGS, 0666);
if (fd < 0) {
(void) fprintf(io->errs, "%s: can't open \"%s\"\n", __FUNCTION__, filename);
return fd;
}
fstat(fd, &st);
*stream = pgp_new(sizeof(**stream));
(*stream)->io = (*stream)->cbinfo.io = io;
pgp_set_callback(*stream, callback, vp);


+ 6
- 11
src/validate.c View File

@ -768,22 +768,18 @@ pgp_filter_keys_fileread(
pgp_stream_t *stream;
validate_key_cb_t vdata;
key_filter_cb_t filter;
unsigned res = 1;
int fd;
unsigned res = 1;
int fd;
(void) memset(&vdata, 0x0, sizeof(vdata));
(void) memset(&vdata, 0x0, sizeof(validate_key_cb_t));
vdata.result = NULL;
vdata.getpassphrase = NULL;
(void) memset(&filter, 0x0, sizeof(filter));
(void) memset(&filter, 0x0, sizeof(key_filter_cb_t));
filter.destpubring = destpubring;
filter.destsecring = destsecring;
fd = pgp_setup_file_read(io,
&stream,filename,
&vdata,
pgp_validate_key_cb,
1);
fd = pgp_setup_file_read(io, &stream, filename, &vdata, pgp_validate_key_cb, 1);
if (fd < 0) {
perror(filename);
@ -946,8 +942,7 @@ pgp_validate_file(pgp_io_t *io,
signame = infile;
}
(void) memset(&validation, 0x0, sizeof(validation));
infd = pgp_setup_file_read(io, &parse, signame, &validation,
validate_data_cb, 1);
infd = pgp_setup_file_read(io, &parse, signame, &validation, validate_data_cb, 1);
if (infd < 0) {
return 0;
}


Loading…
Cancel
Save