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

« back to all changes in this revision

Viewing changes to unix/xc/extras/Xpm/cxpm/cxpm.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
/*
 
2
 * Copyright (C) 1998 Arnaud LE HORS
 
3
 *
 
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 
5
 * of this software and associated documentation files (the "Software"), to
 
6
 * deal in the Software without restriction, including without limitation the
 
7
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
8
 * sell copies of the Software, and to permit persons to whom the Software is
 
9
 * furnished to do so, subject to the following conditions:
 
10
 *
 
11
 * The above copyright notice and this permission notice shall be included in
 
12
 * all copies or substantial portions of the Software.
 
13
 *
 
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
17
 * Arnaud LE HORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 
18
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
19
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
20
 *
 
21
 * Except as contained in this notice, the name of Arnaud LE HORS shall not be
 
22
 * used in advertising or otherwise to promote the sale, use or other dealings
 
23
 * in this Software without prior written authorization from Arnaud LE HORS.
 
24
 */
 
25
/* $XFree86: xc/extras/Xpm/cxpm/cxpm.c,v 1.2 2001/08/01 00:44:34 tsi Exp $ */
 
26
 
 
27
/*****************************************************************************\
 
28
* cxpm.c:                                                                     *
 
29
*                                                                             *
 
30
*  Check XPM File program                                                     *
 
31
*                                                                             *
 
32
*  Developed by Arnaud Le Hors                                                *
 
33
\*****************************************************************************/
 
34
 
 
35
#define CXPMPROG
 
36
 
 
37
#include "../lib/XpmI.h"
 
38
 
 
39
#undef xpmGetC
 
40
#define xpmGetC(data) sGetc(data, data->stream.file)
 
41
#define Getc sGetc
 
42
#define Ungetc sUngetc
 
43
 
 
44
 
 
45
/*
 
46
 * special getc and ungetc counting read lines and characters
 
47
 * note that 's' could stand both for "special" and "slow" ;-)
 
48
 */
 
49
static int
 
50
sGetc(data)
 
51
    xpmData *data;
 
52
{
 
53
    int c = getc(data->stream.file);
 
54
    if (c == '\n') {
 
55
        data->lineNum++;
 
56
        data->charNum = 0;
 
57
    } else {
 
58
        data->charNum++;
 
59
    }
 
60
    return c;
 
61
}
 
62
 
 
63
static void
 
64
sUngetc(data, c)
 
65
    xpmData *data;
 
66
    int c;
 
67
{
 
68
    ungetc(c, data->stream.file);
 
69
    if (c == '\n') {
 
70
        data->lineNum--;
 
71
        data->charNum = 0;
 
72
    } else {
 
73
        data->charNum--;
 
74
    }
 
75
}
 
76
 
 
77
/* include all the code we need (yeah, I know, quite ugly...) */
 
78
#include "../lib/data.c"
 
79
#include "../lib/parse.c"
 
80
#include "../lib/RdFToI.c"      /* only for OpenReadFile and xpmDataClose */
 
81
#include "../lib/hashtab.c"
 
82
#include "../lib/misc.c"
 
83
#include "../lib/Attrib.c"
 
84
#include "../lib/Image.c"
 
85
 
 
86
void
 
87
ErrorMessage(ErrorStatus, data)
 
88
    int ErrorStatus;
 
89
    xpmData *data;
 
90
 
 
91
{
 
92
    char *error = NULL;
 
93
 
 
94
    switch (ErrorStatus) {
 
95
    case XpmSuccess:
 
96
        return;
 
97
    case XpmOpenFailed:
 
98
        error = "Cannot open file";
 
99
        break;
 
100
    case XpmFileInvalid:
 
101
        error = "Invalid XPM file";
 
102
        break;
 
103
    case XpmNoMemory:
 
104
        error = "Not enough memory";
 
105
        break;
 
106
    case XpmColorFailed:
 
107
        error = "Failed to parse color";
 
108
        break;
 
109
    }
 
110
 
 
111
    if (error) {
 
112
        fprintf(stderr, "Xpm Error: %s.\n", error);
 
113
        if (ErrorStatus == XpmFileInvalid && data)
 
114
          fprintf(stderr, "Error found line %d near character %d\n",
 
115
                  data->lineNum + 1,
 
116
                  data->charNum + 1);
 
117
        exit(1);
 
118
    }
 
119
}
 
120
 
 
121
int
 
122
main(argc, argv)
 
123
    int argc;
 
124
    char **argv;
 
125
{
 
126
    XpmImage image;
 
127
    char *filename;
 
128
    int ErrorStatus;
 
129
    xpmData data;
 
130
 
 
131
    if (argc > 1) {
 
132
        if (!strcmp(argv[1], "-?") || !strncmp(argv[1], "-h", 2)) {
 
133
            fprintf(stderr, "Usage: %s [filename]\n", argv[0]);
 
134
            exit(1);
 
135
        }
 
136
        filename = argv[1];
 
137
    } else {
 
138
        filename = NULL;
 
139
    }
 
140
 
 
141
    xpmInitXpmImage(&image);
 
142
 
 
143
    if ((ErrorStatus = OpenReadFile(filename, &data)) != XpmSuccess)
 
144
        ErrorMessage(ErrorStatus, NULL);
 
145
 
 
146
    ErrorStatus = xpmParseData(&data, &image, NULL);
 
147
    ErrorMessage(ErrorStatus, &data);
 
148
 
 
149
    xpmDataClose(&data);
 
150
    XpmFreeXpmImage(&image);
 
151
 
 
152
    exit(0);
 
153
}