X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=pgppacket.c;h=9d484706ac628ff5f26a33cc120f63ec953edb3f;hp=f6c64a5396000b657406f697cbdbcfb0d83ec005;hb=ef7b80006ebb47372d69c64e8b2b2f0764333d55;hpb=6833ce8bdca2d64e14485118f2a4417b7e1cb1b1 diff --git a/pgppacket.c b/pgppacket.c index f6c64a5..9d48470 100644 --- a/pgppacket.c +++ b/pgppacket.c @@ -1,23 +1,16 @@ /* + * Copyright notice from original mutt: * Copyright (C) 2001 Thomas Roessler - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111, USA. + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ -#include "config.h" +#if HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -29,6 +22,8 @@ #include "pgplib.h" #include "pgppacket.h" +#include "lib/mem.h" + #define CHUNKSIZE 1024 static unsigned char *pbuf = NULL; @@ -36,15 +31,13 @@ static size_t plen = 0; static int read_material (size_t material, size_t * used, FILE * fp) { - if (*used + material >= plen) - { + if (*used + material >= plen) { unsigned char *p; size_t nplen; nplen = *used + material + CHUNKSIZE; - if (!(p = realloc (pbuf, nplen))) /* __MEM_CHECKED__ */ - { + if (!(p = realloc (pbuf, nplen))) { /* __MEM_CHECKED__ */ perror ("realloc"); return -1; } @@ -52,8 +45,7 @@ static int read_material (size_t material, size_t * used, FILE * fp) pbuf = p; } - if (fread (pbuf + *used, 1, material, fp) < material) - { + if (fread (pbuf + *used, 1, material, fp) < material) { perror ("fread"); return -1; } @@ -65,89 +57,80 @@ static int read_material (size_t material, size_t * used, FILE * fp) unsigned char *pgp_read_packet (FILE * fp, size_t * len) { size_t used = 0; - long startpos; + off_t startpos; unsigned char ctb; unsigned char b; size_t material; - startpos = ftell (fp); + startpos = ftello (fp); - if (!plen) - { + if (!plen) { plen = CHUNKSIZE; - pbuf = safe_malloc (plen); + pbuf = mem_malloc (plen); } - if (fread (&ctb, 1, 1, fp) < 1) - { + if (fread (&ctb, 1, 1, fp) < 1) { if (!feof (fp)) perror ("fread"); goto bail; } - if (!(ctb & 0x80)) - { + if (!(ctb & 0x80)) { goto bail; } - if (ctb & 0x40) /* handle PGP 5.0 packets. */ - { + if (ctb & 0x40) { /* handle PGP 5.0 packets. */ int partial = 0; + pbuf[0] = ctb; used++; - do - { - if (fread (&b, 1, 1, fp) < 1) - { - perror ("fread"); - goto bail; + do { + if (fread (&b, 1, 1, fp) < 1) { + perror ("fread"); + goto bail; } - if (b < 192) - { - material = b; - partial = 0; - /* material -= 1; */ + if (b < 192) { + material = b; + partial = 0; + /* material -= 1; */ } - else if (192 <= b && b <= 223) - { - material = (b - 192) * 256; - if (fread (&b, 1, 1, fp) < 1) - { - perror ("fread"); - goto bail; - } - material += b + 192; - partial = 0; - /* material -= 2; */ + else if (192 <= b && b <= 223) { + material = (b - 192) * 256; + if (fread (&b, 1, 1, fp) < 1) { + perror ("fread"); + goto bail; + } + material += b + 192; + partial = 0; + /* material -= 2; */ } - else if (b < 255) - { - material = 1 << (b & 0x1f); - partial = 1; - /* material -= 1; */ + else if (b < 255) { + material = 1 << (b & 0x1f); + partial = 1; + /* material -= 1; */ } else - /* b == 255 */ + /* b == 255 */ { - unsigned char buf[4]; - if (fread (buf, 4, 1, fp) < 1) - { - perror ("fread"); - goto bail; - } - /*assert( sizeof(material) >= 4 ); */ - material = buf[0] << 24; - material |= buf[1] << 16; - material |= buf[2] << 8; - material |= buf[3]; - partial = 0; - /* material -= 5; */ + unsigned char buf[4]; + + if (fread (buf, 4, 1, fp) < 1) { + perror ("fread"); + goto bail; + } + /*assert( sizeof(material) >= 4 ); */ + material = buf[0] << 24; + material |= buf[1] << 16; + material |= buf[2] << 8; + material |= buf[3]; + partial = 0; + /* material -= 5; */ } if (read_material (material, &used, fp) == -1) - goto bail; + goto bail; } while (partial); @@ -156,49 +139,46 @@ unsigned char *pgp_read_packet (FILE * fp, size_t * len) /* Old-Style PGP */ { int bytes = 0; + pbuf[0] = 0x80 | ((ctb >> 2) & 0x0f); used++; - switch (ctb & 0x03) - { - case 0: + switch (ctb & 0x03) { + case 0: { - if (fread (&b, 1, 1, fp) < 1) - { - perror ("fread"); - goto bail; - } - - material = b; - break; + if (fread (&b, 1, 1, fp) < 1) { + perror ("fread"); + goto bail; + } + + material = b; + break; } - case 1: + case 1: bytes = 2; - case 2: + case 2: { - int i; + int i; - if (!bytes) - bytes = 4; + if (!bytes) + bytes = 4; - material = 0; + material = 0; - for (i = 0; i < bytes; i++) - { - if (fread (&b, 1, 1, fp) < 1) - { - perror ("fread"); - goto bail; - } + for (i = 0; i < bytes; i++) { + if (fread (&b, 1, 1, fp) < 1) { + perror ("fread"); + goto bail; + } - material = (material << 8) + b; - } - break; + material = (material << 8) + b; + } + break; } - default: + default: goto bail; } @@ -213,13 +193,12 @@ unsigned char *pgp_read_packet (FILE * fp, size_t * len) bail: - fseek (fp, startpos, SEEK_SET); + fseeko (fp, startpos, SEEK_SET); return NULL; } void pgp_release_packet (void) { plen = 0; - FREE (&pbuf); + mem_free (&pbuf); } -