Changeset 59f388a in mainline for uspace/lib/posix/source/sys/stat.c


Ignore:
Timestamp:
2017-04-04T20:56:47Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
51774cd
Parents:
8fe46a0
Message:

Fail legacy interfaces if the position is too large for them to represent

HelenOS interfaces support unsigned 64-bit file sizes and offsets. This
is in contrast with C99-ish and POSIX-ish interfaces in libc and libposix.
The legacy API emulation internally uses the native unsigned 64-bit file
sizes and positions and so it may happen that a returned file size or
offset are bigger than the legacy interface can represent. We choose
to report failure in such a case in order to avoid returning wrong
results.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/source/sys/stat.c

    r8fe46a0 r59f388a  
    4949 * @param dest POSIX stat struct.
    5050 * @param src HelenOS stat struct.
     51 *
     52 * @return 0 on success, -1 on error.
    5153 */
    52 static void stat_to_posix(struct posix_stat *dest, struct stat *src)
     54static int stat_to_posix(struct posix_stat *dest, struct stat *src)
    5355{
    5456        memset(dest, 0, sizeof(struct posix_stat));
     
    6870        dest->st_nlink = src->lnkcnt;
    6971        dest->st_size = src->size;
     72
     73        if (src->size > INT64_MAX) {
     74                errno = ERANGE;
     75                return -1;
     76        }
     77
     78        return 0;
    7079}
    7180
     
    8392        if (rc < 0)
    8493                return -1;
    85         stat_to_posix(st, &hst);
    86         return 0;
     94        return stat_to_posix(st, &hst);
    8795}
    8896
     
    113121        if (rc < 0)
    114122                return -1;
    115         stat_to_posix(st, &hst);
    116         return 0;
     123        return stat_to_posix(st, &hst);
    117124}
    118125
Note: See TracChangeset for help on using the changeset viewer.