~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to g10/kbxio.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2006-01-24 04:31:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060124043142-pbg192or6qxv3yk2
Tags: 1.9.20-1
* New Upstream version. Closes:#306890,#344530
  * Closes:#320490: gpg-protect-tool fails to decrypt PKCS-12 files 
* Depend on libopensc2-dev, not -1-. Closes:#348106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* kbxio.c - KBX I/O handling
 
2
 *      Copyright (C) 2000 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GnuPG.
 
5
 *
 
6
 * GnuPG is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * GnuPG is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
19
 */
 
20
 
 
21
 
 
22
#include <config.h>
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
#include <errno.h>
 
27
#include <assert.h>
 
28
#include <gcrypt.h>
 
29
 
 
30
#include "iobuf.h"
 
31
#include "util.h"
 
32
#include "kbx.h"
 
33
 
 
34
 
 
35
int
 
36
kbx_read_blob ( KBXBLOB *r_blob, FILE *a )
 
37
{
 
38
    char *image;
 
39
    size_t imagelen = 0;
 
40
    int c1, c2, c3, c4;
 
41
    int rc;
 
42
 
 
43
    *r_blob = NULL;
 
44
    if (    (c1 = getc ( a )) == EOF
 
45
         || (c2 = getc ( a )) == EOF
 
46
         || (c3 = getc ( a )) == EOF
 
47
         || (c4 = getc ( a )) == EOF ) {
 
48
        if ( c1 == EOF && !ferror ( a ) )
 
49
            return -1;
 
50
        return GPGERR_GENERAL;
 
51
    }
 
52
    imagelen = (c1 << 24) | (c2 << 16) | (c3 << 8 ) | c4;
 
53
    if ( imagelen > 500000 ) { /* sanity check:blob too large */
 
54
        return GPGERR_GENERAL;
 
55
    }
 
56
    else if ( imagelen < 4 ) { /* blobtoo short */
 
57
        return GPGERR_GENERAL;
 
58
    }
 
59
    image = gcry_malloc ( imagelen );
 
60
    if ( !image ) {
 
61
        return GPGERR_GENERAL;
 
62
    }
 
63
 
 
64
    image[0] = c1; image[1] = c2; image[2] = c3; image[3] = c4;
 
65
    if ( fread ( image+4, imagelen-4, 1, a ) != 1 )  {
 
66
        gcry_free ( image );
 
67
        return GPGERR_GENERAL;
 
68
    }
 
69
 
 
70
    rc = kbx_new_blob ( r_blob, image, imagelen );
 
71
    return rc;
 
72
}
 
73
 
 
74
 
 
75