Replace bogus characters in time zone abbreviations. Return 0 on success, an errno value if a time zone abbreviation is too long. */
| 774 | Return 0 on success, an errno value if a time zone abbreviation is |
| 775 | too long. */ |
| 776 | static int |
| 777 | scrub_abbrs(struct state *sp) |
| 778 | { |
| 779 | int i; |
| 780 | |
| 781 | /* Reject overlong abbreviations. */ |
| 782 | for (i = 0; i < sp->charcnt - (TZNAME_MAXIMUM + 1); ) { |
| 783 | int len = strnlen(&sp->chars[i], TZNAME_MAXIMUM + 1); |
| 784 | if (TZNAME_MAXIMUM < len) |
| 785 | return EOVERFLOW; |
| 786 | i += len + 1; |
| 787 | } |
| 788 | |
| 789 | /* Replace bogus characters. */ |
| 790 | for (i = 0; i < sp->charcnt; ++i) |
| 791 | switch (sp->chars[i]) { |
| 792 | case '\0': |
| 793 | case '+': case '-': case '.': |
| 794 | case '0': case '1': case '2': case '3': case '4': |
| 795 | case '5': case '6': case '7': case '8': case '9': |
| 796 | case ':': |
| 797 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': |
| 798 | case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': |
| 799 | case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': |
| 800 | case 'V': case 'W': case 'X': case 'Y': case 'Z': |
| 801 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': |
| 802 | case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': |
| 803 | case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': |
| 804 | case 'v': case 'w': case 'x': case 'y': case 'z': |
| 805 | break; |
| 806 | |
| 807 | default: |
| 808 | sp->chars[i] = '_'; |
| 809 | break; |
| 810 | } |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | #endif |
| 816 |