~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/Xmu/Lower.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: Lower.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
 
2
 
 
3
/* 
 
4
 
 
5
Copyright 1988, 1998  The Open Group
 
6
 
 
7
Permission to use, copy, modify, distribute, and sell this software and its
 
8
documentation for any purpose is hereby granted without fee, provided that
 
9
the above copyright notice appear in all copies and that both that
 
10
copyright notice and this permission notice appear in supporting
 
11
documentation.
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall not be
 
24
used in advertising or otherwise to promote the sale, use or other dealings
 
25
in this Software without prior written authorization from The Open Group.
 
26
 
 
27
*/
 
28
 
 
29
/* $XFree86: xc/lib/Xmu/Lower.c,v 1.12 2001/12/14 19:55:47 dawes Exp $ */
 
30
 
 
31
#define  XK_LATIN1
 
32
#include <X11/keysymdef.h>
 
33
#include <X11/Xmu/CharSet.h>
 
34
#include <X11/Xmu/SysUtil.h>
 
35
 
 
36
#include <stdio.h>
 
37
 
 
38
#ifndef HAS_SNPRINTF
 
39
#undef SCOPE
 
40
#define SCOPE static
 
41
#include "snprintf.c"
 
42
#endif
 
43
 
 
44
#include <stdarg.h>
 
45
 
 
46
/*
 
47
 * ISO Latin-1 case conversion routine
 
48
 */
 
49
#define XmuTolower(c)                                                    \
 
50
((c) >= XK_a && (c) <= XK_z ?                                            \
 
51
 (c) : (c) >= XK_A && (c) <= XK_Z ?                                      \
 
52
 (c) + (XK_a - XK_A) : (c) >= XK_Agrave && (c) <= XK_Odiaeresis ?        \
 
53
 (c) + (XK_agrave - XK_Agrave) : (c) >= XK_Ooblique && (c) <= XK_Thorn ? \
 
54
 (c) + (XK_oslash - XK_Ooblique) :                                       \
 
55
 (c))
 
56
 
 
57
#define XmuToupper(c)                                                    \
 
58
((c) >= XK_A && (c) <= XK_Z ?                                            \
 
59
 (c) : (c) >= XK_a && (c) <= XK_z ?                                      \
 
60
 (c) - (XK_a - XK_A) : (c) >= XK_agrave && (c) <= XK_odiaeresis ?        \
 
61
 (c) - (XK_agrave - XK_Agrave) : (c) >= XK_oslash && (c) <= XK_thorn ?   \
 
62
 (c) - (XK_oslash - XK_Ooblique) :                                       \
 
63
 (c))
 
64
 
 
65
/*
 
66
 * Implementation
 
67
 */
 
68
void
 
69
XmuCopyISOLatin1Lowered(char *dst, _Xconst char *src)
 
70
{
 
71
  register unsigned char *dest, *source;
 
72
 
 
73
  for (dest = (unsigned char *)dst, source = (unsigned char *)src;
 
74
       *source;
 
75
       source++, dest++)
 
76
    *dest = XmuTolower(*source);
 
77
  *dest = '\0';
 
78
}
 
79
 
 
80
void
 
81
XmuCopyISOLatin1Uppered(char *dst, _Xconst char *src)
 
82
{
 
83
  register unsigned char *dest, *source;
 
84
 
 
85
  for (dest = (unsigned char *)dst, source = (unsigned char *)src;
 
86
       *source;
 
87
       source++, dest++)
 
88
    *dest = XmuToupper(*source);
 
89
  *dest = '\0';
 
90
}
 
91
 
 
92
int
 
93
XmuCompareISOLatin1(_Xconst char *first, _Xconst char *second)
 
94
{
 
95
  register unsigned char *ap, *bp;
 
96
 
 
97
  for (ap = (unsigned char *)first, bp = (unsigned char *)second;
 
98
       *ap && *bp && XmuTolower(*ap) == XmuTolower(*bp);
 
99
       ap++, bp++)
 
100
    ;
 
101
 
 
102
  return ((int)XmuTolower(*ap) - (int)XmuTolower(*bp));
 
103
}
 
104
 
 
105
void
 
106
XmuNCopyISOLatin1Lowered(char *dst, _Xconst char *src, register int size)
 
107
{
 
108
  register unsigned char *dest, *source;
 
109
 
 
110
  if (size > 0)
 
111
    {
 
112
      for (dest = (unsigned char *)dst, source = (unsigned char *)src;
 
113
           *source && size > 1;
 
114
           source++, dest++, size--)
 
115
        *dest = XmuTolower(*source);
 
116
      *dest = '\0';
 
117
    }
 
118
}
 
119
 
 
120
void
 
121
XmuNCopyISOLatin1Uppered(char *dst, _Xconst char *src, register int size)
 
122
{
 
123
  register unsigned char *dest, *source;
 
124
 
 
125
  if (size > 0)
 
126
    {
 
127
      for (dest = (unsigned char *)dst, source = (unsigned char *)src;
 
128
           *source && size > 1;
 
129
           source++, dest++, size--)
 
130
        *dest = XmuToupper(*source);
 
131
      *dest = '\0';
 
132
    }
 
133
}
 
134
 
 
135
int
 
136
XmuSnprintf(char *str, int size, _Xconst char *fmt, ...)
 
137
{
 
138
  va_list ap;
 
139
  int retval;
 
140
 
 
141
  if (size <= 0)
 
142
    return (size);
 
143
 
 
144
  va_start(ap, fmt);
 
145
 
 
146
#if 0
 
147
  retval = vsprintf(str, fmt, ap);
 
148
  if (retval >= size)
 
149
    {
 
150
      fprintf(stderr, "WARNING: buffer overflow detected!\n");
 
151
      fflush(stderr);
 
152
      abort();
 
153
    }
 
154
#else
 
155
  retval = vsnprintf(str, size, fmt, ap);
 
156
#endif
 
157
 
 
158
  va_end(ap);
 
159
 
 
160
  return (retval);
 
161
}