~ubuntu-branches/ubuntu/trusty/xulrunner/trusty

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/base/item.c

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-25 13:04:18 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825130418-ck1i2ms384tzb9m0
Tags: 1.8.1.16+nobinonly-0ubuntu1
* New upstream release (taken from upstream CVS), LP: #254618.
* Fix MFSA 2008-35, MFSA 2008-34, MFSA 2008-33, MFSA 2008-32, MFSA 2008-31,
  MFSA 2008-30, MFSA 2008-29, MFSA 2008-28, MFSA 2008-27, MFSA 2008-25,
  MFSA 2008-24, MFSA 2008-23, MFSA 2008-22, MFSA 2008-21, MFSA 2008-26 also
  known as CVE-2008-2933, CVE-2008-2785, CVE-2008-2811, CVE-2008-2810,
  CVE-2008-2809, CVE-2008-2808, CVE-2008-2807, CVE-2008-2806, CVE-2008-2805,
  CVE-2008-2803, CVE-2008-2802, CVE-2008-2801, CVE-2008-2800, CVE-2008-2798.
* Drop 89_bz419350_attachment_306066 patch, merged upstream.
* Bump Standards-Version to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public License Version
 
5
 * 1.1 (the "License"); you may not use this file except in compliance with
 
6
 * the License. You may obtain a copy of the License at
 
7
 * http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS IS" basis,
 
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
 * for the specific language governing rights and limitations under the
 
12
 * License.
 
13
 *
 
14
 * The Original Code is the Netscape security libraries.
 
15
 *
 
16
 * The Initial Developer of the Original Code is
 
17
 * Netscape Communications Corporation.
 
18
 * Portions created by the Initial Developer are Copyright (C) 1994-2000
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *
 
23
 * Alternatively, the contents of this file may be used under the terms of
 
24
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
25
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
26
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
27
 * of those above. If you wish to allow use of your version of this file only
 
28
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
29
 * use your version of this file under the terms of the MPL, indicate your
 
30
 * decision by deleting the provisions above and replace them with the notice
 
31
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
32
 * the provisions above, a recipient may use your version of this file under
 
33
 * the terms of any one of the MPL, the GPL or the LGPL.
 
34
 *
 
35
 * ***** END LICENSE BLOCK ***** */
 
36
 
 
37
#ifdef DEBUG
 
38
static const char CVS_ID[] = "@(#) $RCSfile: item.c,v $ $Revision: 1.4 $ $Date: 2005/01/20 02:25:45 $";
 
39
#endif /* DEBUG */
 
40
 
 
41
/*
 
42
 * item.c
 
43
 *
 
44
 * This contains some item-manipulation code.
 
45
 */
 
46
 
 
47
#ifndef BASE_H
 
48
#include "base.h"
 
49
#endif /* BASE_H */
 
50
 
 
51
/*
 
52
 * nssItem_Create
 
53
 *
 
54
 * -- fgmr comments --
 
55
 *
 
56
 * The error may be one of the following values:
 
57
 *  NSS_ERROR_INVALID_ARENA
 
58
 *  NSS_ERROR_NO_MEMORY
 
59
 *  NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
 
60
 *  NSS_ERROR_INVALID_POINTER
 
61
 *  
 
62
 * Return value:
 
63
 *  A pointer to an NSSItem upon success
 
64
 *  NULL upon failure
 
65
 */
 
66
 
 
67
NSS_IMPLEMENT NSSItem *
 
68
nssItem_Create
 
69
(
 
70
  NSSArena *arenaOpt,
 
71
  NSSItem *rvOpt,
 
72
  PRUint32 length,
 
73
  const void *data
 
74
)
 
75
{
 
76
  NSSItem *rv = (NSSItem *)NULL;
 
77
 
 
78
#ifdef DEBUG
 
79
  if( (NSSArena *)NULL != arenaOpt ) {
 
80
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
 
81
      return (NSSItem *)NULL;
 
82
    }
 
83
  }
 
84
 
 
85
  if( (const void *)NULL == data ) {
 
86
    if( length > 0 ) {
 
87
      nss_SetError(NSS_ERROR_INVALID_POINTER);
 
88
      return (NSSItem *)NULL;
 
89
    }
 
90
  }
 
91
#endif /* DEBUG */
 
92
 
 
93
  if( (NSSItem *)NULL == rvOpt ) {
 
94
    rv = (NSSItem *)nss_ZNEW(arenaOpt, NSSItem);
 
95
    if( (NSSItem *)NULL == rv ) {
 
96
      goto loser;
 
97
    }
 
98
  } else {
 
99
    rv = rvOpt;
 
100
  }
 
101
 
 
102
  rv->size = length;
 
103
  rv->data = nss_ZAlloc(arenaOpt, length);
 
104
  if( (void *)NULL == rv->data ) {
 
105
    goto loser;
 
106
  }
 
107
 
 
108
  if( length > 0 ) {
 
109
    (void)nsslibc_memcpy(rv->data, data, length);
 
110
  }
 
111
 
 
112
  return rv;
 
113
 
 
114
 loser:
 
115
  if( rv != rvOpt ) {
 
116
    nss_ZFreeIf(rv);
 
117
  }
 
118
 
 
119
  return (NSSItem *)NULL;
 
120
}
 
121
 
 
122
NSS_IMPLEMENT void
 
123
nssItem_Destroy
 
124
(
 
125
  NSSItem *item
 
126
)
 
127
{
 
128
  nss_ClearErrorStack();
 
129
 
 
130
  nss_ZFreeIf(item->data);
 
131
  nss_ZFreeIf(item);
 
132
 
 
133
}
 
134
 
 
135
/*
 
136
 * nssItem_Duplicate
 
137
 *
 
138
 * -- fgmr comments --
 
139
 *
 
140
 * The error may be one of the following values:
 
141
 *  NSS_ERROR_INVALID_ARENA
 
142
 *  NSS_ERROR_NO_MEMORY
 
143
 *  NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
 
144
 *  NSS_ERROR_INVALID_ITEM
 
145
 *  
 
146
 * Return value:
 
147
 *  A pointer to an NSSItem upon success
 
148
 *  NULL upon failure
 
149
 */
 
150
 
 
151
NSS_IMPLEMENT NSSItem *
 
152
nssItem_Duplicate
 
153
(
 
154
  NSSItem *obj,
 
155
  NSSArena *arenaOpt,
 
156
  NSSItem *rvOpt
 
157
)
 
158
{
 
159
#ifdef DEBUG
 
160
  if( (NSSArena *)NULL != arenaOpt ) {
 
161
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
 
162
      return (NSSItem *)NULL;
 
163
    }
 
164
  }
 
165
 
 
166
  if( (NSSItem *)NULL == obj ) {
 
167
    nss_SetError(NSS_ERROR_INVALID_ITEM);
 
168
    return (NSSItem *)NULL;
 
169
  }
 
170
#endif /* DEBUG */
 
171
 
 
172
  return nssItem_Create(arenaOpt, rvOpt, obj->size, obj->data);
 
173
}
 
174
 
 
175
#ifdef DEBUG
 
176
/*
 
177
 * nssItem_verifyPointer
 
178
 *
 
179
 * -- fgmr comments --
 
180
 *
 
181
 * The error may be one of the following values:
 
182
 *  NSS_ERROR_INVALID_ITEM
 
183
 *
 
184
 * Return value:
 
185
 *  PR_SUCCESS upon success
 
186
 *  PR_FAILURE upon failure
 
187
 */
 
188
 
 
189
NSS_IMPLEMENT PRStatus
 
190
nssItem_verifyPointer
 
191
(
 
192
  const NSSItem *item
 
193
)
 
194
{
 
195
  if( ((const NSSItem *)NULL == item) ||
 
196
      (((void *)NULL == item->data) && (item->size > 0)) ) {
 
197
    nss_SetError(NSS_ERROR_INVALID_ITEM);
 
198
    return PR_FAILURE;
 
199
  }
 
200
 
 
201
  return PR_SUCCESS;
 
202
}
 
203
#endif /* DEBUG */
 
204
 
 
205
/*
 
206
 * nssItem_Equal
 
207
 *
 
208
 * -- fgmr comments --
 
209
 *
 
210
 * The error may be one of the following values:
 
211
 *  NSS_ERROR_INVALID_ITEM
 
212
 *
 
213
 * Return value:
 
214
 *  PR_TRUE if the items are identical
 
215
 *  PR_FALSE if they aren't
 
216
 *  PR_FALSE upon error
 
217
 */
 
218
 
 
219
NSS_IMPLEMENT PRBool
 
220
nssItem_Equal
 
221
(
 
222
  const NSSItem *one,
 
223
  const NSSItem *two,
 
224
  PRStatus *statusOpt
 
225
)
 
226
{
 
227
  if( (PRStatus *)NULL != statusOpt ) {
 
228
    *statusOpt = PR_SUCCESS;
 
229
  }
 
230
 
 
231
  if( ((const NSSItem *)NULL == one) && ((const NSSItem *)NULL == two) ) {
 
232
    return PR_TRUE;
 
233
  }
 
234
 
 
235
  if( ((const NSSItem *)NULL == one) || ((const NSSItem *)NULL == two) ) {
 
236
    return PR_FALSE;
 
237
  }
 
238
 
 
239
  if( one->size != two->size ) {
 
240
    return PR_FALSE;
 
241
  }
 
242
 
 
243
  return nsslibc_memequal(one->data, two->data, one->size, statusOpt);
 
244
}