Giter VIP home page Giter VIP logo

fcaseopen's People

Contributors

onesadcookie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fcaseopen's Issues

Conversely?

Any plans of making case-sensitive fopen for case-insensitive (Windows) filesystems? Sometimes I prefer to demand relaxed API to follow strict ones, across platforms.

casepath return value is true when a file (but not parent directory) doesn't exist.

Hi!

It's me again I found another bug, let's hope this is the last one (isn't C string and path handling a joy?). The return value of casepath is true even when a file doesn't exist. This doesn't actually break fcaseopen or casechdir since fopen will just return NULL anyway but it was a nasty surprise when I used casepath off label on its own to get the valid file path so I could check the date on it.

Thanks,
Aaron.

Casepath buffer overflow

The restriction that "r must have strlen(path) + 2 bytes" is incorrect as it fails to account for the null terminator. This is easiest way to see this is to walk through casepath on "a", which would have been alloca'd 3 bytes:

// r must have strlen(path) + 2 bytes
static int casepath(char const *path, char *r) // In the case that path is "a", the length of r is 3 bytes.
{
    size_t l = strlen(path);
    char *p = alloca(l + 1);
    strcpy(p, path);
    size_t rl = 0;
    
    DIR *d;
    if (p[0] == '/')
    {
        d = opendir("/");
        p = p + 1;
    }
    else
    {
        d = opendir(".");
        r[0] = '.'; // we take this path an initialise the first two bytes to 'a' and a null.
        r[1] = 0;
        rl = 1;
    }
    
    int last = 0;
    char *c = strsep(&p, "/"); // strsep doesn't find a '/' and sets c to the entire string. In this case "a"
    while (c)
    {
        if (!d) // We successfully opened "."
        {
            return 0;
        }
        
        if (last) // last is still 0
        {
            closedir(d);
            return 0;
        }
        
        r[rl] = '/'; // rl is 1, r is now "./" (no null terminator)
        rl += 1;
        r[rl] = 0; // r is "./" (null terminated)
        
        struct dirent *e = readdir(d); // reading the current directory "."
        while (e)
        {
            if (strcasecmp(c, e->d_name) == 0)
            { // found file 'a'
                // copy 'a' to where the null terminator was (the last byte in our buffer)
                // AND a null terminator in the next byte of the buffer!?!
                strcpy(r + rl, e->d_name);
                ...

This means that the requirement for casepath's buffer size is actually three bytes more than path's strlen(), since strcpy writes a null to the next byte.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.