~ubuntu-branches/ubuntu/hardy/gnupg2/hardy-updates

« back to all changes in this revision

Viewing changes to intl/localealias.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia, Michael Bienia, Kees Cook
  • Date: 2006-12-07 00:28:23 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061207002823-0i7ittrpmsm1nv0i
Tags: 2.0.1-0ubuntu1
[ Michael Bienia ]
* New upstream version.
* Remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
* g10/encr-data.c: remotely controllable function pointer (CVE-2006-6235)
* debian/control: add libcurl3-gnutls-dev to build-depends 
  (Closes Ubuntu: #62864)

[ Kees Cook ]
* debian/rules: include doc/ files as done with gnupg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Handle aliases for locale names.
2
 
   Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc.
 
2
   Copyright (C) 1995-1999, 2000-2001, 2003, 2005 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software; you can redistribute it and/or modify it
5
5
   under the terms of the GNU Library General Public License as published
13
13
 
14
14
   You should have received a copy of the GNU Library General Public
15
15
   License along with this program; if not, write to the Free Software
16
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17
17
   USA.  */
18
18
 
19
19
/* Tell glibc's <string.h> to provide a prototype for mempcpy().
81
81
# endif
82
82
# define HAVE_MEMPCPY   1
83
83
# define HAVE___FSETLOCKING     1
 
84
#endif
84
85
 
85
 
/* We need locking here since we can be called from different places.  */
 
86
/* Handle multi-threaded applications.  */
 
87
#ifdef _LIBC
86
88
# include <bits/libc-lock.h>
87
 
 
88
 
__libc_lock_define_initialized (static, lock);
 
89
#else
 
90
# include "lock.h"
89
91
#endif
90
92
 
91
93
#ifndef internal_function
120
122
#endif
121
123
 
122
124
 
 
125
__libc_lock_define_initialized (static, lock)
 
126
 
 
127
 
123
128
struct alias_map
124
129
{
125
130
  const char *alias;
155
160
  const char *result = NULL;
156
161
  size_t added;
157
162
 
158
 
#ifdef _LIBC
159
163
  __libc_lock_lock (lock);
160
 
#endif
161
164
 
162
165
  if (locale_alias_path == NULL)
163
166
    locale_alias_path = LOCALE_ALIAS_PATH;
204
207
    }
205
208
  while (added != 0);
206
209
 
207
 
#ifdef _LIBC
208
210
  __libc_lock_unlock (lock);
209
 
#endif
210
211
 
211
212
  return result;
212
213
}
230
231
  memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile);
231
232
#endif
232
233
 
 
234
#ifdef _LIBC
 
235
  /* Note the file is opened with cancellation in the I/O functions
 
236
     disabled.  */
 
237
  fp = fopen (relocate (full_fname), "rc");
 
238
#else
233
239
  fp = fopen (relocate (full_fname), "r");
 
240
#endif
234
241
  freea (full_fname);
235
242
  if (fp == NULL)
236
243
    return 0;
254
261
      char *alias;
255
262
      char *value;
256
263
      char *cp;
 
264
      int complete_line;
257
265
 
258
266
      if (FGETS (buf, sizeof buf, fp) == NULL)
259
267
        /* EOF reached.  */
260
268
        break;
261
269
 
 
270
      /* Determine whether the line is complete.  */
 
271
      complete_line = strchr (buf, '\n') != NULL;
 
272
 
262
273
      cp = buf;
263
274
      /* Ignore leading white space.  */
264
275
      while (isspace ((unsigned char) cp[0]))
280
291
 
281
292
          if (cp[0] != '\0')
282
293
            {
283
 
              size_t alias_len;
284
 
              size_t value_len;
285
 
 
286
294
              value = cp++;
287
295
              while (cp[0] != '\0' && !isspace ((unsigned char) cp[0]))
288
296
                ++cp;
298
306
              else if (cp[0] != '\0')
299
307
                *cp++ = '\0';
300
308
 
301
 
              if (nmap >= maxmap)
302
 
                if (__builtin_expect (extend_alias_table (), 0))
303
 
                  return added;
304
 
 
305
 
              alias_len = strlen (alias) + 1;
306
 
              value_len = strlen (value) + 1;
307
 
 
308
 
              if (string_space_act + alias_len + value_len > string_space_max)
 
309
#ifdef IN_LIBGLOCALE
 
310
              /* glibc's locale.alias contains entries for ja_JP and ko_KR
 
311
                 that make it impossible to use a Japanese or Korean UTF-8
 
312
                 locale under the name "ja_JP" or "ko_KR".  Ignore these
 
313
                 entries.  */
 
314
              if (strchr (alias, '_') == NULL)
 
315
#endif
309
316
                {
310
 
                  /* Increase size of memory pool.  */
311
 
                  size_t new_size = (string_space_max
312
 
                                     + (alias_len + value_len > 1024
313
 
                                        ? alias_len + value_len : 1024));
314
 
                  char *new_pool = (char *) realloc (string_space, new_size);
315
 
                  if (new_pool == NULL)
316
 
                    return added;
317
 
 
318
 
                  if (__builtin_expect (string_space != new_pool, 0))
 
317
                  size_t alias_len;
 
318
                  size_t value_len;
 
319
 
 
320
                  if (nmap >= maxmap)
 
321
                    if (__builtin_expect (extend_alias_table (), 0))
 
322
                      goto out;
 
323
 
 
324
                  alias_len = strlen (alias) + 1;
 
325
                  value_len = strlen (value) + 1;
 
326
 
 
327
                  if (string_space_act + alias_len + value_len > string_space_max)
319
328
                    {
320
 
                      size_t i;
 
329
                      /* Increase size of memory pool.  */
 
330
                      size_t new_size = (string_space_max
 
331
                                         + (alias_len + value_len > 1024
 
332
                                            ? alias_len + value_len : 1024));
 
333
                      char *new_pool = (char *) realloc (string_space, new_size);
 
334
                      if (new_pool == NULL)
 
335
                        goto out;
321
336
 
322
 
                      for (i = 0; i < nmap; i++)
 
337
                      if (__builtin_expect (string_space != new_pool, 0))
323
338
                        {
324
 
                          map[i].alias += new_pool - string_space;
325
 
                          map[i].value += new_pool - string_space;
 
339
                          size_t i;
 
340
 
 
341
                          for (i = 0; i < nmap; i++)
 
342
                            {
 
343
                              map[i].alias += new_pool - string_space;
 
344
                              map[i].value += new_pool - string_space;
 
345
                            }
326
346
                        }
 
347
 
 
348
                      string_space = new_pool;
 
349
                      string_space_max = new_size;
327
350
                    }
328
351
 
329
 
                  string_space = new_pool;
330
 
                  string_space_max = new_size;
 
352
                  map[nmap].alias = memcpy (&string_space[string_space_act],
 
353
                                            alias, alias_len);
 
354
                  string_space_act += alias_len;
 
355
 
 
356
                  map[nmap].value = memcpy (&string_space[string_space_act],
 
357
                                            value, value_len);
 
358
                  string_space_act += value_len;
 
359
 
 
360
                  ++nmap;
 
361
                  ++added;
331
362
                }
332
 
 
333
 
              map[nmap].alias = memcpy (&string_space[string_space_act],
334
 
                                        alias, alias_len);
335
 
              string_space_act += alias_len;
336
 
 
337
 
              map[nmap].value = memcpy (&string_space[string_space_act],
338
 
                                        value, value_len);
339
 
              string_space_act += value_len;
340
 
 
341
 
              ++nmap;
342
 
              ++added;
343
363
            }
344
364
        }
345
365
 
346
366
      /* Possibly not the whole line fits into the buffer.  Ignore
347
367
         the rest of the line.  */
348
 
      while (strchr (buf, '\n') == NULL)
349
 
        if (FGETS (buf, sizeof buf, fp) == NULL)
350
 
          /* Make sure the inner loop will be left.  The outer loop
351
 
             will exit at the `feof' test.  */
352
 
          break;
 
368
      if (! complete_line)
 
369
        do
 
370
          if (FGETS (buf, sizeof buf, fp) == NULL)
 
371
            /* Make sure the inner loop will be left.  The outer loop
 
372
               will exit at the `feof' test.  */
 
373
            break;
 
374
        while (strchr (buf, '\n') == NULL);
353
375
    }
354
376
 
 
377
 out:
355
378
  /* Should we test for ferror()?  I think we have to silently ignore
356
379
     errors.  --drepper  */
357
380
  fclose (fp);