comparison interps/cfunge/cfunge-src/src/instructions/safe_env.c @ 996:859f9b4339e6

<Gregor> tar xf egobot.tar.xz
author HackBot
date Sun, 09 Dec 2012 19:30:08 +0000
parents
children
comparison
equal deleted inserted replaced
995:6883f5911eb7 996:859f9b4339e6
1 /* ANSI-C code produced by gperf version 3.0.3 */
2 /* Command-line: gperf safe_env.gperf */
3 /* Computed positions: -k'4,$' */
4
5 #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
6 && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
7 && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
8 && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
9 && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
10 && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
11 && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
12 && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
13 && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
14 && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
15 && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
16 && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
17 && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
18 && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
19 && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
20 && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
21 && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
22 && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
23 && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
24 && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
25 && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
26 && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
27 && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
28 /* The character set is not based on ISO-646. */
29 #error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
30 #endif
31
32 #line 7 "safe_env.gperf"
33
34 #include <string.h>
35 #include <stdbool.h>
36 #include "safe_env.h"
37
38 #define TOTAL_KEYWORDS 32
39 #define MIN_WORD_LENGTH 2
40 #define MAX_WORD_LENGTH 17
41 #define MIN_HASH_VALUE 2
42 #define MAX_HASH_VALUE 54
43 /* maximum key range = 53, duplicates = 0 */
44
45 FUNGE_ATTR_FAST static inline unsigned int
46 safe_env_hash (register const char *str, register unsigned int len)
47 {
48 static const unsigned char asso_values[] =
49 {
50 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
51 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
52 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
53 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
54 55, 55, 55, 55, 55, 55, 55, 55, 55, 5,
55 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
56 55, 55, 55, 55, 55, 15, 55, 0, 0, 5,
57 55, 25, 20, 0, 55, 55, 15, 15, 15, 15,
58 0, 55, 10, 15, 0, 0, 55, 55, 55, 0,
59 0, 55, 55, 55, 55, 55, 55, 55, 55, 55,
60 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
61 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
62 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
63 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
64 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
65 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
66 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
67 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
68 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
69 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
70 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
71 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
72 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
73 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
74 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
75 55, 55, 55, 55, 55, 55
76 };
77 register int hval = len;
78
79 switch (hval)
80 {
81 default:
82 hval += asso_values[(unsigned char)str[3]];
83 /*FALLTHROUGH*/
84 case 3:
85 case 2:
86 break;
87 }
88 return hval + asso_values[(unsigned char)str[len - 1]];
89 }
90
91 FUNGE_ATTR_FAST static inline const char *
92 safe_in_word_set (register const char *str, register unsigned int len)
93 {
94 static const unsigned char lengthtable[] =
95 {
96 0, 0, 2, 3, 4, 5, 0, 7, 3, 0, 0, 6, 7, 8,
97 4, 10, 6, 12, 8, 0, 5, 6, 7, 0, 4, 10, 11, 7,
98 0, 14, 0, 0, 17, 8, 4, 5, 6, 0, 0, 9, 10, 11,
99 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4
100 };
101 static const char * const wordlist[] =
102 {
103 "", "",
104 "TZ",
105 "PWD",
106 "HOST",
107 "GROUP",
108 "",
109 "DISPLAY",
110 "PS1",
111 "", "",
112 "OSTYPE",
113 "LC_TIME",
114 "LC_CTYPE",
115 "HOME",
116 "LC_COLLATE",
117 "EDITOR",
118 "LC_TELEPHONE",
119 "LC_PAPER",
120 "",
121 "PAGER",
122 "VISUAL",
123 "COLUMNS",
124 "",
125 "USER",
126 "LC_NUMERIC",
127 "LC_MONETARY",
128 "LC_NAME",
129 "",
130 "LC_MEASUREMENT",
131 "", "",
132 "LC_IDENTIFICATION",
133 "MACHTYPE",
134 "TERM",
135 "SHELL",
136 "LC_ALL",
137 "", "",
138 "COLORTERM",
139 "LC_ADDRESS",
140 "LC_MESSAGES",
141 "", "",
142 "PATH",
143 "", "", "", "", "", "", "", "", "",
144 "LANG"
145 };
146
147 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
148 {
149 register int key = safe_env_hash (str, len);
150
151 if (key <= MAX_HASH_VALUE && key >= 0)
152 if (len == lengthtable[key])
153 {
154 register const char *s = wordlist[key];
155
156 if (*str == *s && !memcmp (str + 1, s + 1, len - 1))
157 return s;
158 }
159 }
160 return 0;
161 }
162 #line 45 "safe_env.gperf"
163
164
165 FUNGE_ATTR_FAST bool check_env_is_safe(const char *envvar) {
166 const char * p;
167
168 p = strchr(envvar, '=');
169 if (!p)
170 return false;
171 else
172 return (safe_in_word_set(envvar, p - envvar) != NULL);
173 }