46
46
uchar c = *character;
48
if( (c & (uchar)0xC2 /*11000010*/) == (uchar)0xC0 /*11000000*/ ) {
48
if ((c & (uchar)0xC2 /*11000010*/) == (uchar)0xC0 /*11000000*/) {
49
49
uchar nextc = *(character+1);
51
if( (nextc & (uchar)0xC0 /*11000000*/ ) != (uchar)0x80 /*10000000*/ )
51
if ((nextc & (uchar)0xC0 /*11000000*/)
52
!= (uchar)0x80 /*10000000*/)
54
if( (c & (uchar)0x3E /* 00111110 */ ) == (uchar)0 )
56
if( c == (uchar)0xE0 /*11100000*/ &&
57
(nextc & (uchar)0x20 /*00100000*/ ) == (uchar)0)
59
if( c == (uchar)0xF0 /*11110000*/ &&
60
(nextc & (uchar)0x30 /*00110000*/ ) == (uchar)0)
62
if( c == (uchar)0xF8 /*11111000*/ &&
63
(nextc & (uchar)0x38 /*00111000*/ ) == (uchar)0)
65
if( c == (uchar)0xFC /*11111100*/ &&
66
(nextc & (uchar)0x3C /*00111100*/ ) == (uchar)0)
55
if ((c & (uchar)0x3E /* 00111110 */) == (uchar)0)
57
if (c == (uchar)0xE0 /*11100000*/ &&
58
(nextc & (uchar)0x20 /*00100000*/) == (uchar)0)
60
if (c == (uchar)0xF0 /*11110000*/ &&
61
(nextc & (uchar)0x30 /*00110000*/) == (uchar)0)
63
if (c == (uchar)0xF8 /*11111000*/ &&
64
(nextc & (uchar)0x38 /*00111000*/) == (uchar)0)
66
if (c == (uchar)0xFC /*11111100*/ &&
67
(nextc & (uchar)0x3C /*00111100*/) == (uchar)0)
72
#define REJECTLOWCHARS(s,str,descr) \
73
if( (uchar)*s < (uchar)' ' ) { \
73
#define REJECTLOWCHARS(s, str, descr) \
74
if ((uchar)*s < (uchar)' ') { \
75
76
"Character 0x%02hhx not allowed within %s '%s'!\n", \
77
78
return RET_ERROR; \
80
#define REJECTCHARIF(c,s,str,descr) \
81
#define REJECTCHARIF(c, s, str, descr) \
83
84
"Character '%c' not allowed within %s '%s'!\n", \
85
86
return RET_ERROR; \
92
93
bool firstcharacter = true;
94
if( string[0] == '\0' ) {
95
if (string[0] == '\0') {
95
96
/* This is not really ignoreable, as this will lead
96
97
* to paths not normalized, so all checks go wrong */
97
fprintf(stderr,"Source name is not allowed to be emtpy!\n");
98
fprintf(stderr, "Source name is not allowed to be emtpy!\n");
100
if( string[0] == '.' ) {
101
if (string[0] == '.') {
101
102
/* A dot is not only hard to see, it would cause the directory
102
103
* to become /./.bla, which is quite dangerous. */
103
fprintf(stderr,"Source names are not allowed to start with a dot!\n");
105
"Source names are not allowed to start with a dot!\n");
104
106
return RET_ERROR;
107
while( *s != '\0' ) {
108
if( (*s > 'z' || *s < 'a' ) &&
109
(*s > '9' || *s < '0' ) &&
110
if ((*s > 'z' || *s < 'a') &&
111
(*s > '9' || *s < '0') &&
110
112
(firstcharacter ||
111
( *s != '+' && *s != '-' && *s != '.'))) {
112
REJECTLOWCHARS(s,string,"sourcename");
113
REJECTCHARIF( *s == '/', s,string, "sourcename");
114
if( overlongUTF8(s) ) {
113
(*s != '+' && *s != '-' && *s != '.'))) {
114
REJECTLOWCHARS(s, string, "sourcename");
115
REJECTCHARIF (*s == '/', s, string, "sourcename");
116
if (overlongUTF8(s)) {
116
118
"This could contain an overlong UTF8 sequence, rejecting source name '%s'!\n",
118
120
return RET_ERROR;
121
"Not rejecting", "To ignore this", forbiddenchar,
122
"Character 0x%02hhx not allowed in sourcename: '%s'!\n", *s, string) ) {
122
if (!IGNORING_(forbiddenchar,
123
"Character 0x%02hhx not allowed in sourcename: '%s'!\n", *s, string)) {
123
124
return RET_ERROR;
125
if( ISSET(*s,0x80) ) {
127
"Not rejecting", "To ignore this", 8bit,
128
"8bit character in source name: '%s'!\n", string) ) {
126
if (ISSET(*s, 0x80)) {
128
"8bit character in source name: '%s'!\n", string)) {
129
129
return RET_ERROR;
140
140
retvalue properfilename(const char *string) {
143
if( string[0] == '\0' ) {
144
fprintf(stderr,"Error: empty filename!\n");
143
if (string[0] == '\0') {
144
fprintf(stderr, "Error: empty filename!\n");
145
145
return RET_ERROR;
147
if( (string[0] == '.' && string[1] == '\0') ||
148
(string[0] == '.' && string[1] == '.' && string[2] == '\0') ) {
147
if ((string[0] == '.' && string[1] == '\0') ||
148
(string[0] == '.' && string[1] == '.' && string[2] == '\0')) {
149
149
fprintf(stderr, "File name not allowed: '%s'!\n", string);
150
150
return RET_ERROR;
152
for( s = string ; *s != '\0' ; s++ ) {
153
REJECTLOWCHARS(s,string,"filename");
154
REJECTCHARIF( *s == '/' ,s,string,"filename");
155
if( ISSET(*s,0x80) ) {
156
if( overlongUTF8(s) ) {
152
for (s = string ; *s != '\0' ; s++) {
153
REJECTLOWCHARS(s, string, "filename");
154
REJECTCHARIF (*s == '/' , s, string, "filename");
155
if (ISSET(*s, 0x80)) {
156
if (overlongUTF8(s)) {
158
158
"This could contain an overlong UTF8 sequence, rejecting file name '%s'!\n",
160
160
return RET_ERROR;
163
"Not rejecting", "To ignore this", 8bit,
164
"8bit character in file name: '%s'!\n", string)) {
163
"8bit character in file name: '%s'!\n", string)) {
165
164
return RET_ERROR;
187
186
const char *checkfordirectoryandidentifier(const char *string) {
190
assert( string != NULL && string[0] != '\0' );
189
assert (string != NULL && string[0] != '\0');
192
if( (string[0] == '.' && (string[1] == '\0'||string[1]=='/')) )
191
if ((string[0] == '.' && (string[1] == '\0'||string[1]=='/')))
193
192
return "'.' is not allowed as directory part";
194
if( (string[0] == '.' && string[1] == '.' &&
195
(string[2] == '\0'||string[2] =='/')) )
193
if ((string[0] == '.' && string[1] == '.'
194
&& (string[2] == '\0'||string[2] =='/')))
196
195
return "'..' is not allowed as directory part";
197
for( s = string; *s != '\0'; s++ ) {
196
for (s = string; *s != '\0'; s++) {
199
198
return "'|' is not allowed";
200
if( (uchar)*s < (uchar)' ' )
199
if ((uchar)*s < (uchar)' ')
201
200
return formaterror("Character 0x%02hhx not allowed", *s);
202
if( *s == '/' && s[1] == '.' && (s[2] == '\0' || s[2] == '/') )
201
if (*s == '/' && s[1] == '.' && (s[2] == '\0' || s[2] == '/'))
203
202
return "'.' is not allowed as directory part";
204
if( *s == '/' && s[1] == '.' && s[2] == '.' &&
205
(s[3] == '\0' || s[3] =='/'))
203
if (*s == '/' && s[1] == '.' && s[2] == '.'
204
&& (s[3] == '\0' || s[3] =='/'))
206
205
return "'..' is not allowed as directory part";
207
if( *s == '/' && s[1] == '/' )
206
if (*s == '/' && s[1] == '/')
208
207
return "\"//\" is not allowed";
209
if( ISSET(*s,0x80) ) {
210
if( overlongUTF8(s) )
211
return "Contains overlong UTF-8 sequence if treated as UTF-8";
212
if( !IGNORABLE(8bit) )
213
return "Contains 8bit character (use --ignore=8bit to ignore)";
208
if (ISSET(*s, 0x80)) {
211
"Contains overlong UTF-8 sequence if treated as UTF-8";
212
if (!IGNORABLE(8bit))
214
"Contains 8bit character (use --ignore=8bit to ignore)";
220
221
const char *checkforidentifierpart(const char *string) {
223
assert( string != NULL && string[0] != '\0' );
224
assert (string != NULL && string[0] != '\0');
225
for( s = string; *s != '\0' ; s++ ) {
226
for (s = string; *s != '\0' ; s++) {
227
228
return "'|' is not allowed";
229
230
return "'/' is not allowed";
230
if( (uchar)*s < (uchar)' ' )
231
if ((uchar)*s < (uchar)' ')
231
232
return formaterror("Character 0x%02hhx not allowed", *s);
232
if( ISSET(*s,0x80) ) {
233
if( overlongUTF8(s) )
234
return "Contains overlong UTF-8 sequence if treated as UTF-8";
235
if( !IGNORABLE(8bit) )
236
return "Contains 8bit character (use --ignore=8bit to ignore)";
233
if (ISSET(*s, 0x80)) {
236
"Contains overlong UTF-8 sequence if treated as UTF-8";
237
if (!IGNORABLE(8bit))
239
"Contains 8bit character (use --ignore=8bit to ignore)";
242
245
retvalue properfilenamepart(const char *string) {
245
for( s = string ; *s != '\0' ; s++ ) {
246
REJECTLOWCHARS(s,string,"filenamepart");
247
REJECTCHARIF( *s == '/' ,s,string,"filenamepart");
248
if( ISSET(*s,0x80) ) {
249
if( overlongUTF8(s) ) {
248
for (s = string ; *s != '\0' ; s++) {
249
REJECTLOWCHARS(s, string, "filenamepart");
250
REJECTCHARIF (*s == '/' , s, string, "filenamepart");
251
if (ISSET(*s, 0x80)) {
252
if (overlongUTF8(s)) {
251
254
"This could contain an overlong UTF8 sequence, rejecting part of file name '%s'!\n",
253
256
return RET_ERROR;
256
"Not rejecting", "To ignore this", 8bit, "8bit character in part of file name: '%s'!\n",
259
"8bit character in part of file name: '%s'!\n",
258
261
return RET_ERROR;
267
270
bool first = true;
268
271
bool yetonlydigits = true;
270
if( string[0] == '\0' && !IGNORING(
271
"Ignoring","To ignore this",emptyfilenamepart,"A version string is empty!\n") ) {
273
if (string[0] == '\0' && !IGNORING(emptyfilenamepart,
274
"A version string is empty!\n")) {
272
275
return RET_ERROR;
274
if( ( *s < '0' || *s > '9' ) &&
275
(( *s >= 'a' && *s <= 'z') || (*s >='A' && *s <= 'Z'))) {
277
if ((*s < '0' || *s > '9') &&
278
((*s >= 'a' && *s <= 'z') || (*s >='A' && *s <= 'Z'))) {
276
279
/* As there are official packages violating the rule
277
280
* of policy 5.6.11 to start with a digit, disabling
278
281
* this test, and only omitting a warning. */
280
fprintf(stderr,"Warning: Package version '%s' does not start with a digit, violating 'should'-directive in policy 5.6.11\n",string);
284
"Warning: Package version '%s' does not start with a digit, violating 'should'-directive in policy 5.6.11\n",
282
for( ; *s != '\0' ; s++,first=false ) {
283
if( (*s <= '9' || *s >= '0' ) ) {
287
for (; *s != '\0' ; s++, first=false) {
288
if ((*s <= '9' || *s >= '0')) {
286
if( !first && yetonlydigits && *s == ':' ) {
291
if (!first && yetonlydigits && *s == ':') {
290
295
yetonlydigits = false;
291
if( (*s >= 'A' && *s <= 'Z' ) ||
292
(*s >= 'a' || *s <= 'z' )) {
296
if ((*s >= 'A' && *s <= 'Z') ||
297
(*s >= 'a' || *s <= 'z')) {
293
298
yetonlydigits = false;
296
if( first || (*s != '+' && *s != '-' &&
297
*s != '.' && *s != '~' &&
298
(!hadepoch || *s != ':' ))) {
299
REJECTLOWCHARS(s,string,"version");
300
REJECTCHARIF( *s == '/' ,s,string,"version");
301
if( overlongUTF8(s) ) {
301
if (first || (*s != '+' && *s != '-'
302
&& *s != '.' && *s != '~'
303
&& (!hadepoch || *s != ':'))) {
304
REJECTLOWCHARS(s, string, "version");
305
REJECTCHARIF (*s == '/' , s, string, "version");
306
if (overlongUTF8(s)) {
303
308
"This could contain an overlong UTF8 sequence, rejecting version '%s'!\n",
305
310
return RET_ERROR;
308
"Not rejecting", "To ignore this", forbiddenchar,
309
"Character '%c' not allowed in version: '%s'!\n", *s, string) )
312
if (!IGNORING_(forbiddenchar,
313
"Character '%c' not allowed in version: '%s'!\n", *s, string))
310
314
return RET_ERROR;
311
if( ISSET(*s,0x80) ) {
313
"Not rejecting", "To ignore this", 8bit,
314
"8bit character in version: '%s'!\n", string) )
315
if (ISSET(*s, 0x80)) {
317
"8bit character in version: '%s'!\n", string))
315
318
return RET_ERROR;
338
341
/* To be able to avoid multiple warnings,
339
342
* this should always be a subset of propersourcename */
341
if( string[0] == '\0' ) {
344
if (string[0] == '\0') {
342
345
/* This is not really ignoreable, as this is a primary
343
346
* key for our database */
344
fprintf(stderr,"Package name is not allowed to be emtpy!\n");
347
fprintf(stderr, "Package name is not allowed to be emtpy!\n");
345
348
return RET_ERROR;
348
while( *s != '\0' ) {
349
352
/* DAK also allowed upper case letters last I looked, policy
350
353
* does not, so they are not allowed without --ignore=forbiddenchar */
351
354
// perhaps some extra ignore-rule for upper case?
352
if( (*s > 'z' || *s < 'a' ) &&
353
(*s > '9' || *s < '0' ) &&
355
(*s != '+' && *s != '-' && *s != '.'))) {
356
REJECTLOWCHARS(s,string,"package name");
357
REJECTCHARIF( *s == '/' ,s,string,"package name");
358
if( overlongUTF8(s) ) {
355
if ((*s > 'z' || *s < 'a') &&
356
(*s > '9' || *s < '0') &&
358
|| (*s != '+' && *s != '-' && *s != '.'))) {
359
REJECTLOWCHARS(s, string, "package name");
360
REJECTCHARIF (*s == '/' , s, string, "package name");
361
if (overlongUTF8(s)) {
360
363
"This could contain an overlong UTF8 sequence, rejecting package name '%s'!\n",
362
365
return RET_ERROR;
365
"Not rejecting", "To ignore this", forbiddenchar,
366
"Character 0x%02hhx not allowed in package name: '%s'!\n", *s, string) ) {
367
if (!IGNORING(forbiddenchar,
368
"Character 0x%02hhx not allowed in package name: '%s'!\n", *s, string)) {
367
369
return RET_ERROR;
369
if( ISSET(*s,0x80) ) {
371
"Not rejecting","To ignore this",8bit,"8bit character in package name: '%s'!\n",string) ) {
371
if (ISSET(*s, 0x80)) {
373
"8bit character in package name: '%s'!\n", string)) {
372
374
return RET_ERROR;