clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name uidna.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D V8_DEPRECATION_WARNINGS -D V8_IMMINENT_DEPRECATION_WARNINGS -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D U_COMMON_IMPLEMENTATION=1 -D U_ATTRIBUTE_DEPRECATED= -D _CRT_SECURE_NO_DEPRECATE= -D U_STATIC_IMPLEMENTATION=1 -D UCONFIG_NO_SERVICE=1 -D U_ENABLE_DYLOAD=0 -D U_HAVE_STD_STRING=1 -D UCONFIG_NO_BREAK_ITERATION=0 -I ../deps/icu-small/source/common -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-deprecated-declarations -Wno-strict-aliasing -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c++ ../deps/icu-small/source/common/uidna.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | #include "unicode/utypes.h" |
20 | |
21 | #if !UCONFIG_NO_IDNA |
22 | |
23 | #include "unicode/uidna.h" |
24 | #include "unicode/ustring.h" |
25 | #include "unicode/usprep.h" |
26 | #include "punycode.h" |
27 | #include "ustr_imp.h" |
28 | #include "cmemory.h" |
29 | #include "uassert.h" |
30 | #include "sprpimpl.h" |
31 | |
32 | |
33 | static const UChar ACE_PREFIX[] ={ 0x0078,0x006E,0x002d,0x002d } ; |
34 | #define ACE_PREFIX_LENGTH 4 |
35 | |
36 | #define MAX_LABEL_LENGTH 63 |
37 | |
38 | #define MAX_LABEL_BUFFER_SIZE 100 |
39 | |
40 | #define MAX_DOMAIN_NAME_LENGTH 255 |
41 | |
42 | #define MAX_IDN_BUFFER_SIZE MAX_DOMAIN_NAME_LENGTH+1 |
43 | |
44 | #define LOWER_CASE_DELTA 0x0020 |
45 | #define HYPHEN 0x002D |
46 | #define FULL_STOP 0x002E |
47 | #define CAPITAL_A 0x0041 |
48 | #define CAPITAL_Z 0x005A |
49 | |
50 | inline static UChar |
51 | toASCIILower(UChar ch){ |
52 | if(CAPITAL_A <= ch && ch <= CAPITAL_Z){ |
53 | return ch + LOWER_CASE_DELTA; |
54 | } |
55 | return ch; |
56 | } |
57 | |
58 | inline static UBool |
59 | startsWithPrefix(const UChar* src , int32_t srcLength){ |
60 | if(srcLength < ACE_PREFIX_LENGTH){ |
61 | return FALSE; |
62 | } |
63 | |
64 | for(int8_t i=0; i< ACE_PREFIX_LENGTH; i++){ |
65 | if(toASCIILower(src[i]) != ACE_PREFIX[i]){ |
66 | return FALSE; |
67 | } |
68 | } |
69 | return TRUE; |
70 | } |
71 | |
72 | |
73 | inline static int32_t |
74 | compareCaseInsensitiveASCII(const UChar* s1, int32_t s1Len, |
75 | const UChar* s2, int32_t s2Len){ |
76 | |
77 | int32_t minLength; |
78 | int32_t lengthResult; |
79 | |
80 | |
81 | if(s1Len != s2Len) { |
| 11 | | Assuming 's1Len' is not equal to 's2Len' | |
|
| |
82 | if(s1Len < s2Len) { |
| 13 | | Assuming 's1Len' is < 's2Len' | |
|
| |
83 | minLength = s1Len; |
84 | lengthResult = -1; |
85 | } else { |
86 | minLength = s2Len; |
87 | lengthResult = 1; |
88 | } |
89 | } else { |
90 | |
91 | minLength = s1Len; |
92 | lengthResult = 0; |
93 | } |
94 | |
95 | UChar c1,c2; |
96 | int32_t rc; |
97 | |
98 | for(int32_t i =0;;i++) { |
| |
| 16 | | Loop condition is true. Entering loop body | |
|
99 | |
100 | |
101 | if(i == minLength) { |
| |
102 | return lengthResult; |
103 | } |
104 | |
105 | c1 = s1[i]; |
106 | c2 = s2[i]; |
| 18 | | Assigned value is garbage or undefined |
|
107 | |
108 | |
109 | if(c1!=c2) { |
110 | rc=(int32_t)toASCIILower(c1)-(int32_t)toASCIILower(c2); |
111 | if(rc!=0) { |
112 | lengthResult=rc; |
113 | break; |
114 | } |
115 | } |
116 | } |
117 | return lengthResult; |
118 | } |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | static inline UBool isLabelSeparator(UChar ch){ |
130 | switch(ch){ |
131 | case 0x002e: |
132 | case 0x3002: |
133 | case 0xFF0E: |
134 | case 0xFF61: |
135 | return TRUE; |
136 | default: |
137 | return FALSE; |
138 | } |
139 | } |
140 | |
141 | |
142 | |
143 | |
144 | static inline int32_t |
145 | getNextSeparator(UChar *src, int32_t srcLength, |
146 | UChar **limit, UBool *done){ |
147 | if(srcLength == -1){ |
148 | int32_t i; |
149 | for(i=0 ; ;i++){ |
150 | if(src[i] == 0){ |
151 | *limit = src + i; |
152 | *done = TRUE; |
153 | return i; |
154 | } |
155 | if(isLabelSeparator(src[i])){ |
156 | *limit = src + (i+1); |
157 | return i; |
158 | |
159 | } |
160 | } |
161 | }else{ |
162 | int32_t i; |
163 | for(i=0;i<srcLength;i++){ |
164 | if(isLabelSeparator(src[i])){ |
165 | *limit = src + (i+1); |
166 | return i; |
167 | } |
168 | } |
169 | |
170 | |
171 | *limit = src+srcLength; |
172 | *done = TRUE; |
173 | |
174 | return i; |
175 | } |
176 | } |
177 | static inline UBool isLDHChar(UChar ch){ |
178 | |
179 | if(ch>0x007A){ |
180 | return FALSE; |
181 | } |
182 | |
183 | if( (ch==0x002D) || |
184 | (0x0030 <= ch && ch <= 0x0039) || |
185 | (0x0041 <= ch && ch <= 0x005A) || |
186 | (0x0061 <= ch && ch <= 0x007A) |
187 | ){ |
188 | return TRUE; |
189 | } |
190 | return FALSE; |
191 | } |
192 | |
193 | static int32_t |
194 | _internal_toASCII(const UChar* src, int32_t srcLength, |
195 | UChar* dest, int32_t destCapacity, |
196 | int32_t options, |
197 | UStringPrepProfile* nameprep, |
198 | UParseError* parseError, |
199 | UErrorCode* status) |
200 | { |
201 | |
202 | |
203 | UChar b1Stack[MAX_LABEL_BUFFER_SIZE], b2Stack[MAX_LABEL_BUFFER_SIZE]; |
204 | |
205 | UChar *b1 = b1Stack, *b2 = b2Stack; |
206 | int32_t b1Len=0, b2Len, |
207 | b1Capacity = MAX_LABEL_BUFFER_SIZE, |
208 | b2Capacity = MAX_LABEL_BUFFER_SIZE , |
209 | reqLength=0; |
210 | |
211 | int32_t namePrepOptions = ((options & UIDNA_ALLOW_UNASSIGNED) != 0) ? USPREP_ALLOW_UNASSIGNED: 0; |
212 | UBool* caseFlags = NULL; |
213 | |
214 | |
215 | UBool srcIsASCII = TRUE; |
216 | |
217 | UBool srcIsLDH = TRUE; |
218 | |
219 | int32_t j=0; |
220 | |
221 | |
222 | UBool useSTD3ASCIIRules = (UBool)((options & UIDNA_USE_STD3_RULES) != 0); |
223 | |
224 | int32_t failPos = -1; |
225 | |
226 | if(srcLength == -1){ |
227 | srcLength = u_strlen(src); |
228 | } |
229 | |
230 | if(srcLength > b1Capacity){ |
231 | b1 = (UChar*) uprv_malloc(srcLength * U_SIZEOF_UCHAR); |
232 | if(b1==NULL){ |
233 | *status = U_MEMORY_ALLOCATION_ERROR; |
234 | goto CLEANUP; |
235 | } |
236 | b1Capacity = srcLength; |
237 | } |
238 | |
239 | |
240 | for( j=0;j<srcLength;j++){ |
241 | if(src[j] > 0x7F){ |
242 | srcIsASCII = FALSE; |
243 | } |
244 | b1[b1Len++] = src[j]; |
245 | } |
246 | |
247 | |
248 | if(srcIsASCII == FALSE){ |
249 | |
250 | |
251 | b1Len = usprep_prepare(nameprep, src, srcLength, b1, b1Capacity, namePrepOptions, parseError, status); |
252 | |
253 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
254 | |
255 | |
256 | if(b1 != b1Stack){ |
257 | uprv_free(b1); |
258 | } |
259 | b1 = (UChar*) uprv_malloc(b1Len * U_SIZEOF_UCHAR); |
260 | if(b1==NULL){ |
261 | *status = U_MEMORY_ALLOCATION_ERROR; |
262 | goto CLEANUP; |
263 | } |
264 | |
265 | *status = U_ZERO_ERROR; |
266 | |
267 | b1Len = usprep_prepare(nameprep, src, srcLength, b1, b1Len, namePrepOptions, parseError, status); |
268 | } |
269 | } |
270 | |
271 | if(U_FAILURE(*status)){ |
272 | goto CLEANUP; |
273 | } |
274 | if(b1Len == 0){ |
275 | *status = U_IDNA_ZERO_LENGTH_LABEL_ERROR; |
276 | goto CLEANUP; |
277 | } |
278 | |
279 | |
280 | srcIsASCII = TRUE; |
281 | for( j=0;j<b1Len;j++){ |
282 | |
283 | if(b1[j] > 0x7F){ |
284 | srcIsASCII = FALSE; |
285 | }else if(isLDHChar(b1[j])==FALSE){ |
286 | srcIsLDH = FALSE; |
287 | failPos = j; |
288 | } |
289 | } |
290 | if(useSTD3ASCIIRules == TRUE){ |
291 | |
292 | |
293 | |
294 | |
295 | |
296 | |
297 | if( srcIsLDH == FALSE |
298 | || b1[0] == HYPHEN || b1[b1Len-1] == HYPHEN){ |
299 | *status = U_IDNA_STD3_ASCII_RULES_ERROR; |
300 | |
301 | |
302 | if(srcIsLDH==FALSE){ |
303 | |
304 | uprv_syntaxError(b1,failPos, b1Len,parseError); |
305 | }else if(b1[0] == HYPHEN){ |
306 | |
307 | uprv_syntaxError(b1,0,b1Len,parseError); |
308 | }else{ |
309 | |
310 | uprv_syntaxError(b1, (b1Len>0) ? b1Len-1 : b1Len, b1Len,parseError); |
311 | } |
312 | |
313 | goto CLEANUP; |
314 | } |
315 | } |
316 | |
317 | if(srcIsASCII){ |
318 | if(b1Len <= destCapacity){ |
319 | u_memmove(dest, b1, b1Len); |
320 | reqLength = b1Len; |
321 | }else{ |
322 | reqLength = b1Len; |
323 | goto CLEANUP; |
324 | } |
325 | }else{ |
326 | |
327 | if(!startsWithPrefix(b1,b1Len)){ |
328 | |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | |
335 | |
336 | b2Len = u_strToPunycode(b1,b1Len,b2,b2Capacity,caseFlags, status); |
337 | |
338 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
339 | |
340 | |
341 | b2 = (UChar*) uprv_malloc(b2Len * U_SIZEOF_UCHAR); |
342 | if(b2 == NULL){ |
343 | *status = U_MEMORY_ALLOCATION_ERROR; |
344 | goto CLEANUP; |
345 | } |
346 | |
347 | *status = U_ZERO_ERROR; |
348 | |
349 | b2Len = u_strToPunycode(b1,b1Len,b2,b2Len,caseFlags, status); |
350 | } |
351 | |
352 | if(U_FAILURE(*status)){ |
353 | goto CLEANUP; |
354 | } |
355 | |
356 | |
357 | |
358 | reqLength = b2Len+ACE_PREFIX_LENGTH; |
359 | |
360 | if(reqLength > destCapacity){ |
361 | *status = U_BUFFER_OVERFLOW_ERROR; |
362 | goto CLEANUP; |
363 | } |
364 | |
365 | u_memcpy(dest, ACE_PREFIX, ACE_PREFIX_LENGTH); |
366 | |
367 | u_memcpy(dest+ACE_PREFIX_LENGTH, b2, b2Len); |
368 | |
369 | }else{ |
370 | *status = U_IDNA_ACE_PREFIX_ERROR; |
371 | |
372 | uprv_syntaxError(b1,0,b1Len,parseError); |
373 | goto CLEANUP; |
374 | } |
375 | } |
376 | |
377 | if(reqLength > MAX_LABEL_LENGTH){ |
378 | *status = U_IDNA_LABEL_TOO_LONG_ERROR; |
379 | } |
380 | |
381 | CLEANUP: |
382 | if(b1 != b1Stack){ |
383 | uprv_free(b1); |
384 | } |
385 | if(b2 != b2Stack){ |
386 | uprv_free(b2); |
387 | } |
388 | uprv_free(caseFlags); |
389 | |
390 | return u_terminateUChars(dest, destCapacity, reqLength, status); |
391 | } |
392 | |
393 | static int32_t |
394 | _internal_toUnicode(const UChar* src, int32_t srcLength, |
395 | UChar* dest, int32_t destCapacity, |
396 | int32_t options, |
397 | UStringPrepProfile* nameprep, |
398 | UParseError* parseError, |
399 | UErrorCode* status) |
400 | { |
401 | |
402 | |
403 | |
404 | int32_t namePrepOptions = ((options & UIDNA_ALLOW_UNASSIGNED) != 0) ? USPREP_ALLOW_UNASSIGNED: 0; |
405 | |
406 | |
407 | UChar b1Stack[MAX_LABEL_BUFFER_SIZE], b2Stack[MAX_LABEL_BUFFER_SIZE], b3Stack[MAX_LABEL_BUFFER_SIZE]; |
408 | |
409 | |
410 | UChar *b1 = b1Stack, *b2 = b2Stack, *b1Prime=NULL, *b3=b3Stack; |
411 | int32_t b1Len = 0, b2Len, b1PrimeLen, b3Len, |
412 | b1Capacity = MAX_LABEL_BUFFER_SIZE, |
413 | b2Capacity = MAX_LABEL_BUFFER_SIZE, |
414 | b3Capacity = MAX_LABEL_BUFFER_SIZE, |
415 | reqLength=0; |
416 | |
417 | UBool* caseFlags = NULL; |
418 | |
419 | UBool srcIsASCII = TRUE; |
420 | |
421 | |
422 | |
423 | |
424 | if(srcLength==-1){ |
425 | srcLength = 0; |
426 | for(;src[srcLength]!=0;){ |
427 | if(src[srcLength]> 0x7f){ |
428 | srcIsASCII = FALSE; |
429 | } |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | srcLength++; |
437 | } |
438 | }else if(srcLength > 0){ |
439 | for(int32_t j=0; j<srcLength; j++){ |
440 | if(src[j]> 0x7f){ |
441 | srcIsASCII = FALSE; |
442 | break; |
443 | } |
444 | |
445 | |
446 | |
447 | |
448 | |
449 | |
450 | } |
451 | }else{ |
452 | return 0; |
453 | } |
454 | |
455 | if(srcIsASCII == FALSE){ |
456 | |
457 | b1Len = usprep_prepare(nameprep, src, srcLength, b1, b1Capacity, namePrepOptions, parseError, status); |
458 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
459 | |
460 | |
461 | b1 = (UChar*) uprv_malloc(b1Len * U_SIZEOF_UCHAR); |
462 | if(b1==NULL){ |
463 | *status = U_MEMORY_ALLOCATION_ERROR; |
464 | goto CLEANUP; |
465 | } |
466 | |
467 | *status = U_ZERO_ERROR; |
468 | |
469 | b1Len = usprep_prepare(nameprep, src, srcLength, b1, b1Len, namePrepOptions, parseError, status); |
470 | } |
471 | |
472 | if(U_FAILURE(*status)){ |
473 | goto CLEANUP; |
474 | } |
475 | }else{ |
476 | |
477 | |
478 | b1 = (UChar*) src; |
479 | b1Len = srcLength; |
480 | } |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 | |
488 | |
489 | if(startsWithPrefix(b1,b1Len)){ |
490 | |
491 | |
492 | b1Prime = b1 + ACE_PREFIX_LENGTH; |
493 | b1PrimeLen = b1Len - ACE_PREFIX_LENGTH; |
494 | |
495 | |
496 | b2Len = u_strFromPunycode(b1Prime, b1PrimeLen, b2, b2Capacity, caseFlags,status); |
497 | |
498 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
499 | |
500 | |
501 | b2 = (UChar*) uprv_malloc(b2Len * U_SIZEOF_UCHAR); |
502 | if(b2==NULL){ |
503 | *status = U_MEMORY_ALLOCATION_ERROR; |
504 | goto CLEANUP; |
505 | } |
506 | |
507 | *status = U_ZERO_ERROR; |
508 | |
509 | b2Len = u_strFromPunycode(b1Prime, b1PrimeLen, b2, b2Len, caseFlags, status); |
510 | } |
511 | |
512 | |
513 | |
514 | b3Len = uidna_toASCII(b2, b2Len, b3, b3Capacity, options, parseError, status); |
515 | |
516 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
517 | |
518 | |
519 | b3 = (UChar*) uprv_malloc(b3Len * U_SIZEOF_UCHAR); |
520 | if(b3==NULL){ |
521 | *status = U_MEMORY_ALLOCATION_ERROR; |
522 | goto CLEANUP; |
523 | } |
524 | |
525 | *status = U_ZERO_ERROR; |
526 | |
527 | b3Len = uidna_toASCII(b2,b2Len,b3,b3Len,options,parseError, status); |
528 | |
529 | } |
530 | |
531 | if(U_FAILURE(*status)){ |
532 | goto CLEANUP; |
533 | } |
534 | |
535 | |
536 | if(compareCaseInsensitiveASCII(b1, b1Len, b3, b3Len) !=0){ |
537 | |
538 | *status = U_IDNA_VERIFICATION_ERROR; |
539 | goto CLEANUP; |
540 | } |
541 | |
542 | |
543 | reqLength = b2Len; |
544 | if(b2Len <= destCapacity) { |
545 | u_memmove(dest, b2, b2Len); |
546 | } |
547 | } |
548 | else{ |
549 | |
550 | |
551 | |
552 | |
553 | |
554 | |
555 | |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | |
568 | |
569 | |
570 | |
571 | |
572 | |
573 | if(srcLength <= destCapacity){ |
574 | u_memmove(dest, src, srcLength); |
575 | } |
576 | reqLength = srcLength; |
577 | } |
578 | |
579 | |
580 | CLEANUP: |
581 | |
582 | if(b1 != b1Stack && b1!=src){ |
583 | uprv_free(b1); |
584 | } |
585 | if(b2 != b2Stack){ |
586 | uprv_free(b2); |
587 | } |
588 | uprv_free(caseFlags); |
589 | |
590 | |
591 | |
592 | |
593 | |
594 | |
595 | |
596 | if(U_FAILURE(*status)){ |
597 | |
598 | if(dest && srcLength <= destCapacity){ |
599 | |
600 | U_ASSERT(srcLength >= 0); |
601 | u_memmove(dest, src, srcLength); |
602 | } |
603 | reqLength = srcLength; |
604 | *status = U_ZERO_ERROR; |
605 | } |
606 | |
607 | return u_terminateUChars(dest, destCapacity, reqLength, status); |
608 | } |
609 | |
610 | U_CAPI int32_t U_EXPORT2 |
611 | uidna_toASCII(const UChar* src, int32_t srcLength, |
612 | UChar* dest, int32_t destCapacity, |
613 | int32_t options, |
614 | UParseError* parseError, |
615 | UErrorCode* status){ |
616 | |
617 | if(status == NULL || U_FAILURE(*status)){ |
618 | return 0; |
619 | } |
620 | if((src==NULL) || (srcLength < -1) || (destCapacity<0) || (!dest && destCapacity > 0)){ |
621 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
622 | return 0; |
623 | } |
624 | |
625 | UStringPrepProfile* nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, status); |
626 | |
627 | if(U_FAILURE(*status)){ |
628 | return -1; |
629 | } |
630 | |
631 | int32_t retLen = _internal_toASCII(src, srcLength, dest, destCapacity, options, nameprep, parseError, status); |
632 | |
633 | |
634 | usprep_close(nameprep); |
635 | |
636 | return retLen; |
637 | } |
638 | |
639 | U_CAPI int32_t U_EXPORT2 |
640 | uidna_toUnicode(const UChar* src, int32_t srcLength, |
641 | UChar* dest, int32_t destCapacity, |
642 | int32_t options, |
643 | UParseError* parseError, |
644 | UErrorCode* status){ |
645 | |
646 | if(status == NULL || U_FAILURE(*status)){ |
647 | return 0; |
648 | } |
649 | if( (src==NULL) || (srcLength < -1) || (destCapacity<0) || (!dest && destCapacity > 0)){ |
650 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
651 | return 0; |
652 | } |
653 | |
654 | UStringPrepProfile* nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, status); |
655 | |
656 | if(U_FAILURE(*status)){ |
657 | return -1; |
658 | } |
659 | |
660 | int32_t retLen = _internal_toUnicode(src, srcLength, dest, destCapacity, options, nameprep, parseError, status); |
661 | |
662 | usprep_close(nameprep); |
663 | |
664 | return retLen; |
665 | } |
666 | |
667 | |
668 | U_CAPI int32_t U_EXPORT2 |
669 | uidna_IDNToASCII( const UChar *src, int32_t srcLength, |
670 | UChar* dest, int32_t destCapacity, |
671 | int32_t options, |
672 | UParseError *parseError, |
673 | UErrorCode *status){ |
674 | |
675 | if(status == NULL || U_FAILURE(*status)){ |
| |
676 | return 0; |
| 7 | | Returning without writing to '*dest' | |
|
677 | } |
678 | if((src==NULL) || (srcLength < -1) || (destCapacity<0) || (!dest && destCapacity > 0)){ |
679 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
680 | return 0; |
681 | } |
682 | |
683 | int32_t reqLength = 0; |
684 | |
685 | UStringPrepProfile* nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, status); |
686 | |
687 | if(U_FAILURE(*status)){ |
688 | return 0; |
689 | } |
690 | |
691 | |
692 | UChar *delimiter = (UChar*)src; |
693 | UChar *labelStart = (UChar*)src; |
694 | UChar *currentDest = (UChar*) dest; |
695 | int32_t remainingLen = srcLength; |
696 | int32_t remainingDestCapacity = destCapacity; |
697 | int32_t labelLen = 0, labelReqLength = 0; |
698 | UBool done = FALSE; |
699 | |
700 | |
701 | for(;;){ |
702 | |
703 | labelLen = getNextSeparator(labelStart,remainingLen, &delimiter,&done); |
704 | labelReqLength = 0; |
705 | if(!(labelLen==0 && done)){ |
706 | |
707 | labelReqLength = _internal_toASCII( labelStart, labelLen, |
708 | currentDest, remainingDestCapacity, |
709 | options, nameprep, |
710 | parseError, status); |
711 | |
712 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
713 | |
714 | *status = U_ZERO_ERROR; |
715 | remainingDestCapacity = 0; |
716 | } |
717 | } |
718 | |
719 | |
720 | if(U_FAILURE(*status)){ |
721 | break; |
722 | } |
723 | |
724 | reqLength +=labelReqLength; |
725 | |
726 | if(labelReqLength < remainingDestCapacity){ |
727 | currentDest = currentDest + labelReqLength; |
728 | remainingDestCapacity -= labelReqLength; |
729 | }else{ |
730 | |
731 | remainingDestCapacity = 0; |
732 | } |
733 | |
734 | if(done == TRUE){ |
735 | break; |
736 | } |
737 | |
738 | |
739 | if(remainingDestCapacity > 0){ |
740 | *currentDest++ = FULL_STOP; |
741 | remainingDestCapacity--; |
742 | } |
743 | reqLength++; |
744 | |
745 | labelStart = delimiter; |
746 | if(remainingLen >0 ){ |
747 | remainingLen = (int32_t)(srcLength - (delimiter - src)); |
748 | } |
749 | |
750 | } |
751 | |
752 | if(reqLength > MAX_DOMAIN_NAME_LENGTH){ |
753 | *status = U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR; |
754 | } |
755 | |
756 | usprep_close(nameprep); |
757 | |
758 | return u_terminateUChars(dest, destCapacity, reqLength, status); |
759 | } |
760 | |
761 | U_CAPI int32_t U_EXPORT2 |
762 | uidna_IDNToUnicode( const UChar* src, int32_t srcLength, |
763 | UChar* dest, int32_t destCapacity, |
764 | int32_t options, |
765 | UParseError* parseError, |
766 | UErrorCode* status){ |
767 | |
768 | if(status == NULL || U_FAILURE(*status)){ |
769 | return 0; |
770 | } |
771 | if((src==NULL) || (srcLength < -1) || (destCapacity<0) || (!dest && destCapacity > 0)){ |
772 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
773 | return 0; |
774 | } |
775 | |
776 | int32_t reqLength = 0; |
777 | |
778 | UStringPrepProfile* nameprep = usprep_openByType(USPREP_RFC3491_NAMEPREP, status); |
779 | |
780 | if(U_FAILURE(*status)){ |
781 | return 0; |
782 | } |
783 | |
784 | |
785 | UChar *delimiter = (UChar*)src; |
786 | UChar *labelStart = (UChar*)src; |
787 | UChar *currentDest = (UChar*) dest; |
788 | int32_t remainingLen = srcLength; |
789 | int32_t remainingDestCapacity = destCapacity; |
790 | int32_t labelLen = 0, labelReqLength = 0; |
791 | UBool done = FALSE; |
792 | |
793 | for(;;){ |
794 | |
795 | labelLen = getNextSeparator(labelStart,remainingLen, &delimiter,&done); |
796 | |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | |
803 | |
804 | |
805 | |
806 | |
807 | |
808 | labelReqLength = _internal_toUnicode(labelStart, labelLen, |
809 | currentDest, remainingDestCapacity, |
810 | options, nameprep, |
811 | parseError, status); |
812 | |
813 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
814 | *status = U_ZERO_ERROR; |
815 | remainingDestCapacity = 0; |
816 | } |
817 | |
818 | if(U_FAILURE(*status)){ |
819 | break; |
820 | } |
821 | |
822 | reqLength +=labelReqLength; |
823 | |
824 | if(labelReqLength < remainingDestCapacity){ |
825 | currentDest = currentDest + labelReqLength; |
826 | remainingDestCapacity -= labelReqLength; |
827 | }else{ |
828 | |
829 | remainingDestCapacity = 0; |
830 | } |
831 | |
832 | if(done == TRUE){ |
833 | break; |
834 | } |
835 | |
836 | |
837 | |
838 | if(remainingDestCapacity > 0){ |
839 | *currentDest++ = *(labelStart + labelLen); |
840 | remainingDestCapacity--; |
841 | } |
842 | reqLength++; |
843 | |
844 | labelStart = delimiter; |
845 | if(remainingLen >0 ){ |
846 | remainingLen = (int32_t)(srcLength - (delimiter - src)); |
847 | } |
848 | |
849 | } |
850 | |
851 | if(reqLength > MAX_DOMAIN_NAME_LENGTH){ |
852 | *status = U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR; |
853 | } |
854 | |
855 | usprep_close(nameprep); |
856 | |
857 | return u_terminateUChars(dest, destCapacity, reqLength, status); |
858 | } |
859 | |
860 | U_CAPI int32_t U_EXPORT2 |
861 | uidna_compare( const UChar *s1, int32_t length1, |
862 | const UChar *s2, int32_t length2, |
863 | int32_t options, |
864 | UErrorCode* status){ |
865 | |
866 | if(status == NULL || U_FAILURE(*status)){ |
| 1 | Assuming 'status' is not equal to NULL | |
|
| |
867 | return -1; |
868 | } |
869 | |
870 | UChar b1Stack[MAX_IDN_BUFFER_SIZE], b2Stack[MAX_IDN_BUFFER_SIZE]; |
871 | UChar *b1 = b1Stack, *b2 = b2Stack; |
872 | int32_t b1Len, b2Len, b1Capacity = MAX_IDN_BUFFER_SIZE, b2Capacity = MAX_IDN_BUFFER_SIZE; |
873 | int32_t result=-1; |
874 | |
875 | UParseError parseError; |
876 | |
877 | b1Len = uidna_IDNToASCII(s1, length1, b1, b1Capacity, options, &parseError, status); |
878 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
| 3 | | Assuming the condition is false | |
|
| |
879 | |
880 | b1 = (UChar*) uprv_malloc(b1Len * U_SIZEOF_UCHAR); |
881 | if(b1==NULL){ |
882 | *status = U_MEMORY_ALLOCATION_ERROR; |
883 | goto CLEANUP; |
884 | } |
885 | |
886 | *status = U_ZERO_ERROR; |
887 | |
888 | b1Len = uidna_IDNToASCII(s1,length1,b1,b1Len, options, &parseError, status); |
889 | |
890 | } |
891 | |
892 | b2Len = uidna_IDNToASCII(s2,length2, b2,b2Capacity, options, &parseError, status); |
| 5 | | Calling 'uidna_IDNToASCII_71' | |
|
| 8 | | Returning from 'uidna_IDNToASCII_71' | |
|
893 | if(*status == U_BUFFER_OVERFLOW_ERROR){ |
| |
894 | |
895 | b2 = (UChar*) uprv_malloc(b2Len * U_SIZEOF_UCHAR); |
896 | if(b2==NULL){ |
897 | *status = U_MEMORY_ALLOCATION_ERROR; |
898 | goto CLEANUP; |
899 | } |
900 | |
901 | *status = U_ZERO_ERROR; |
902 | |
903 | b2Len = uidna_IDNToASCII(s2, length2, b2, b2Len, options, &parseError, status); |
904 | |
905 | } |
906 | |
907 | result = compareCaseInsensitiveASCII(b1,b1Len,b2,b2Len); |
| 10 | | Calling 'compareCaseInsensitiveASCII' | |
|
908 | |
909 | CLEANUP: |
910 | if(b1 != b1Stack){ |
911 | uprv_free(b1); |
912 | } |
913 | |
914 | if(b2 != b2Stack){ |
915 | uprv_free(b2); |
916 | } |
917 | |
918 | return result; |
919 | } |
920 | |
921 | #endif /* #if !UCONFIG_NO_IDNA */ |