]> arthur.barton.de Git - netatalk.git/blob - libatalk/util/strdicasecmp.c
Memory overflow caused by 'basedir regex', bug #567
[netatalk.git] / libatalk / util / strdicasecmp.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <atalk/util.h>
6
7 const int       _diacasemap[] = {
8         /* map  value   name */
9         0       /* 0    NUL*/,
10         1       /* 1    SOH*/,
11         2       /* 2    STX*/,
12         3       /* 3    ETX*/,
13         4       /* 4    EOT*/,
14         5       /* 5    ENQ*/,
15         6       /* 6    ACK*/,
16         7       /* 7    BEL*/,
17         8       /* 8    BS*/,
18         9       /* 9    HT*/,
19         10      /* 10   NL*/,
20         11      /* 11   VT*/,
21         12      /* 12   NP*/,
22         13      /* 13   CR*/,
23         14      /* 14   SO*/,
24         15      /* 15   SI*/,
25         16      /* 16   DLE*/,
26         17      /* 17   DC1*/,
27         18      /* 18   DC2*/,
28         19      /* 19   DC3*/,
29         20      /* 20   DC4*/,
30         21      /* 21   NAK*/,
31         22      /* 22   SYN*/,
32         23      /* 23   ETB*/,
33         24      /* 24   CAN*/,
34         25      /* 25   EM*/,
35         26      /* 26   SUB*/,
36         27      /* 27   ESC*/,
37         28      /* 28   FS*/,
38         29      /* 29   GS*/,
39         30      /* 30   RS*/,
40         31      /* 31   US*/,
41         32      /* 32   SP*/,
42         33      /* 33    ! */,
43         34      /* 34    " */,
44         35      /* 35    # */,
45         36      /* 36    $ */,
46         37      /* 37    % */,
47         38      /* 38    & */,
48         39      /* 39    ' */,
49         40      /* 40    ( */,
50         41      /* 41    ) */,
51         42      /* 42    * */,
52         43      /* 43    + */,
53         44      /* 44    , */,
54         45      /* 45    - */,
55         46      /* 46    . */,
56         47      /* 47    / */,
57         48      /* 48    0 */,
58         49      /* 49    1 */,
59         50      /* 50    2 */,
60         51      /* 51    3 */,
61         52      /* 52    4 */,
62         53      /* 53    5 */,
63         54      /* 54    6 */,
64         55      /* 55    7 */,
65         56      /* 56    8 */,
66         57      /* 57    9 */,
67         58      /* 58    : */,
68         59      /* 59    ; */,
69         60      /* 60    < */,
70         61      /* 61    = */,
71         62      /* 62    > */,
72         63      /* 63    ? */,
73         64      /* 64    @ */,
74         65      /* 65    A */,
75         66      /* 66    B */,
76         67      /* 67    C */,
77         68      /* 68    D */,
78         69      /* 69    E */,
79         70      /* 70    F */,
80         71      /* 71    G */,
81         72      /* 72    H */,
82         73      /* 73    I */,
83         74      /* 74    J */,
84         75      /* 75    K */,
85         76      /* 76    L */,
86         77      /* 77    M */,
87         78      /* 78    N */,
88         79      /* 79    O */,
89         80      /* 80    P */,
90         81      /* 81    Q */,
91         82      /* 82    R */,
92         83      /* 83    S */,
93         84      /* 84    T */,
94         85      /* 85    U */,
95         86      /* 86    V */,
96         87      /* 87    W */,
97         88      /* 88    X */,
98         89      /* 89    Y */,
99         90      /* 90    Z */,
100         91      /* 91    [ */,
101         92      /* 92    \ */,
102         93      /* 93    ] */,
103         94      /* 94    ^ */,
104         95      /* 95    _ */,
105         96      /* 96    ` */,
106         65      /* 97    a */,
107         66      /* 98    b */,
108         67      /* 99    c */,
109         68      /* 100   d */,
110         69      /* 101   e */,
111         70      /* 102   f */,
112         71      /* 103   g */,
113         72      /* 104   h */,
114         73      /* 105   i */,
115         74      /* 106   j */,
116         75      /* 107   k */,
117         76      /* 108   l */,
118         77      /* 109   m */,
119         78      /* 110   n */,
120         79      /* 111   o */,
121         80      /* 112   p */,
122         81      /* 113   q */,
123         82      /* 114   r */,
124         83      /* 115   s */,
125         84      /* 116   t */,
126         85      /* 117   u */,
127         86      /* 118   v */,
128         87      /* 119   w */,
129         88      /* 120   x */,
130         89      /* 121   y */,
131         90      /* 122   z */,
132         123     /* 123   { */,
133         124     /* 124   | */,
134         125     /* 125   } */,
135         126     /* 126   ~ */,
136         127     /* 127  DEL*/,
137         128     /* 128  Adieresis*/,
138         129     /* 129  Aring*/,
139         130     /* 130  Ccedilla*/,
140         131     /* 131  Eacute*/,
141         132     /* 132  Ntilda*/,
142         133     /* 133  Odieresis*/,
143         134     /* 134  Udieresis*/,
144         231     /* 135  aacute*/,
145         203     /* 136  agrave*/,
146         229     /* 137  acircumflex*/,
147         128     /* 138  adieresis*/,
148         204     /* 139  atilda*/,
149         129     /* 140  aring*/,
150         130     /* 141  ccedilla*/,
151         131     /* 142  eacute*/,
152         233     /* 143  egrave*/,
153         230     /* 144  ecircumflex*/,
154         232     /* 145  edieresis*/,
155         234     /* 146  iacute*/,
156         237     /* 147  igrave*/,
157         235     /* 148  icircumflex*/,
158         236     /* 149  idieresis*/,
159         132     /* 150  ntilda*/,
160         238     /* 151  oacute*/,
161         241     /* 152  ograve*/,
162         239     /* 153  ocircumflex*/,
163         133     /* 154  odieresis*/,
164         205     /* 155  otilda*/,
165         242     /* 156  uacute*/,
166         244     /* 157  ugrave*/,
167         243     /* 158  ucircumflex*/,
168         134     /* 159  udieresis*/,
169         160     /* 160  daggar*/,
170         161     /* 161  ring*/,
171         162     /* 162  cent*/,
172         163     /* 163  sterling*/,
173         164     /* 164  section*/,
174         165     /* 165  bullet*/,
175         166     /* 166  paragraph*/,
176         167     /* 167  germandbls*/,
177         168     /* 168  registered*/,
178         169     /* 169  copyright*/,
179         170     /* 170  trademark*/,
180         171     /* 171  acute*/,
181         172     /* 172  dieresis*/,
182         173     /* 173  notequal*/,
183         174     /* 174  AE*/,
184         175     /* 175  Oslash*/,
185         176     /* 176  infinity*/,
186         177     /* 177  plusminus*/,
187         178     /* 178  lessequal*/,
188         179     /* 179  greaterequal*/,
189         180     /* 180  yen*/,
190         181     /* 181  mu*/,
191         198     /* 182  delta*/,
192         183     /* 183  Sigma*/,
193         184     /* 184  Pi*/,
194         184     /* 185  pi*/,
195         186     /* 186  intergral*/,
196         187     /* 187  ordfeminine*/,
197         188     /* 188  ordmasculine*/,
198         189     /* 189  Omega*/,
199         174     /* 190  ae*/,
200         175     /* 191  oslash*/,
201         192     /* 192  questiondown*/,
202         193     /* 193  exclamdown*/,
203         194     /* 194  not*/,
204         195     /* 195  radical*/,
205         196     /* 196  florin*/,
206         197     /* 197  aprox*/,
207         198     /* 198  Delta*/,
208         199     /* 199  guillemotleft*/,
209         200     /* 200  guillemotright*/,
210         201     /* 201  ellipsis*/,
211         202     /* 202  */,
212         203     /* 203  Agrave*/,
213         204     /* 204  Atilda*/,
214         205     /* 205  Otilda*/,
215         206     /* 206  OE*/,
216         206     /* 207  oe*/,
217         208     /* 208  endash*/,
218         209     /* 209  emdash*/,
219         210     /* 210  quotedblleft*/,
220         211     /* 211  quotedblright*/,
221         212     /* 212  quoteleft*/,
222         213     /* 213  quoteright*/,
223         214     /* 214  divide*/,
224         215     /* 215  diamond*/,
225         217     /* 216  ydieresis*/,
226         217     /* 217  Ydieresis*/,
227         218     /* 218  fraction*/,
228         219     /* 219  currency*/,
229         220     /* 220  guilsinglleft*/,
230         221     /* 221  guilsinglright*/,
231         222     /* 222  fi*/,
232         223     /* 223  fl*/,
233         224     /* 224  daggardbl*/,
234         225     /* 225  periodcentered*/,
235         226     /* 226  quotesinglbase*/,
236         227     /* 227  quotedblbase*/,
237         228     /* 228  perthousand*/,
238         229     /* 229  Acircumflex*/,
239         230     /* 230  Ecircumflex*/,
240         231     /* 231  Aaccute*/,
241         232     /* 232  Edieresis*/,
242         233     /* 233  Egrave*/,
243         234     /* 234  Iaccute*/,
244         235     /* 235  Icircumflex*/,
245         236     /* 236  Idieresis*/,
246         237     /* 237  Igrave*/,
247         238     /* 238  Oaccute*/,
248         239     /* 239  Ocircumflex*/,
249         240     /* 240  apple*/,
250         241     /* 241  Ograve*/,
251         242     /* 242  Uaccute*/,
252         243     /* 243  Ucircumflex*/,
253         244     /* 244  Ugrave*/,
254         245     /* 245  dotlessi*/,
255         246     /* 246  circumflex*/,
256         247     /* 247  tilda*/,
257         248     /* 248  macron*/,
258         249     /* 249  breve*/,
259         250     /* 250  dotaccent*/,
260         251     /* 251  ring*/,
261         252     /* 252  cedilla*/,
262         253     /* 253  hungarumlaut*/,
263         254     /* 254  ogonek*/,
264         255     /* 255  caron*/,
265 };
266
267 const int       _dialowermap[] = {
268         /* map  value   name */
269         0       /* 0    NUL*/,
270         1       /* 1    SOH*/,
271         2       /* 2    STX*/,
272         3       /* 3    ETX*/,
273         4       /* 4    EOT*/,
274         5       /* 5    ENQ*/,
275         6       /* 6    ACK*/,
276         7       /* 7    BEL*/,
277         8       /* 8    BS*/,
278         9       /* 9    HT*/,
279         10      /* 10   NL*/,
280         11      /* 11   VT*/,
281         12      /* 12   NP*/,
282         13      /* 13   CR*/,
283         14      /* 14   SO*/,
284         15      /* 15   SI*/,
285         16      /* 16   DLE*/,
286         17      /* 17   DC1*/,
287         18      /* 18   DC2*/,
288         19      /* 19   DC3*/,
289         20      /* 20   DC4*/,
290         21      /* 21   NAK*/,
291         22      /* 22   SYN*/,
292         23      /* 23   ETB*/,
293         24      /* 24   CAN*/,
294         25      /* 25   EM*/,
295         26      /* 26   SUB*/,
296         27      /* 27   ESC*/,
297         28      /* 28   FS*/,
298         29      /* 29   GS*/,
299         30      /* 30   RS*/,
300         31      /* 31   US*/,
301         32      /* 32   SP*/,
302         33      /* 33    ! */,
303         34      /* 34    " */,
304         35      /* 35    # */,
305         36      /* 36    $ */,
306         37      /* 37    % */,
307         38      /* 38    & */,
308         39      /* 39    ' */,
309         40      /* 40    ( */,
310         41      /* 41    ) */,
311         42      /* 42    * */,
312         43      /* 43    + */,
313         44      /* 44    , */,
314         45      /* 45    - */,
315         46      /* 46    . */,
316         47      /* 47    / */,
317         48      /* 48    0 */,
318         49      /* 49    1 */,
319         50      /* 50    2 */,
320         51      /* 51    3 */,
321         52      /* 52    4 */,
322         53      /* 53    5 */,
323         54      /* 54    6 */,
324         55      /* 55    7 */,
325         56      /* 56    8 */,
326         57      /* 57    9 */,
327         58      /* 58    : */,
328         59      /* 59    ; */,
329         60      /* 60    < */,
330         61      /* 61    = */,
331         62      /* 62    > */,
332         63      /* 63    ? */,
333         64      /* 64    @ */,
334         97      /* 65    A */,
335         98      /* 66    B */,
336         99      /* 67    C */,
337         100     /* 68    D */,
338         101     /* 69    E */,
339         102     /* 70    F */,
340         103     /* 71    G */,
341         104     /* 72    H */,
342         105     /* 73    I */,
343         106     /* 74    J */,
344         107     /* 75    K */,
345         108     /* 76    L */,
346         109     /* 77    M */,
347         110     /* 78    N */,
348         111     /* 79    O */,
349         112     /* 80    P */,
350         113     /* 81    Q */,
351         114     /* 82    R */,
352         115     /* 83    S */,
353         116     /* 84    T */,
354         117     /* 85    U */,
355         118     /* 86    V */,
356         119     /* 87    W */,
357         120     /* 88    X */,
358         121     /* 89    Y */,
359         122     /* 90    Z */,
360         91      /* 91    [ */,
361         92      /* 92    \ */,
362         93      /* 93    ] */,
363         94      /* 94    ^ */,
364         95      /* 95    _ */,
365         96      /* 96    ` */,
366         97      /* 97    a */,
367         98      /* 98    b */,
368         99      /* 99    c */,
369         100     /* 100   d */,
370         101     /* 101   e */,
371         102     /* 102   f */,
372         103     /* 103   g */,
373         104     /* 104   h */,
374         105     /* 105   i */,
375         106     /* 106   j */,
376         107     /* 107   k */,
377         108     /* 108   l */,
378         109     /* 109   m */,
379         110     /* 110   n */,
380         111     /* 111   o */,
381         112     /* 112   p */,
382         113     /* 113   q */,
383         114     /* 114   r */,
384         115     /* 115   s */,
385         116     /* 116   t */,
386         117     /* 117   u */,
387         118     /* 118   v */,
388         119     /* 119   w */,
389         120     /* 120   x */,
390         121     /* 121   y */,
391         122     /* 122   z */,
392         123     /* 123   { */,
393         124     /* 124   | */,
394         125     /* 125   } */,
395         126     /* 126   ~ */,
396         127     /* 127  DEL*/,
397         138     /* 128  Adieresis*/,
398         140     /* 129  Aring*/,
399         141     /* 130  Ccedilla*/,
400         142     /* 131  Eacute*/,
401         150     /* 132  Ntilda*/,
402         154     /* 133  Odieresis*/,
403         159     /* 134  Udieresis*/,
404         135     /* 135  aacute*/,
405         136     /* 136  agrave*/,
406         137     /* 137  acircumflex*/,
407         138     /* 138  adieresis*/,
408         139     /* 139  atilda*/,
409         140     /* 140  aring*/,
410         141     /* 141  ccedilla*/,
411         142     /* 142  eacute*/,
412         143     /* 143  egrave*/,
413         144     /* 144  ecircumflex*/,
414         145     /* 145  edieresis*/,
415         146     /* 146  iacute*/,
416         147     /* 147  igrave*/,
417         148     /* 148  icircumflex*/,
418         149     /* 149  idieresis*/,
419         132     /* 150  ntilda*/,
420         151     /* 151  oacute*/,
421         152     /* 152  ograve*/,
422         153     /* 153  ocircumflex*/,
423         154     /* 154  odieresis*/,
424         155     /* 155  otilda*/,
425         156     /* 156  uacute*/,
426         157     /* 157  ugrave*/,
427         158     /* 158  ucircumflex*/,
428         159     /* 159  udieresis*/,
429         160     /* 160  daggar*/,
430         161     /* 161  ring*/,
431         162     /* 162  cent*/,
432         163     /* 163  sterling*/,
433         164     /* 164  section*/,
434         165     /* 165  bullet*/,
435         166     /* 166  paragraph*/,
436         167     /* 167  germandbls*/,
437         168     /* 168  registered*/,
438         169     /* 169  copyright*/,
439         170     /* 170  trademark*/,
440         171     /* 171  acute*/,
441         172     /* 172  dieresis*/,
442         173     /* 173  notequal*/,
443         190     /* 174  AE*/,
444         191     /* 175  Oslash*/,
445         176     /* 176  infinity*/,
446         177     /* 177  plusminus*/,
447         178     /* 178  lessequal*/,
448         179     /* 179  greaterequal*/,
449         180     /* 180  yen*/,
450         181     /* 181  mu*/,
451         198     /* 182  delta*/,
452         183     /* 183  Sigma*/,
453         185     /* 184  Pi*/,
454         185     /* 185  pi*/,
455         186     /* 186  intergral*/,
456         187     /* 187  ordfeminine*/,
457         188     /* 188  ordmasculine*/,
458         189     /* 189  Omega*/,
459         190     /* 190  ae*/,
460         191     /* 191  oslash*/,
461         192     /* 192  questiondown*/,
462         193     /* 193  exclamdown*/,
463         194     /* 194  not*/,
464         195     /* 195  radical*/,
465         196     /* 196  florin*/,
466         197     /* 197  aprox*/,
467         198     /* 198  Delta*/,
468         199     /* 199  guillemotleft*/,
469         200     /* 200  guillemotright*/,
470         201     /* 201  ellipsis*/,
471         202     /* 202  */,
472         136     /* 203  Agrave*/,
473         139     /* 204  Atilda*/,
474         155     /* 205  Otilda*/,
475         207     /* 206  OE*/,
476         207     /* 207  oe*/,
477         208     /* 208  endash*/,
478         209     /* 209  emdash*/,
479         210     /* 210  quotedblleft*/,
480         211     /* 211  quotedblright*/,
481         212     /* 212  quoteleft*/,
482         213     /* 213  quoteright*/,
483         214     /* 214  divide*/,
484         215     /* 215  diamond*/,
485         217     /* 216  ydieresis*/,
486         217     /* 217  Ydieresis*/,
487         218     /* 218  fraction*/,
488         219     /* 219  currency*/,
489         220     /* 220  guilsinglleft*/,
490         221     /* 221  guilsinglright*/,
491         222     /* 222  fi*/,
492         223     /* 223  fl*/,
493         224     /* 224  daggardbl*/,
494         225     /* 225  periodcentered*/,
495         226     /* 226  quotesinglbase*/,
496         227     /* 227  quotedblbase*/,
497         228     /* 228  perthousand*/,
498         137     /* 229  Acircumflex*/,
499         144     /* 230  Ecircumflex*/,
500         135     /* 231  Aacute*/,
501         145     /* 232  Edieresis*/,
502         143     /* 233  Egrave*/,
503         146     /* 234  Iaccute*/,
504         148     /* 235  Icircumflex*/,
505         149     /* 236  Idieresis*/,
506         147     /* 237  Igrave*/,
507         151     /* 238  Oacute*/,
508         153     /* 239  Ocircumflex*/,
509         240     /* 240  apple*/,
510         152     /* 241  Ograve*/,
511         156     /* 242  Uacute*/,
512         158     /* 243  Ucircumflex*/,
513         157     /* 244  Ugrave*/,
514         245     /* 245  dotlessi*/,
515         246     /* 246  circumflex*/,
516         247     /* 247  tilda*/,
517         248     /* 248  macron*/,
518         249     /* 249  breve*/,
519         250     /* 250  dotaccent*/,
520         251     /* 251  ring*/,
521         252     /* 252  cedilla*/,
522         253     /* 253  hungarumlaut*/,
523         254     /* 254  ogonek*/,
524         255     /* 255  caron*/,
525 };
526
527 int strdiacasecmp( const char *s1, const char *s2 )
528 {
529     while ( _diacasemap[ (unsigned char) *s1 ] ==
530             _diacasemap[ (unsigned char) *s2++ ] ) {
531         if ( *s1++ == '\0' ) {
532             return( 0 );
533         }
534     }
535     return( _diacasemap[ (unsigned char) *s1 ] -
536             _diacasemap[ (unsigned char) *--s2 ] );
537 }
538
539 int strndiacasecmp( const char *s1, const char *s2, size_t n )
540 {
541     while ( n > 0 &&
542             _diacasemap[ (unsigned char) *s1 ] ==
543             _diacasemap[ (unsigned char) *s2++ ] ) {
544         if ( *s1++ == '\0' ) {
545             return( 0 );
546         }
547         n--;
548     }
549
550     if (n == 0)
551         return 0;
552     return _diacasemap[ (unsigned char) *s1 ] -
553            _diacasemap[ (unsigned char) *--s2 ];
554 }