Changeset c0393db in mainline


Ignore:
Timestamp:
2015-04-04T21:14:22Z (10 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6efd162
Parents:
43523b1
Message:

isa: read() is not guaranteed to read all the bytes requested.

This wrong assumption prevented the isa driver from loading part of the configuration file when using FAT as root filesystem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/isa/isa.c

    r43523b1 rc0393db  
    245245        bool opened = false;
    246246        int fd;
    247         size_t len = 0;
     247        size_t file_len;
     248        size_t total_read = 0;
     249        ssize_t r;
    248250
    249251        fd = open(conf_path, O_RDONLY);
     
    255257        opened = true;
    256258
    257         len = lseek(fd, 0, SEEK_END);
     259        file_len = lseek(fd, 0, SEEK_END);
    258260        lseek(fd, 0, SEEK_SET);
    259         if (len == 0) {
     261        if (file_len == 0) {
    260262                ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",
    261263                    conf_path);
     
    263265        }
    264266
    265         buf = malloc(len + 1);
     267        buf = malloc(file_len + 1);
    266268        if (buf == NULL) {
    267269                ddf_msg(LVL_ERROR, "Memory allocation failed.");
     
    269271        }
    270272
    271         if (0 >= read(fd, buf, len)) {
    272                 ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
    273                 goto cleanup;
    274         }
    275 
    276         buf[len] = 0;
     273        do {
     274                r = read(fd, &buf[total_read], file_len - total_read);
     275                if (r < 0) {
     276                        ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
     277                        goto cleanup;
     278                }
     279
     280                total_read += r;
     281        } while (total_read < file_len);
     282
     283        buf[file_len] = 0;
    277284
    278285        suc = true;
Note: See TracChangeset for help on using the changeset viewer.