Changes in / [b6061f8c:c7c6afd] in mainline


Ignore:
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • common/stdc/uchar.c

    rb6061f8c rc7c6afd  
    8484}
    8585
    86 static bool _is_non_shortest(unsigned short cont, uint8_t b)
    87 {
    88         return (cont == 0b1111110000000000 && !(b & 0b00100000)) ||
    89             (cont == 0b1111111111110000 && !(b & 0b00110000));
    90 }
    91 
    9286size_t mbrtoc32(char32_t *c, const char *s, size_t n, mbstate_t *mb)
    9387{
     
    145139
    146140                if (_is_2_byte(b)) {
    147                         /* Reject non-shortest form. */
    148                         if (!(b & 0b00011110)) {
    149                                 _set_ilseq();
    150                                 return UCHAR_ILSEQ;
    151                         }
    152 
    153141                        /* 2 byte encoding               110xxxxx */
    154142                        mb->continuation = b ^ 0b0000000011000000;
     
    164152        }
    165153
    166         for (; i < n; i++) {
     154        while (i < n) {
    167155                /* Read continuation bytes. */
    168                 uint8_t b = s[i];
    169 
    170                 if (!_is_continuation(b) || _is_non_shortest(mb->continuation, b)) {
     156
     157                if (!_is_continuation(s[i])) {
    171158                        _set_ilseq();
    172159                        return UCHAR_ILSEQ;
     
    175162                /* Top bit becomes zero just before the last byte is shifted in. */
    176163                if (!(mb->continuation & 0x8000)) {
    177                         *c = ((char32_t) mb->continuation) << 6 | (b & 0x3f);
     164                        *c = ((char32_t) mb->continuation) << 6 | (s[i++] & 0x3f);
    178165                        mb->continuation = 0;
    179                         return ++i;
    180                 }
    181 
    182                 mb->continuation = mb->continuation << 6 | (b & 0x3f);
     166                        return i;
     167                }
     168
     169                mb->continuation = mb->continuation << 6 | (s[i++] & 0x3f);
    183170        }
    184171
  • common/str.c

    rb6061f8c rc7c6afd  
    156156static inline int _char_continuation_bytes(char32_t c)
    157157{
    158         if ((c & ~LO_MASK_32(7)) == 0)
    159                 return 0;
    160 
    161158        if ((c & ~LO_MASK_32(11)) == 0)
    162159                return 1;
     
    210207char32_t str_decode(const char *str, size_t *offset, size_t size)
    211208{
    212         if (*offset >= size)
     209        if (*offset + 1 > size)
    213210                return 0;
    214211
     
    226223        /* Determine code length */
    227224
    228         int cbytes = _continuation_bytes(b0);
    229         int b0_bits = 6 - cbytes;  /* Data bits in first byte */
    230 
    231         if (cbytes < 0 || *offset + cbytes > size)
     225        unsigned int cbytes = _continuation_bytes(b0);
     226        unsigned int b0_bits = 6 - cbytes;  /* Data bits in first byte */
     227
     228        if (*offset + cbytes > size)
    232229                return U_SPECIAL;
    233230
     
    235232
    236233        /* Decode continuation bytes */
    237         for (int i = 0; i < cbytes; i++) {
    238                 uint8_t b = (uint8_t) str[*offset];
     234        while (cbytes > 0) {
     235                uint8_t b = (uint8_t) str[(*offset)++];
    239236
    240237                if (!_is_continuation_byte(b))
    241238                        return U_SPECIAL;
    242239
    243                 (*offset)++;
    244 
    245240                /* Shift data bits to ch */
    246241                ch = (ch << CONT_BITS) | (char32_t) (b & LO_MASK_8(CONT_BITS));
    247         }
    248 
    249         /*
    250          * Reject non-shortest form encodings.
    251          * See https://www.unicode.org/versions/corrigendum1.html
    252          */
    253         if (cbytes != _char_continuation_bytes(ch))
    254                 return U_SPECIAL;
     242                cbytes--;
     243        }
    255244
    256245        return ch;
     
    356345
    357346/* Convert in place any bytes that don't form a valid character into U_SPECIAL. */
    358 static void _sanitize_string(char *str, size_t n)
    359 {
    360         uint8_t *b = (uint8_t *) str;
    361 
    362         for (; *b && n > 0; b++, n--) {
    363                 int cont = _continuation_bytes(b[0]);
    364                 if (__builtin_expect(cont, 0) == 0)
     347static void _repair_string(char *str, size_t n)
     348{
     349        for (; *str && n > 0; str++, n--) {
     350                int cont = _continuation_bytes(*str);
     351                if (cont == 0)
    365352                        continue;
    366353
    367354                if (cont < 0 || n <= (size_t) cont) {
    368                         b[0] = U_SPECIAL;
     355                        *str = U_SPECIAL;
    369356                        continue;
    370357                }
    371358
    372                 /* Check continuation bytes. */
    373359                for (int i = 1; i <= cont; i++) {
    374                         if (!_is_continuation_byte(b[i])) {
    375                                 b[0] = U_SPECIAL;
     360                        if (!_is_continuation_byte(str[i])) {
     361                                *str = U_SPECIAL;
    376362                                continue;
    377363                        }
    378                 }
    379 
    380                 /*
    381                  * Check for non-shortest form encoding.
    382                  * See https://www.unicode.org/versions/corrigendum1.html
    383                  */
    384 
    385                 switch (cont) {
    386                 case 1:
    387                         /* 0b110!!!!x 0b10xxxxxx */
    388                         if (!(b[0] & 0b00011110))
    389                                 b[0] = U_SPECIAL;
    390 
    391                         continue;
    392                 case 2:
    393                         /* 0b1110!!!! 0b10!xxxxx 0b10xxxxxx */
    394                         if (!(b[0] & 0b00001111) && !(b[1] & 0b00100000))
    395                                 b[0] = U_SPECIAL;
    396 
    397                         continue;
    398                 case 3:
    399                         /* 0b11110!!! 0b10!!xxxx 0b10xxxxxx 0b10xxxxxx */
    400                         if (!(b[0] & 0b00000111) && !(b[1] & 0b00110000))
    401                                 b[0] = U_SPECIAL;
    402 
    403                         continue;
    404364                }
    405365        }
     
    921881static void _str_cpyn(char *dest, size_t size, const char *src)
    922882{
    923         assert(dest && src && size);
    924 
    925         if (!dest || !src || !size)
    926                 return;
    927 
    928         if (size == STR_NO_LIMIT)
    929                 return _str_cpy(dest, src);
    930 
    931883        char *dest_top = dest + size - 1;
    932         assert(size == 1 || dest < dest_top);
    933884
    934885        while (*src && dest < dest_top)
     
    956907        assert(src != NULL);
    957908        assert(dest != NULL);
    958         assert(size == STR_NO_LIMIT || dest + size > dest);
    959909
    960910        /* Copy data. */
     
    962912
    963913        /* In-place translate invalid bytes to U_SPECIAL. */
    964         _sanitize_string(dest, size);
     914        _repair_string(dest, size);
    965915}
    966916
     
    991941
    992942        /* In-place translate invalid bytes to U_SPECIAL. */
    993         _sanitize_string(dest, size);
     943        _repair_string(dest, size);
    994944}
    995945
     
    1010960        assert(dest != NULL);
    1011961        assert(size > 0);
    1012         assert(size == STR_NO_LIMIT || dest + size > dest);
    1013962
    1014963        size_t dstr_size = _str_nsize(dest, size);
    1015         if (dstr_size < size) {
    1016                 _str_cpyn(dest + dstr_size, size - dstr_size, src);
    1017                 _sanitize_string(dest + dstr_size, size - dstr_size);
    1018         }
     964        _str_cpyn(dest + dstr_size, size - dstr_size, src);
     965        _repair_string(dest + dstr_size, size - dstr_size);
    1019966}
    1020967
     
    15931540                return NULL;
    15941541
    1595         memcpy(dest, src, size);
    1596         _sanitize_string(dest, size);
     1542        _str_cpy(dest, src);
     1543        _repair_string(dest, size);
    15971544        return dest;
    15981545}
     
    16201567char *str_ndup(const char *src, size_t n)
    16211568{
    1622         size_t size = _str_nsize(src, n);
    1623 
    1624         char *dest = malloc(size + 1);
     1569        size_t size = _str_nsize(src, n) + 1;
     1570
     1571        char *dest = malloc(size);
    16251572        if (!dest)
    16261573                return NULL;
    16271574
    1628         memcpy(dest, src, size);
    1629         _sanitize_string(dest, size);
    1630         dest[size] = 0;
     1575        _str_cpyn(dest, size, src);
     1576        _repair_string(dest, size);
    16311577        return dest;
    16321578}
  • uspace/app/sysinst/sysinst.c

    rb6061f8c rc7c6afd  
    7272 */
    7373#define DEFAULT_DEV_0 "devices/\\hw\\sys\\00:01.1\\c0d0"
    74 #define DEFAULT_DEV_1 "devices/\\hw\\sys\\ide1\\c0d0"
     74#define DEFAULT_DEV_1 "devices/\\hw\\sys\\00:01.0\\ide1\\c0d0"
    7575//#define DEFAULT_DEV "devices/\\hw\\pci0\\00:01.2\\uhci_rh\\usb01_a1\\mass-storage0\\l0"
    7676/** Volume label for the new file system */
  • uspace/drv/block/isa-ide/main.c

    rb6061f8c rc7c6afd  
    169169        isa_ide_ctrl_t *ctrl;
    170170        isa_ide_hwres_t res;
    171         unsigned chans;
    172171        errno_t rc;
    173172
     
    188187        ctrl->dev = dev;
    189188
    190         chans = 0;
    191 
    192189        rc = isa_ide_channel_init(ctrl, &ctrl->channel[0], 0, &res);
    193         if (rc == EOK)
    194                 ++chans;
    195         else if (rc != ENOENT)
     190        if (rc == ENOENT)
    196191                goto error;
    197192
    198193        rc = isa_ide_channel_init(ctrl, &ctrl->channel[1], 1, &res);
    199         if (rc == EOK)
    200                 ++chans;
    201         else if (rc != ENOENT)
    202                 goto error;
    203 
    204         if (chans == 0) {
    205                 ddf_msg(LVL_ERROR, "No ISA IDE devices found.");
     194        if (rc == ENOENT)
     195                goto error;
     196
     197        if (rc != EOK) {
     198                ddf_msg(LVL_ERROR, "Failed initializing ATA controller.");
    206199                rc = EIO;
    207200                goto error;
  • uspace/drv/block/pci-ide/main.c

    rb6061f8c rc7c6afd  
    136136        pci_ide_hwres_t res;
    137137        async_sess_t *parent_sess;
    138         unsigned chans;
    139138        errno_t rc;
    140139
     
    158157                goto error;
    159158
    160         chans = 0;
    161 
    162159        rc = pci_ide_channel_init(ctrl, &ctrl->channel[0], 0, &res);
    163         if (rc == EOK)
    164                 ++chans;
    165         else if (rc != ENOENT)
     160        if (rc == ENOENT)
    166161                goto error;
    167162
    168163        rc = pci_ide_channel_init(ctrl, &ctrl->channel[1], 1, &res);
    169         if (rc == EOK)
    170                 ++chans;
    171         else if (rc != ENOENT)
    172                 goto error;
    173 
    174         if (chans == 0) {
    175                 ddf_msg(LVL_ERROR, "No PCI IDE devices found.");
     164        if (rc == ENOENT)
     165                goto error;
     166
     167        if (rc != EOK) {
     168                ddf_msg(LVL_ERROR, "Failed initializing ATA controller.");
    176169                rc = EIO;
    177170                goto error;
  • uspace/lib/c/test/adt/odict.c

    rb6061f8c rc7c6afd  
    233233
    234234                e->key = v;
    235                 odict_insert(&e->odict, &odict, ep ? &ep->odict : NULL);
     235                odict_insert(&e->odict, &odict, &ep->odict);
    236236                PCUT_ASSERT_ERRNO_VAL(EOK, odict_validate(&odict));
    237237                v = seq_next(v);
  • uspace/lib/c/test/str.c

    rb6061f8c rc7c6afd  
    2727 */
    2828
    29 #include "pcut/asserts.h"
    3029#include <stdio.h>
    3130#include <str.h>
     
    116115}
    117116
    118 PCUT_TEST(str_non_shortest)
    119 {
    120         /* Overlong zero. */
    121         const char overlong1[] = { 0b11000000, 0b10000000, 0 };
    122         const char overlong2[] = { 0b11100000, 0b10000000, 0 };
    123         const char overlong3[] = { 0b11110000, 0b10000000, 0 };
    124 
    125         const char overlong4[] = { 0b11000001, 0b10111111, 0 };
    126         const char overlong5[] = { 0b11100000, 0b10011111, 0b10111111, 0 };
    127         const char overlong6[] = { 0b11110000, 0b10001111, 0b10111111, 0b10111111, 0 };
    128 
    129         size_t offset = 0;
    130         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, str_decode(overlong1, &offset, sizeof(overlong1)));
    131         offset = 0;
    132         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, str_decode(overlong2, &offset, sizeof(overlong2)));
    133         offset = 0;
    134         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, str_decode(overlong3, &offset, sizeof(overlong3)));
    135         offset = 0;
    136         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, str_decode(overlong4, &offset, sizeof(overlong4)));
    137         offset = 0;
    138         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, str_decode(overlong5, &offset, sizeof(overlong5)));
    139         offset = 0;
    140         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, str_decode(overlong6, &offset, sizeof(overlong6)));
    141 
    142         char sanitized[sizeof(overlong6)];
    143         str_cpy(sanitized, STR_NO_LIMIT, overlong1);
    144         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, sanitized[0]);
    145         str_cpy(sanitized, STR_NO_LIMIT, overlong2);
    146         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, sanitized[0]);
    147         str_cpy(sanitized, STR_NO_LIMIT, overlong3);
    148         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, sanitized[0]);
    149         str_cpy(sanitized, STR_NO_LIMIT, overlong4);
    150         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, sanitized[0]);
    151         str_cpy(sanitized, STR_NO_LIMIT, overlong5);
    152         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, sanitized[0]);
    153         str_cpy(sanitized, STR_NO_LIMIT, overlong6);
    154         PCUT_ASSERT_INT_EQUALS(U_SPECIAL, sanitized[0]);
    155 }
    156 
    157117PCUT_EXPORT(str);
Note: See TracChangeset for help on using the changeset viewer.