~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to g10/free-packet.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* free-packet.c - cleanup stuff for packets
2
 
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
3
 
 *                                             Free Software Foundation, Inc.
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
 
3
 *               2005  Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
7
7
 * GnuPG is free software; you can redistribute it and/or modify
8
8
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * the Free Software Foundation; either version 3 of the License, or
10
10
 * (at your option) any later version.
11
11
 *
12
12
 * GnuPG is distributed in the hope that it will be useful,
15
15
 * GNU General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
18
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20
19
 */
21
20
 
22
21
#include <config.h>
25
24
#include <string.h>
26
25
#include <assert.h>
27
26
 
 
27
#include "gpg.h"
28
28
#include "packet.h"
29
 
#include "iobuf.h"
30
 
#include "mpi.h"
 
29
#include "../common/iobuf.h"
31
30
#include "util.h"
32
31
#include "cipher.h"
33
 
#include "memory.h"
34
 
#include "options.h"
 
32
#include "options.h" 
 
33
 
35
34
 
36
35
void
37
36
free_symkey_enc( PKT_symkey_enc *enc )
38
37
{
39
 
    xfree (enc);
 
38
    xfree(enc);
40
39
}
41
40
 
42
41
void
45
44
    int n, i;
46
45
    n = pubkey_get_nenc( enc->pubkey_algo );
47
46
    if( !n )
48
 
        mpi_release (enc->data[0]);
 
47
        mpi_release(enc->data[0]);
49
48
    for(i=0; i < n; i++ )
50
 
        mpi_release ( enc->data[i] );
51
 
    xfree (enc);
 
49
        mpi_release( enc->data[i] );
 
50
    xfree(enc);
52
51
}
53
52
 
54
53
void
58
57
 
59
58
  n = pubkey_get_nsig( sig->pubkey_algo );
60
59
  if( !n )
61
 
    mpi_release (sig->data[0]);
 
60
    mpi_release(sig->data[0]);
62
61
  for(i=0; i < n; i++ )
63
 
    mpi_release ( sig->data[i] );
64
 
  
65
 
  xfree (sig->revkey);
66
 
  xfree (sig->hashed);
67
 
  xfree (sig->unhashed);
68
 
  xfree (sig);
 
62
    mpi_release( sig->data[i] );
 
63
 
 
64
  xfree(sig->revkey);
 
65
  xfree(sig->hashed);
 
66
  xfree(sig->unhashed);
 
67
 
 
68
  if (sig->pka_info)
 
69
    {
 
70
      xfree (sig->pka_info->uri);
 
71
      xfree (sig->pka_info);
 
72
    }
 
73
 
 
74
  xfree(sig);
69
75
}
70
76
 
71
77
 
75
81
    int n, i;
76
82
    n = pubkey_get_npkey( pk->pubkey_algo );
77
83
    if( !n )
78
 
        mpi_release (pk->pkey[0]);
 
84
        mpi_release(pk->pkey[0]);
79
85
    for(i=0; i < n; i++ ) {
80
 
        mpi_release ( pk->pkey[i] );
 
86
        mpi_release( pk->pkey[i] );
81
87
        pk->pkey[i] = NULL;
82
88
    }
83
89
    if (pk->prefs) {
89
95
        pk->user_id = NULL;
90
96
    }
91
97
    if (pk->revkey) {
92
 
        xfree (pk->revkey);
 
98
        xfree(pk->revkey);
93
99
        pk->revkey=NULL;
94
100
        pk->numrevkeys=0;
95
101
    }
100
106
free_public_key( PKT_public_key *pk )
101
107
{
102
108
    release_public_key_parts( pk );
103
 
    xfree (pk);
 
109
    xfree(pk);
104
110
}
105
111
 
106
112
 
150
156
    int n, i;
151
157
 
152
158
    if( !d )
153
 
        d = xmalloc (sizeof *d);
 
159
        d = xmalloc(sizeof *d);
154
160
    memcpy( d, s, sizeof *d );
155
161
    d->user_id = scopy_user_id (s->user_id);
156
162
    d->prefs = copy_prefs (s->prefs);
164
170
    if( !s->revkey && s->numrevkeys )
165
171
        BUG();
166
172
    if( s->numrevkeys ) {
167
 
        d->revkey = xmalloc (sizeof(struct revocation_key)*s->numrevkeys);
 
173
        d->revkey = xmalloc(sizeof(struct revocation_key)*s->numrevkeys);
168
174
        memcpy(d->revkey,s->revkey,sizeof(struct revocation_key)*s->numrevkeys);
169
175
    }
170
176
    else
194
200
    sk->keyid[1]    = pk->keyid[1];
195
201
}
196
202
 
 
203
 
 
204
static pka_info_t *
 
205
cp_pka_info (const pka_info_t *s)
 
206
{
 
207
  pka_info_t *d = xmalloc (sizeof *s + strlen (s->email));
 
208
  
 
209
  d->valid = s->valid;
 
210
  d->checked = s->checked;
 
211
  d->uri = s->uri? xstrdup (s->uri):NULL;
 
212
  memcpy (d->fpr, s->fpr, sizeof s->fpr);
 
213
  strcpy (d->email, s->email);
 
214
  return d;
 
215
}
 
216
 
 
217
 
197
218
PKT_signature *
198
219
copy_signature( PKT_signature *d, PKT_signature *s )
199
220
{
200
221
    int n, i;
201
222
 
202
223
    if( !d )
203
 
        d = xmalloc (sizeof *d);
 
224
        d = xmalloc(sizeof *d);
204
225
    memcpy( d, s, sizeof *d );
205
226
    n = pubkey_get_nsig( s->pubkey_algo );
206
227
    if( !n )
209
230
        for(i=0; i < n; i++ )
210
231
            d->data[i] = mpi_copy( s->data[i] );
211
232
    }
 
233
    d->pka_info = s->pka_info? cp_pka_info (s->pka_info) : NULL;
212
234
    d->hashed = cp_subpktarea (s->hashed);
213
235
    d->unhashed = cp_subpktarea (s->unhashed);
214
236
    if(s->numrevkeys)
241
263
 
242
264
    n = pubkey_get_nskey( sk->pubkey_algo );
243
265
    if( !n )
244
 
        mpi_release (sk->skey[0]);
 
266
        mpi_release(sk->skey[0]);
245
267
    for(i=0; i < n; i++ ) {
246
 
        mpi_release ( sk->skey[i] );
 
268
        mpi_release( sk->skey[i] );
247
269
        sk->skey[i] = NULL;
248
270
    }
249
271
}
252
274
free_secret_key( PKT_secret_key *sk )
253
275
{
254
276
    release_secret_key_parts( sk );
255
 
    xfree (sk);
 
277
    xfree(sk);
256
278
}
257
279
 
258
280
PKT_secret_key *
261
283
    int n, i;
262
284
 
263
285
    if( !d )
264
 
        d = xmalloc (sizeof *d);
 
286
        d = xmalloc_secure(sizeof *d);
 
287
    else
 
288
        release_secret_key_parts (d);
265
289
    memcpy( d, s, sizeof *d );
266
290
    n = pubkey_get_nskey( s->pubkey_algo );
267
291
    if( !n )
268
 
        d->skey[0] = mpi_copy(s->skey[0]);
 
292
        d->skey[0] = mpi_copy(s->skey[0]);
269
293
    else {
270
294
        for(i=0; i < n; i++ )
271
 
            d->skey[i] = mpi_copy( s->skey[i] );
 
295
            d->skey[i] = mpi_copy( s->skey[i] );
272
296
    }
 
297
 
273
298
    return d;
274
299
}
275
300
 
276
301
void
277
302
free_comment( PKT_comment *rem )
278
303
{
279
 
    xfree (rem);
 
304
    xfree(rem);
280
305
}
281
306
 
282
307
void
283
308
free_attributes(PKT_user_id *uid)
284
309
{
285
 
  xfree (uid->attribs);
286
 
  xfree (uid->attrib_data);
 
310
  xfree(uid->attribs);
 
311
  xfree(uid->attrib_data);
287
312
 
288
313
  uid->attribs=NULL;
289
314
  uid->attrib_data=NULL;
312
337
        while( iobuf_read( zd->buf, NULL, 1<<30 ) != -1 )
313
338
            ;
314
339
    }
315
 
    xfree (zd);
 
340
    xfree(zd);
316
341
}
317
342
 
318
343
void
319
344
free_encrypted( PKT_encrypted *ed )
320
345
{
321
346
    if( ed->buf ) { /* have to skip some bytes */
322
 
        if( iobuf_in_block_mode(ed->buf) ) {
 
347
        if( ed->is_partial ) {
323
348
            while( iobuf_read( ed->buf, NULL, 1<<30 ) != -1 )
324
349
                ;
325
350
        }
333
358
           }
334
359
        }
335
360
    }
336
 
    xfree (ed);
 
361
    xfree(ed);
337
362
}
338
363
 
339
364
 
341
366
free_plaintext( PKT_plaintext *pt )
342
367
{
343
368
    if( pt->buf ) { /* have to skip some bytes */
344
 
        if( iobuf_in_block_mode(pt->buf) ) {
 
369
        if( pt->is_partial ) {
345
370
            while( iobuf_read( pt->buf, NULL, 1<<30 ) != -1 )
346
371
                ;
347
372
        }
355
380
           }
356
381
        }
357
382
    }
358
 
    xfree (pt);
 
383
    xfree(pt);
359
384
}
360
385
 
361
386
/****************
405
430
        free_plaintext( pkt->pkt.plaintext );
406
431
        break;
407
432
      default:
408
 
        xfree ( pkt->pkt.generic );
 
433
        xfree( pkt->pkt.generic );
409
434
        break;
410
435
    }
411
436
    pkt->pkt.generic = NULL;