Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 59f388a in mainline


Ignore:
Timestamp:
2017-04-04T20:56:47Z (5 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
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.

Location:
uspace/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/io.c

    r8fe46a0 r59f388a  
    834834off64_t ftell(FILE *stream)
    835835{
     836        /* The native position is too large for the C99-ish interface. */
     837        if (stream->pos - stream->ungetc_chars > INT64_MAX)
     838                return EOF;
     839
    836840        if (stream->error)
    837841                return EOF;
  • 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
  • uspace/lib/posix/source/unistd.c

    r8fe46a0 r59f388a  
    245245                break;
    246246        }
     247        if (posix_pos[fildes] > INT64_MAX) {
     248                /* The native width is too large for the POSIX interface. */
     249                errno = ERANGE;
     250                return -1;
     251        }
    247252        return posix_pos[fildes];
    248253}
Note: See TracChangeset for help on using the changeset viewer.