Coverage Report

Created: 2026-10-08 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gnupg/g10/free-packet.c
Line
Count
Source
1
/* free-packet.c - cleanup stuff for packets
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
3
 *               2005, 2010  Free Software Foundation, Inc.
4
 *
5
 * This file is part of GnuPG.
6
 *
7
 * GnuPG is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * GnuPG is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
#include <config.h>
22
#include <stdio.h>
23
#include <stdlib.h>
24
#include <string.h>
25
26
#include "gpg.h"
27
#include "../common/util.h"
28
#include "packet.h"
29
#include "../common/iobuf.h"
30
#include "options.h"
31
32
33
/* This is a wrapper for mpi_copy which handles opaque MPIs with a
34
 * NULL pointer as opaque data; e.g. gcry_mpi_set_opaque(a, NULL, 0).
35
 * It seems that at least gcry_mpi_set_opaque_copy does not yet handle
36
 * this correctly.  */
37
static gcry_mpi_t
38
my_mpi_copy (gcry_mpi_t a)
39
68.5k
{
40
68.5k
  if (a
41
25.8k
      && gcry_mpi_get_flag (a, GCRYMPI_FLAG_OPAQUE)
42
13.4k
      && !gcry_mpi_get_opaque (a, NULL))
43
113
    return NULL;
44
45
68.4k
  return gcry_mpi_copy (a);
46
68.5k
}
47
48
49
void
50
free_symkey_enc( PKT_symkey_enc *enc )
51
40.0k
{
52
40.0k
  if (enc)
53
40.0k
    xfree (enc->seskey);
54
40.0k
  xfree(enc);
55
40.0k
}
56
57
58
/* This is the core of free_pubkey_enc but does only release the
59
 * allocated members of ENC.  */
60
void
61
release_pubkey_enc_parts (PKT_pubkey_enc *enc)
62
116k
{
63
116k
  int n, i;
64
116k
  n = pubkey_get_nenc( enc->pubkey_algo );
65
116k
  if (!n)
66
116k
    mpi_release (enc->data[0]);
67
144k
  for (i=0; i < n; i++ )
68
116k
    mpi_release (enc->data[i]);
69
116k
}
70
71
void
72
free_pubkey_enc (PKT_pubkey_enc *enc)
73
71.3k
{
74
71.3k
  release_pubkey_enc_parts (enc);
75
71.3k
  xfree (enc);
76
71.3k
}
77
78
79
/* Copy everything from SRC to DST.  This assumes that DST has been
80
 * malloced or statically allocated. */
81
void
82
copy_pubkey_enc_parts (PKT_pubkey_enc *dst, PKT_pubkey_enc *src)
83
44.8k
{
84
44.8k
  int n, i;
85
86
44.8k
  dst->keyid[0] = src->keyid[0];
87
44.8k
  dst->keyid[1] = src->keyid[1];
88
44.8k
  dst->version  = src->version;
89
44.8k
  dst->pubkey_algo = src->pubkey_algo;
90
44.8k
  dst->seskey_algo = src->seskey_algo;
91
44.8k
  dst->throw_keyid = src->throw_keyid;
92
44.8k
  dst->fprlen      = src->fprlen;
93
44.8k
  memcpy (dst->fpr, src->fpr, sizeof src->fpr);
94
95
44.8k
  if (!(n = pubkey_get_nenc (dst->pubkey_algo)))
96
42.7k
    n = 1;  /* All data is in the first item as an opaque MPI. */
97
91.0k
  for (i=0; i < n; i++)
98
46.2k
    dst->data[i] = my_mpi_copy (src->data[i]);
99
177k
  for (; i < PUBKEY_MAX_NENC; i++)
100
133k
    dst->data[i] = NULL;
101
44.8k
}
102
103
104
static void
105
free_onepass_sig (PKT_onepass_sig *ops)
106
60.0k
{
107
60.0k
  if (ops)
108
60.0k
    {
109
60.0k
      mpi_release (ops->salt);
110
60.0k
      xfree (ops);
111
60.0k
    }
112
60.0k
}
113
114
115
void
116
free_seckey_enc( PKT_signature *sig )
117
28.4M
{
118
28.4M
  int n, i;
119
120
28.4M
  n = pubkey_get_nsig( sig->pubkey_algo );
121
28.4M
  if( !n )
122
28.4M
    mpi_release(sig->data[0]);
123
82.9M
  for(i=0; i < n; i++ )
124
54.4M
    mpi_release( sig->data[i] );
125
126
28.4M
  xfree(sig->revkey);
127
28.4M
  xfree(sig->hashed);
128
28.4M
  xfree(sig->unhashed);
129
28.4M
  mpi_release (sig->salt);
130
131
  /* Do not forget to update copy_signature() too. */
132
28.4M
  xfree(sig->rev_subject_info);
133
28.4M
  xfree (sig->signers_uid);
134
135
28.4M
  xfree(sig);
136
28.4M
}
137
138
139
void
140
release_public_key_parts (PKT_public_key *pk)
141
2.60M
{
142
2.60M
  int n, i;
143
144
2.60M
  if (pk->seckey_info)
145
75.6k
    n = pubkey_get_nskey (pk->pubkey_algo);
146
2.52M
  else
147
2.52M
    n = pubkey_get_npkey (pk->pubkey_algo);
148
2.60M
  if (!n)
149
2.60M
    mpi_release (pk->pkey[0]);
150
8.77M
  for (i=0; i < n; i++ )
151
6.17M
    {
152
6.17M
      mpi_release (pk->pkey[i]);
153
6.17M
      pk->pkey[i] = NULL;
154
6.17M
    }
155
2.60M
  if (pk->seckey_info)
156
75.6k
    {
157
75.6k
      xfree (pk->seckey_info);
158
75.6k
      pk->seckey_info = NULL;
159
75.6k
    }
160
2.60M
  if (pk->prefs)
161
4.28k
    {
162
4.28k
      xfree (pk->prefs);
163
4.28k
      pk->prefs = NULL;
164
4.28k
    }
165
2.60M
  if (pk->dks_prefs)
166
0
    {
167
0
      xfree (pk->dks_prefs);
168
0
      pk->dks_prefs = NULL;
169
0
    }
170
2.60M
  free_user_id (pk->user_id);
171
2.60M
  pk->user_id = NULL;
172
2.60M
  if (pk->revkey)
173
155
    {
174
155
      xfree(pk->revkey);
175
155
      pk->revkey=NULL;
176
155
      pk->numrevkeys=0;
177
155
    }
178
2.60M
  if (pk->serialno)
179
0
    {
180
0
      xfree (pk->serialno);
181
0
      pk->serialno = NULL;
182
0
    }
183
2.60M
  if (pk->updateurl)
184
9.45k
    {
185
9.45k
      xfree (pk->updateurl);
186
9.45k
      pk->updateurl = NULL;
187
9.45k
    }
188
2.60M
  if (pk->revoked.reason_comment)
189
0
    {
190
0
      xfree (pk->revoked.reason_comment);
191
0
      pk->revoked.reason_comment = NULL;
192
0
    }
193
2.60M
}
194
195
196
/* Free an allocated public key structure including all parts.
197
   Passing NULL is allowed.  */
198
void
199
free_public_key (PKT_public_key *pk)
200
2.73M
{
201
2.73M
  if (pk)
202
2.60M
    {
203
2.60M
      release_public_key_parts (pk);
204
2.60M
      xfree(pk);
205
2.60M
    }
206
2.73M
}
207
208
209
static subpktarea_t *
210
cp_subpktarea (subpktarea_t *s )
211
6.04k
{
212
6.04k
    subpktarea_t *d;
213
214
6.04k
    if( !s )
215
5.60k
  return NULL;
216
442
    d = xmalloc (sizeof (*d) + s->size - 1 );
217
442
    d->size = s->size;
218
442
    d->len = s->len;
219
442
    memcpy (d->data, s->data, s->len);
220
442
    return d;
221
6.04k
}
222
223
/*
224
 * Return a copy of the preferences
225
 */
226
prefitem_t *
227
copy_prefs (const prefitem_t *prefs)
228
653k
{
229
653k
    size_t n;
230
653k
    prefitem_t *new;
231
232
653k
    if (!prefs)
233
648k
        return NULL;
234
235
50.0k
    for (n=0; prefs[n].type; n++)
236
45.7k
        ;
237
4.28k
    new = xmalloc ( sizeof (*new) * (n+1));
238
50.0k
    for (n=0; prefs[n].type; n++) {
239
45.7k
        new[n].type = prefs[n].type;
240
45.7k
        new[n].value = prefs[n].value;
241
45.7k
    }
242
4.28k
    new[n].type = PREFTYPE_NONE;
243
4.28k
    new[n].value = 0;
244
245
4.28k
    return new;
246
653k
}
247
248
249
/* Copy the public key S to D.  If D is NULL allocate a new public key
250
 * structure.  Only the basic stuff is copied; not any ancillary
251
 * data.  */
252
PKT_public_key *
253
copy_public_key_basics (PKT_public_key *d, PKT_public_key *s)
254
8.15k
{
255
8.15k
  int n, i;
256
257
8.15k
  if (!d)
258
2.15k
    d = xmalloc (sizeof *d);
259
8.15k
  memcpy (d, s, sizeof *d);
260
8.15k
  d->seckey_info = NULL;
261
8.15k
  d->user_id = NULL;
262
8.15k
  d->prefs = NULL;
263
8.15k
  d->dks_prefs = NULL;
264
8.15k
  d->revoked.got_reason = 0;
265
8.15k
  d->revoked.reason_code = 0;
266
8.15k
  d->revoked.reason_comment = NULL;
267
8.15k
  d->revoked.reason_comment_len = 0;
268
269
8.15k
  n = pubkey_get_npkey (s->pubkey_algo);
270
8.15k
  i = 0;
271
8.15k
  if (!n)
272
518
    d->pkey[i++] = my_mpi_copy (s->pkey[0]);
273
7.63k
  else
274
7.63k
    {
275
24.1k
      for (; i < n; i++ )
276
16.4k
        d->pkey[i] = my_mpi_copy (s->pkey[i]);
277
7.63k
    }
278
48.2k
  for (; i < PUBKEY_MAX_NSKEY; i++)
279
40.0k
    d->pkey[i] = NULL;
280
281
8.15k
  d->revkey = NULL;
282
8.15k
  d->serialno = NULL;
283
8.15k
  d->updateurl = NULL;
284
285
8.15k
  return d;
286
8.15k
}
287
288
289
/* Copy the public key S to D.  If D is NULL allocate a new public key
290
   structure.  If S has seckret key infos, only the public stuff is
291
   copied.  */
292
PKT_public_key *
293
copy_public_key (PKT_public_key *d, PKT_public_key *s)
294
8.15k
{
295
8.15k
  d = copy_public_key_basics (d, s);
296
8.15k
  d->user_id = scopy_user_id (s->user_id);
297
8.15k
  d->prefs = copy_prefs (s->prefs);
298
8.15k
  d->dks_prefs = copy_prefs (s->dks_prefs);
299
300
8.15k
  if (!s->revkey && s->numrevkeys)
301
0
    BUG();
302
8.15k
  if (s->numrevkeys)
303
4
    {
304
4
      d->revkey = xmalloc(sizeof(struct revocation_key)*s->numrevkeys);
305
4
      memcpy(d->revkey,s->revkey,sizeof(struct revocation_key)*s->numrevkeys);
306
4
    }
307
308
8.15k
  if (s->serialno)
309
0
    d->serialno = xstrdup (s->serialno);
310
8.15k
  if (s->updateurl)
311
0
    d->updateurl = xstrdup (s->updateurl);
312
8.15k
  if (s->revoked.got_reason)
313
187
    {
314
187
      d->revoked.got_reason = s->revoked.got_reason;
315
187
      d->revoked.reason_code = s->revoked.reason_code;
316
187
      if (s->revoked.reason_comment_len)
317
0
        {
318
0
          d->revoked.reason_comment = xmalloc (s->revoked.reason_comment_len);
319
0
          memcpy (d->revoked.reason_comment, s->revoked.reason_comment,
320
0
                  s->revoked.reason_comment_len);
321
0
          d->revoked.reason_comment_len = s->revoked.reason_comment_len;
322
0
        }
323
187
    }
324
325
8.15k
  return d;
326
8.15k
}
327
328
329
330
/* When modifying the signature struct adjust copy_signature()
331
 * such that the changes are considered too (e.g. pointers are set to NULL
332
 * if they are not copied. */
333
PKT_signature *
334
copy_signature( PKT_signature *d, PKT_signature *s )
335
3.02k
{
336
3.02k
    int n, i;
337
338
3.02k
    if( !d )
339
3.02k
  d = xmalloc(sizeof *d);
340
3.02k
    memcpy( d, s, sizeof *d );
341
3.02k
    n = pubkey_get_nsig( s->pubkey_algo );
342
3.02k
    if( !n )
343
603
  d->data[0] = my_mpi_copy(s->data[0]);
344
2.42k
    else {
345
7.16k
  for(i=0; i < n; i++ )
346
4.74k
      d->data[i] = my_mpi_copy( s->data[i] );
347
2.42k
    }
348
3.02k
    d->hashed = cp_subpktarea (s->hashed);
349
3.02k
    d->unhashed = cp_subpktarea (s->unhashed);
350
3.02k
    d->salt = s->salt? my_mpi_copy (s->salt) : NULL;
351
3.02k
    if (s->signers_uid)
352
0
      d->signers_uid = xstrdup (s->signers_uid);
353
3.02k
    else
354
3.02k
      d->signers_uid = NULL;
355
356
3.02k
    if(s->numrevkeys)
357
0
      {
358
0
  d->revkey=NULL;
359
0
  d->numrevkeys=0;
360
0
  parse_revkeys(d);
361
0
      }
362
363
3.02k
    if (s->rev_subject_info)
364
0
      {
365
0
        d->rev_subject_info = xmalloc (sizeof *d->rev_subject_info);
366
0
        memcpy (d->rev_subject_info, s->rev_subject_info, sizeof *d->rev_subject_info);
367
0
      }
368
3.02k
    else
369
3.02k
      d->rev_subject_info = NULL;
370
371
3.02k
    return d;
372
3.02k
}
373
374
375
/*
376
 * shallow copy of the user ID
377
 */
378
PKT_user_id *
379
scopy_user_id (PKT_user_id *s)
380
14.2k
{
381
14.2k
    if (s)
382
0
        s->ref++;
383
14.2k
    return s;
384
14.2k
}
385
386
387
388
void
389
free_comment( PKT_comment *rem )
390
2.45k
{
391
2.45k
    xfree(rem);
392
2.45k
}
393
394
void
395
free_attributes(PKT_user_id *uid)
396
216k
{
397
216k
  if (!uid)
398
0
    return;
399
400
216k
  xfree(uid->attribs);
401
216k
  xfree(uid->attrib_data);
402
403
216k
  uid->attribs=NULL;
404
216k
  uid->attrib_data=NULL;
405
216k
  uid->attrib_len=0;
406
216k
}
407
408
void
409
free_user_id (PKT_user_id *uid)
410
2.82M
{
411
2.82M
  if (!uid)
412
2.60M
    return;
413
414
2.82M
  log_assert (uid->ref > 0);
415
216k
  if (--uid->ref)
416
0
    return;
417
418
216k
  free_attributes(uid);
419
216k
  xfree (uid->prefs);
420
216k
  xfree (uid->namehash);
421
216k
  xfree (uid->updateurl);
422
216k
  xfree (uid->mbox);
423
216k
  xfree (uid);
424
216k
}
425
426
void
427
free_compressed( PKT_compressed *zd )
428
703k
{
429
703k
  if (!zd)
430
0
    return;
431
432
703k
  if (zd->buf)
433
1.44k
    {
434
      /* We need to skip some bytes.  Because don't have any
435
       * information about the length, so we assume this is the last
436
       * packet */
437
3.59k
      while (iobuf_read( zd->buf, NULL, 1<<30 ) != -1)
438
2.14k
        ;
439
1.44k
    }
440
703k
  xfree(zd);
441
703k
}
442
443
void
444
free_encrypted( PKT_encrypted *ed )
445
273k
{
446
273k
  if (!ed)
447
0
    return;
448
449
273k
  if (ed->buf)
450
252k
    {
451
      /* We need to skip some bytes. */
452
252k
      if (ed->is_partial)
453
5.30k
        {
454
6.36k
          while (iobuf_read( ed->buf, NULL, 1<<30 ) != -1)
455
1.05k
            ;
456
5.30k
  }
457
246k
      else
458
246k
        {
459
251k
          while (ed->len)
460
4.50k
            {
461
              /* Skip the packet. */
462
4.50k
              int n = iobuf_read( ed->buf, NULL, ed->len );
463
4.50k
              if (n == -1)
464
1.38k
                ed->len = 0;
465
3.11k
              else
466
3.11k
                ed->len -= n;
467
4.50k
            }
468
246k
  }
469
252k
    }
470
273k
  xfree (ed);
471
273k
}
472
473
474
void
475
free_plaintext( PKT_plaintext *pt )
476
151k
{
477
151k
  if (!pt)
478
0
    return;
479
480
151k
  if (pt->buf)
481
148k
    { /* We need to skip some bytes.  */
482
148k
      if (pt->is_partial)
483
13.5k
        {
484
26.2k
          while (iobuf_read( pt->buf, NULL, 1<<30 ) != -1)
485
12.7k
            ;
486
13.5k
        }
487
134k
      else
488
134k
        {
489
192k
          while( pt->len )
490
57.3k
            { /* Skip the packet.  */
491
57.3k
              int n = iobuf_read( pt->buf, NULL, pt->len );
492
57.3k
              if (n == -1)
493
14.4k
                pt->len = 0;
494
42.8k
              else
495
42.8k
                pt->len -= n;
496
57.3k
            }
497
134k
  }
498
148k
    }
499
151k
  xfree (pt);
500
151k
}
501
502
503
/****************
504
 * Free the packet in PKT.
505
 */
506
void
507
free_packet (PACKET *pkt, parse_packet_ctx_t parsectx)
508
93.5M
{
509
93.5M
  if (!pkt || !pkt->pkt.generic)
510
61.3M
    {
511
61.3M
      if (parsectx && parsectx->last_pkt.pkt.generic)
512
28.7M
        {
513
28.7M
          if (parsectx->free_last_pkt)
514
43.0k
            {
515
43.0k
              free_packet (&parsectx->last_pkt, NULL);
516
43.0k
              parsectx->free_last_pkt = 0;
517
43.0k
            }
518
28.7M
          parsectx->last_pkt.pkttype = 0;
519
28.7M
          parsectx->last_pkt.pkt.generic = NULL;
520
28.7M
        }
521
61.3M
      return;
522
61.3M
    }
523
524
32.1M
  if (DBG_MEMORY)
525
32.1M
    log_debug ("free_packet() type=%d\n", pkt->pkttype);
526
527
  /* If we have a parser context holding PKT then do not free the
528
   * packet but set a flag that the packet in the parser context is
529
   * now a deep copy.  */
530
32.1M
  if (parsectx && !parsectx->free_last_pkt
531
362k
      && parsectx->last_pkt.pkttype == pkt->pkttype
532
43.0k
      && parsectx->last_pkt.pkt.generic == pkt->pkt.generic)
533
43.0k
    {
534
43.0k
      parsectx->last_pkt = *pkt;
535
43.0k
      parsectx->free_last_pkt = 1;
536
43.0k
      pkt->pkt.generic = NULL;
537
43.0k
      return;
538
43.0k
    }
539
540
32.1M
  switch (pkt->pkttype)
541
32.1M
    {
542
28.4M
    case PKT_SIGNATURE:
543
28.4M
      free_seckey_enc (pkt->pkt.signature);
544
28.4M
      break;
545
60.0k
    case PKT_ONEPASS_SIG:
546
60.0k
      free_onepass_sig (pkt->pkt.onepass_sig);
547
60.0k
      break;
548
71.3k
    case PKT_PUBKEY_ENC:
549
71.3k
      free_pubkey_enc (pkt->pkt.pubkey_enc);
550
71.3k
      break;
551
40.0k
    case PKT_SYMKEY_ENC:
552
40.0k
      free_symkey_enc (pkt->pkt.symkey_enc);
553
40.0k
      break;
554
106k
    case PKT_PUBLIC_KEY:
555
1.75M
    case PKT_PUBLIC_SUBKEY:
556
1.80M
    case PKT_SECRET_KEY:
557
1.89M
    case PKT_SECRET_SUBKEY:
558
1.89M
      free_public_key (pkt->pkt.public_key);
559
1.89M
      break;
560
2.45k
    case PKT_COMMENT:
561
2.45k
      free_comment (pkt->pkt.comment);
562
2.45k
      break;
563
216k
    case PKT_USER_ID:
564
216k
      free_user_id (pkt->pkt.user_id);
565
216k
      break;
566
703k
    case PKT_COMPRESSED:
567
703k
      free_compressed (pkt->pkt.compressed);
568
703k
      break;
569
53.2k
    case PKT_ENCRYPTED:
570
62.7k
    case PKT_ENCRYPTED_MDC:
571
273k
    case PKT_ENCRYPTED_OCB:
572
273k
      free_encrypted (pkt->pkt.encrypted);
573
273k
      break;
574
151k
    case PKT_PLAINTEXT:
575
151k
      free_plaintext (pkt->pkt.plaintext);
576
151k
      break;
577
188k
    default:
578
188k
      xfree (pkt->pkt.generic);
579
188k
      break;
580
32.1M
    }
581
582
32.1M
  pkt->pkt.generic = NULL;
583
32.1M
}
584
585
586
/* Free an entire list of public or symmetric key encrypted data.  */
587
void
588
free_seskey_enc_list (struct seskey_enc_list *sesenc_list)
589
815k
{
590
860k
  while (sesenc_list)
591
44.8k
    {
592
44.8k
      struct seskey_enc_list *tmp = sesenc_list->next;
593
594
44.8k
      if (!sesenc_list->u_sym)
595
44.8k
        release_pubkey_enc_parts (&sesenc_list->u.pub);
596
44.8k
      xfree (sesenc_list);
597
44.8k
      sesenc_list = tmp;
598
44.8k
    }
599
815k
}
600
601
602
/****************
603
 * returns 0 if they match.
604
 */
605
int
606
cmp_public_keys( PKT_public_key *a, PKT_public_key *b )
607
101k
{
608
101k
    int n, i;
609
610
101k
    if( a->timestamp != b->timestamp )
611
38
  return -1;
612
101k
    if( a->version < 4 && a->expiredate != b->expiredate )
613
0
  return -1;
614
101k
    if( a->pubkey_algo != b->pubkey_algo )
615
0
  return -1;
616
617
101k
    n = pubkey_get_npkey( b->pubkey_algo );
618
101k
    if( !n ) { /* unknown algorithm, rest is in opaque MPI */
619
0
  if( mpi_cmp( a->pkey[0], b->pkey[0] ) )
620
0
      return -1; /* can't compare due to unknown algorithm */
621
101k
    } else {
622
232k
  for(i=0; i < n; i++ ) {
623
216k
      if( mpi_cmp( a->pkey[i], b->pkey[i] ) )
624
85.5k
    return -1;
625
216k
  }
626
101k
    }
627
628
16.0k
    return 0;
629
101k
}
630
631
632
633
int
634
cmp_signatures( PKT_signature *a, PKT_signature *b )
635
3.23M
{
636
3.23M
    int n, i;
637
638
3.23M
    if( a->keyid[0] != b->keyid[0] )
639
99.3k
  return -1;
640
3.13M
    if( a->keyid[1] != b->keyid[1] )
641
44.7k
  return -1;
642
3.09M
    if( a->pubkey_algo != b->pubkey_algo )
643
85.6k
  return -1;
644
645
3.00M
    n = pubkey_get_nsig( a->pubkey_algo );
646
3.00M
    if( !n )
647
189
  return -1; /* can't compare due to unknown algorithm */
648
5.52M
    for(i=0; i < n; i++ ) {
649
5.52M
  if( mpi_cmp( a->data[i] , b->data[i] ) )
650
3.00M
      return -1;
651
5.52M
    }
652
679
    return 0;
653
3.00M
}
654
655
656
/****************
657
 * Returns: true if the user ids do not match
658
 */
659
int
660
cmp_user_ids( PKT_user_id *a, PKT_user_id *b )
661
102k
{
662
102k
    int res=1;
663
664
102k
    if( a == b )
665
0
        return 0;
666
667
102k
    if( a->attrib_data && b->attrib_data )
668
0
      {
669
0
  res = a->attrib_len - b->attrib_len;
670
0
  if( !res )
671
0
    res = memcmp( a->attrib_data, b->attrib_data, a->attrib_len );
672
0
      }
673
102k
    else if( !a->attrib_data && !b->attrib_data )
674
102k
      {
675
102k
  res = a->len - b->len;
676
102k
  if( !res )
677
39.5k
    res = memcmp( a->name, b->name, a->len );
678
102k
      }
679
680
102k
    return res;
681
102k
}