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

« back to all changes in this revision

Viewing changes to unix/xc/config/pswrap/pswsemantics.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
 *  pswsemantics.c
 
3
 *
 
4
 * (c) Copyright 1988-1994 Adobe Systems Incorporated.
 
5
 * All rights reserved.
 
6
 * 
 
7
 * Permission to use, copy, modify, distribute, and sublicense this software
 
8
 * and its documentation for any purpose and without fee is hereby granted,
 
9
 * provided that the above copyright notices appear in all copies and that
 
10
 * both those copyright notices and this permission notice appear in
 
11
 * supporting documentation and that the name of Adobe Systems Incorporated
 
12
 * not be used in advertising or publicity pertaining to distribution of the
 
13
 * software without specific, written prior permission.  No trademark license
 
14
 * to use the Adobe trademarks is hereby granted.  If the Adobe trademark
 
15
 * "Display PostScript"(tm) is used to describe this software, its
 
16
 * functionality or for any other purpose, such use shall be limited to a
 
17
 * statement that this software works in conjunction with the Display
 
18
 * PostScript system.  Proper trademark attribution to reflect Adobe's
 
19
 * ownership of the trademark shall be given whenever any such reference to
 
20
 * the Display PostScript system is made.
 
21
 * 
 
22
 * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
 
23
 * ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
 
24
 * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 
25
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
26
 * NON- INFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO EVENT SHALL ADOBE BE LIABLE
 
27
 * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
 
28
 * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
 
29
 * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
 
30
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  ADOBE WILL NOT
 
31
 * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
 
32
 * 
 
33
 * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
 
34
 * Incorporated which may be registered in certain jurisdictions
 
35
 * 
 
36
 * Author:  Adobe Systems Incorporated
 
37
 */
 
38
 
 
39
/***********/
 
40
/* Imports */
 
41
/***********/
 
42
 
 
43
#include <stdlib.h>
 
44
#include <stdio.h>
 
45
 
 
46
#ifdef XENVIRONMENT
 
47
#include <X11/Xos.h>
 
48
#else
 
49
#include <string.h>
 
50
#endif
 
51
 
 
52
#include "pswdict.h"
 
53
#include "pswpriv.h"
 
54
#include "pswsemantics.h"
 
55
 
 
56
/***********************/
 
57
/* Module-wide globals */
 
58
/***********************/
 
59
 
 
60
char *currentPSWName = NULL;
 
61
int reportedPSWName = 0;
 
62
 
 
63
static PSWDict currentDict = NULL;
 
64
 
 
65
 
 
66
/*************************************************/
 
67
/* Procedures called by the parser's annotations */
 
68
/*************************************************/
 
69
 
 
70
static boolean IsCharType(Type t)
 
71
{
 
72
  return (t == T_CHAR || t == T_UCHAR);
 
73
}
 
74
 
 
75
static boolean IsNumStrType(Type t)
 
76
{
 
77
        return (t == T_NUMSTR
 
78
                        || t == T_FLOATNUMSTR
 
79
                        || t == T_LONGNUMSTR
 
80
                        || t == T_SHORTNUMSTR);
 
81
}
 
82
  
 
83
void PSWName(char *s)
 
84
{
 
85
  currentPSWName = psw_malloc(strlen(s)+1);
 
86
  strcpy(currentPSWName, s);
 
87
  reportedPSWName = 0;
 
88
}
 
89
  
 
90
  /* Generate the code for this wrap now */
 
91
void FinalizePSWrapDef(Header hdr, Body body)
 
92
{
 
93
  if (header && ! hdr->isStatic) EmitPrototype(hdr); 
 
94
 
 
95
  printf("#line %d \"%s\"\n", ++outlineno, ofile);
 
96
  EmitBodyHeader(hdr);
 
97
  
 
98
  printf("{\n"); outlineno++;
 
99
  EmitBody(body, hdr);
 
100
  printf("}\n"); outlineno++;
 
101
  printf("#line %d \"%s\"\n", yylineno, ifile); outlineno++;
 
102
 
 
103
  /* release storage for this wrap */
 
104
  /* Omit if you have lots of memory and want pswrap lean and mean */
 
105
  if (bigFile) {
 
106
    register Arg arg, nextarg; register Item item, nextitem;
 
107
    for(arg = hdr->inArgs; arg; arg = nextarg) {
 
108
        nextarg = arg->next;
 
109
        for(item = arg->items; item; item = nextitem) {
 
110
            nextitem = item->next;
 
111
            if (item->subscripted) {
 
112
                  if (!item->subscript->constant) free(item->subscript->name);
 
113
                  free(item->subscript);
 
114
                  if(item->scaled) {
 
115
                        if (!item->scale->constant) free(item->scale->name);
 
116
                        free(item->scale);
 
117
                  }
 
118
            }
 
119
            free(item->name); free(item);
 
120
        }
 
121
        free(arg);
 
122
    }
 
123
    for(arg = hdr->outArgs; arg; arg = nextarg) {
 
124
        nextarg = arg->next;
 
125
        for(item = arg->items; item; item = nextitem) {
 
126
            nextitem = item->next;
 
127
            if (item->subscripted) {
 
128
                if (!item->subscript->constant) free(item->subscript->name);
 
129
                free(item->subscript);
 
130
            }
 
131
            free(item->name); free(item);
 
132
        }
 
133
        free(arg);
 
134
    }
 
135
    free(hdr->name); free(hdr);
 
136
    FreeBody(body);
 
137
  }
 
138
 
 
139
  DestroyPSWDict(currentDict);
 
140
  currentDict = NULL;
 
141
  currentPSWName = NULL;
 
142
  reportedPSWName = 0;
 
143
}
 
144
 
 
145
  /* Complete construction of the Header tree and make some semantic checks */
 
146
Header PSWHeader(boolean isStatic, Args inArgs, Args outArgs)
 
147
{
 
148
  char *name = currentPSWName;
 
149
  register Arg arg, prevArg;
 
150
  register Item item, prevItem;
 
151
  int nextTag = 0;
 
152
  
 
153
  Header hdr = (Header)psw_calloc(sizeof(HeaderRec), 1);
 
154
  hdr->isStatic = isStatic;
 
155
  hdr->name = name;
 
156
 
 
157
  currentDict = CreatePSWDict(511);
 
158
 
 
159
  prevArg = NULL;
 
160
  for (arg = inArgs; arg; arg = arg->next) { /* foreach input arg */
 
161
    prevItem = NULL;
 
162
    for (item = arg->items; item; item = item->next) {
 
163
      if (IsCharType(arg->type)
 
164
          && !(item->starred || item->subscripted)) {
 
165
          ErrIntro(item->sourceLine);
 
166
          fprintf(stderr,
 
167
                 "char input parameter %s must be starred or subscripted\n",
 
168
                 item->name);
 
169
          /* remove item from list */
 
170
          if (prevItem) {prevItem->next = item->next;}
 
171
          else if (item == arg->items) {arg->items = item->next;};
 
172
          /* free(item);  XXX? */
 
173
          continue;
 
174
      }
 
175
      if(item->scaled && !IsNumStrType(arg->type)) {
 
176
          ErrIntro(item->sourceLine);
 
177
          fprintf(stderr,"only numstring parameters may be scaled\n");
 
178
          }
 
179
      if (IsNumStrType(arg->type)
 
180
              && (item->starred || !item->subscripted)) {
 
181
          ErrIntro(item->sourceLine);
 
182
          fprintf(stderr,
 
183
                 "numstring parameter %s may only be subscripted\n",
 
184
                 item->name);
 
185
          /* remove item from list */
 
186
          if (prevItem) {prevItem->next = item->next;}
 
187
          else if (item == arg->items) {arg->items = item->next;};
 
188
          /* free(item);  XXX? */
 
189
          continue;
 
190
      }
 
191
      if (arg->type != T_CONTEXT) {
 
192
          if (PSWDictLookup(currentDict, item->name) != -1) {
 
193
             ErrIntro(item->sourceLine);
 
194
             fprintf(stderr,"parameter %s reused\n", item->name);
 
195
             if (prevItem) {prevItem->next = item->next;}
 
196
                 else if (item == arg->items) {arg->items = item->next;};
 
197
                 /* free this ? */
 
198
                 continue;
 
199
          }
 
200
              PSWDictEnter(currentDict, item->name, (PSWDictValue) item);
 
201
          item->isoutput = false;
 
202
          item->type = arg->type;
 
203
          prevItem = item;
 
204
      }
 
205
    }
 
206
    if (arg->items == NULL) {
 
207
        if (prevArg) { prevArg->next = arg->next;}
 
208
            else if (arg == inArgs) {inArgs = arg->next;}
 
209
            continue;
 
210
    }
 
211
      prevArg = arg;
 
212
  }
 
213
 
 
214
  prevArg = NULL;
 
215
  for (arg = outArgs; arg; arg = arg->next) { /* foreach output arg */
 
216
    prevItem = NULL;
 
217
    for (item = arg->items; item; item = item->next) {
 
218
      if (arg->type == T_USEROBJECT) {
 
219
             ErrIntro(item->sourceLine);
 
220
         fprintf(stderr,"output parameter %s can not be of type userobject\n",
 
221
               item->name);
 
222
             /* remove item from list */
 
223
             if (prevItem) {prevItem->next = item->next;}
 
224
             else if (item == arg->items) {arg->items = item->next;};
 
225
            /* free(item); XXX */
 
226
           continue;
 
227
      }
 
228
      if (arg->type == T_NUMSTR || arg->type == T_FLOATNUMSTR
 
229
          || arg->type == T_LONGNUMSTR || arg->type == T_SHORTNUMSTR) {
 
230
             ErrIntro(item->sourceLine);
 
231
         fprintf(stderr,"output parameter %s can not be of type numstring\n",
 
232
               item->name);
 
233
             /* remove item from list */
 
234
             if (prevItem) {prevItem->next = item->next;}
 
235
             else if (item == arg->items) {arg->items = item->next;};
 
236
            /* free(item); XXX */
 
237
           continue;
 
238
      }
 
239
      if (!(item->starred || item->subscripted)) {
 
240
            ErrIntro(item->sourceLine);
 
241
        fprintf(stderr,"output parameter %s must be starred or subscripted\n",
 
242
              item->name);
 
243
            /* remove item from list */
 
244
            if (prevItem) {prevItem->next = item->next;}
 
245
            else if (item == arg->items) {arg->items = item->next;};
 
246
            /* free(item); XXX */
 
247
            continue;
 
248
      }
 
249
      if (PSWDictLookup(currentDict, item->name) != -1) {
 
250
            ErrIntro(item->sourceLine);
 
251
            fprintf(stderr,"parameter %s reused\n", item->name);
 
252
            /* remove item from list */
 
253
            if (prevItem) {prevItem->next = item->next;}
 
254
            else if (item == arg->items) {arg->items = item->next;};
 
255
            /* free the storage? XXX */
 
256
        continue;
 
257
      }
 
258
      PSWDictEnter(currentDict, item->name, (PSWDictValue) item);
 
259
      item->isoutput = true;
 
260
      item->type = arg->type;
 
261
      item->tag = nextTag++;
 
262
      prevItem = item;
 
263
   } /* inside for loop */
 
264
   if (arg->items == NULL) {
 
265
    if (prevArg) { 
 
266
        prevArg->next = arg->next;
 
267
    } else if (arg == outArgs) {
 
268
        outArgs = arg->next;
 
269
    }
 
270
    continue;
 
271
   }
 
272
      prevArg = arg;
 
273
  } /* outside for loop */
 
274
 
 
275
  /* now go looking for subscripts that name an input arg */
 
276
  for (arg = inArgs; arg; arg = arg->next) { /* foreach input arg */
 
277
    for (item = arg->items; item; item = item->next) {
 
278
      if (item->subscripted && !item->subscript->constant) {
 
279
        PSWDictValue v = PSWDictLookup(currentDict, item->subscript->name);
 
280
        if (v != -1) {
 
281
          Item subItem = (Item)v;
 
282
          if (subItem->isoutput) {
 
283
            ErrIntro(subItem->sourceLine);
 
284
            fprintf(stderr,"output parameter %s used as a subscript\n",
 
285
                subItem->name);
 
286
            continue;
 
287
            }
 
288
          if (subItem->type != T_INT) {
 
289
            ErrIntro(subItem->sourceLine); 
 
290
            fprintf(stderr,
 
291
                "input parameter %s used as a subscript is not an int\n",
 
292
                subItem->name);
 
293
            continue;
 
294
            }
 
295
          }
 
296
        }
 
297
      }
 
298
    }
 
299
  
 
300
  for (arg = outArgs; arg; arg = arg->next) { /* foreach output arg */
 
301
    for (item = arg->items; item; item = item->next) {
 
302
      if (item->subscripted && !item->subscript->constant) {
 
303
        PSWDictValue v = PSWDictLookup(currentDict, item->subscript->name);
 
304
        if (v != -1) {
 
305
          Item subItem = (Item)v;
 
306
          if (subItem->isoutput) {
 
307
            ErrIntro(subItem->sourceLine);
 
308
            fprintf(stderr,"output parameter %s used as a subscript\n",
 
309
                subItem->name);
 
310
            continue;
 
311
            }
 
312
          if (subItem->type != T_INT) {
 
313
            ErrIntro(subItem->sourceLine);
 
314
            fprintf(stderr,
 
315
               "input parameter %s used as a subscript is not an int\n",
 
316
               subItem->name);
 
317
            continue;
 
318
            }
 
319
          }
 
320
        }
 
321
      }
 
322
    }
 
323
  
 
324
  hdr->inArgs = inArgs;
 
325
  hdr->outArgs = outArgs;
 
326
 
 
327
  return hdr;
 
328
}
 
329
 
 
330
Token PSWToken(Type type, char *val)
 
331
{
 
332
  register Token token = (Token)psw_calloc(sizeof(TokenRec), 1);
 
333
 
 
334
  token->next = NULL;
 
335
  token->type = type;
 
336
  token->val = val;
 
337
  token->sourceLine = yylineno;
 
338
 
 
339
  switch (type) {
 
340
    case T_STRING:
 
341
    case T_NAME:
 
342
    case T_LITNAME: {
 
343
      Item dictVal = (Item) PSWDictLookup(currentDict, (char *)val);
 
344
      if ((PSWDictValue) dictVal != -1) {
 
345
          if ((type != T_NAME) && (dictVal->isoutput)) {
 
346
              ErrIntro(yylineno);
 
347
              fprintf(stderr,"output parameter %s used as %s\n",
 
348
                dictVal->name,
 
349
                (type == T_STRING) ? "string": "literal name");
 
350
          } else 
 
351
              if ((type != T_NAME) && !IsCharType(dictVal->type)) {
 
352
                ErrIntro(yylineno);
 
353
                fprintf(stderr,"non-char input parameter %s used as %s\n",
 
354
                        dictVal->name,
 
355
                        (type == T_STRING) ? "string": "literal name");
 
356
              } else 
 
357
                token->namedFormal = dictVal; /* ok, so assign a value */
 
358
      }
 
359
      break;
 
360
    }
 
361
    default:
 
362
      break;
 
363
    }
 
364
 
 
365
  return token;
 
366
}
 
367
 
 
368
Token PSWToken2(Type type, char *val, char *ind)
 
369
{
 
370
  register Token token = (Token)psw_calloc(sizeof(TokenRec), 1);
 
371
  Item dictVal = (Item) PSWDictLookup(currentDict, val);
 
372
  Item dvi;
 
373
 
 
374
  token->next = NULL;
 
375
  token->type = type;
 
376
  token->val = val;
 
377
  token->sourceLine = yylineno;
 
378
 
 
379
  /* Assert(type == T_SUBSCRIPTED); */
 
380
  if (((PSWDictValue) dictVal == -1) || (dictVal->isoutput)) {
 
381
    ErrIntro(yylineno);
 
382
    fprintf(stderr,"%s not an input parameter\n", val);
 
383
  }
 
384
  else if (!dictVal->subscripted) {
 
385
    ErrIntro(yylineno);
 
386
    fprintf(stderr,"%s not an array\n", val);
 
387
  }
 
388
  else if (dictVal->type >= T_NUMSTR) {
 
389
    ErrIntro(yylineno);
 
390
    fprintf(stderr,"cannot subscript numstring %s\n", val);
 
391
  }
 
392
  else if (IsCharType(dictVal->type)) {
 
393
    ErrIntro(yylineno);
 
394
    fprintf(stderr,"%s not a scalar type\n", val);
 
395
  }
 
396
  else {
 
397
    dvi = (Item) PSWDictLookup(currentDict, (char *)ind);
 
398
    if (((PSWDictValue) dvi != -1)
 
399
    && ((dvi->isoutput) || IsCharType(dvi->type))) {
 
400
      ErrIntro(yylineno);
 
401
      fprintf(stderr,"%s wrong type\n",(char *) ind);
 
402
    }
 
403
    else {
 
404
      token->body.var = (char *) ind;
 
405
      token->namedFormal = dictVal; /* ok, so assign a value */
 
406
      return token;
 
407
    }
 
408
  }
 
409
 
 
410
  /*  ERRORS fall through */
 
411
  free(token);
 
412
  return (PSWToken(T_NAME,val));
 
413
}
 
414
 
 
415
Arg PSWArg(Type type, Items items)
 
416
{
 
417
  register Arg arg = (Arg)psw_calloc(sizeof(ArgRec), 1);
 
418
  arg->next = NULL;
 
419
  arg->type = type;
 
420
  arg->items = items;
 
421
  return arg;
 
422
}
 
423
 
 
424
Item PSWItem(char *name)
 
425
{
 
426
  register Item item = (Item)psw_calloc(sizeof(ItemRec), 1);
 
427
  item->next = NULL;
 
428
  item->name = name;
 
429
  item->sourceLine = yylineno;
 
430
  return item;
 
431
}
 
432
 
 
433
Item PSWStarItem(char *name)
 
434
{
 
435
  register Item item = (Item)psw_calloc(sizeof(ItemRec), 1);
 
436
  item->next = NULL;
 
437
  item->name = name;
 
438
  item->starred = true;
 
439
  item->sourceLine = yylineno;
 
440
  return item;
 
441
}
 
442
 
 
443
Item PSWSubscriptItem(char *name, Subscript subscript)
 
444
{
 
445
  register Item item = (Item)psw_calloc(sizeof(ItemRec), 1);
 
446
  item->next = NULL;
 
447
  item->name = name;
 
448
  item->subscript = subscript;
 
449
  item->subscripted = true;
 
450
  item->sourceLine = yylineno;
 
451
  return item;
 
452
}
 
453
 
 
454
Item PSWScaleItem(char *name, Subscript subscript, char *nameval, int val)
 
455
{
 
456
  Item item;
 
457
  Scale scale = (Scale)psw_calloc(sizeof(ScaleRec), 1);
 
458
  item = PSWSubscriptItem(name, subscript);
 
459
  item->scaled = true;
 
460
  if(nameval)
 
461
        scale->name = nameval;
 
462
  else {
 
463
        scale->constant = true;
 
464
        scale->val = val;
 
465
  }
 
466
  item->scale = scale;
 
467
  return(item);
 
468
}
 
469
  
 
470
Subscript PSWNameSubscript(char *name)
 
471
{
 
472
  Subscript subscript = (Subscript)psw_calloc(sizeof(SubscriptRec), 1);
 
473
  subscript->name = name;
 
474
  return subscript;
 
475
}
 
476
 
 
477
Subscript PSWIntegerSubscript(int val)
 
478
{
 
479
  Subscript subscript = (Subscript)psw_calloc(sizeof(SubscriptRec), 1);
 
480
  subscript->constant = true;
 
481
  subscript->val = val;
 
482
  return subscript;
 
483
}
 
484
 
 
485
Args ConsPSWArgs(Arg arg, Args args)
 
486
{
 
487
  arg->next = args;
 
488
  return arg;
 
489
}
 
490
 
 
491
Tokens AppendPSWToken(Token token, Tokens tokens)
 
492
{
 
493
  register Token t;
 
494
  static Token firstToken, lastToken;   /* cache ptr to last */
 
495
  
 
496
  if ((token->type == T_NAME) && (token->namedFormal)) {
 
497
    if( token->namedFormal->isoutput) {
 
498
        Token oldtoken;
 
499
        char *pos = "printobject";
 
500
        char *ss = psw_malloc(strlen(pos) + 1);
 
501
        strcpy(ss, pos);
 
502
        free(token->val);
 
503
        oldtoken = token;
 
504
        token = PSWToken(T_INT, (char *) token->namedFormal->tag);
 
505
        free((char *)oldtoken);
 
506
        token->next = PSWToken(T_NAME, ss);
 
507
     } else 
 
508
        if (token->namedFormal->type == T_USEROBJECT) {
 
509
                char *pos = "execuserobject";
 
510
                char *ss = psw_malloc(strlen(pos) + 1);
 
511
                strcpy(ss, pos);
 
512
                token->next = PSWToken(T_NAME, ss);
 
513
        }
 
514
   }
 
515
        
 
516
  if (tokens == NULL) {
 
517
    firstToken = lastToken = token;
 
518
    return token;
 
519
  }
 
520
  
 
521
  if (tokens != firstToken)
 
522
    firstToken = lastToken = tokens;
 
523
  for (t = lastToken; t->next; t = t->next);
 
524
  lastToken = t->next = token;
 
525
 
 
526
  return tokens;
 
527
}
 
528
 
 
529
Args AppendPSWArgs(Arg arg, Args args)
 
530
{
 
531
  register Arg a;
 
532
  arg->next = NULL;
 
533
  if (args == NULL) return arg;
 
534
  
 
535
  for (a = args; a->next; a = a->next);
 
536
 
 
537
  a->next = arg; 
 
538
  return args;
 
539
}
 
540
 
 
541
Items AppendPSWItems(Item item, Items items)
 
542
{
 
543
  register Item t;
 
544
  item->next = NULL;
 
545
  if (items == NULL) return item;
 
546
  
 
547
  for (t = items; t->next; t = t->next);
 
548
 
 
549
  t->next = item; 
 
550
  return items;
 
551
}