Author eryksun
Recipients CrouZ, eryksun, nw0, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-02-22.06:49:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1613976595.83.0.455392741889.issue38822@roundup.psfhosted.org>
In-reply-to
Content
Here's an implementation of attributes_from_dir() that strips trailing slashes (e.g. "C:/spam///" -> "C:/spam"), which entails copying the const string up to the last character that's not a slash. Rooted paths and drive paths that reference a root directory, such as "/" and "C:////", are special cased to avoid creating an empty path or a drive-relative path (e.g. "C:", which expands to the current working directory on drive C:).

static BOOL
attributes_from_dir(LPCWSTR pszFile, BY_HANDLE_FILE_INFORMATION *info,
                    ULONG *reparse_tag)
{
    BOOL result = TRUE;
    HANDLE hFind;
    WIN32_FIND_DATAW fileData;
    LPWSTR filename = (LPWSTR)pszFile;
    size_t len, n;

    /* Issue 38822: trailing slashes must be removed. */
    /* Get the length without trailing slashes. */
    n = len = wcslen(filename);
    while (n && (filename[n - 1] == L'\\' || filename[n - 1] == L'/')) {
        n--;
    }

    if (n != len) {
        if (n == 0 || (n == 2 && filename[1] == L':')) {
            /* A root directory such as \ or C:\ has no parent to query. */
            result = FALSE;
            goto cleanup;
        }
        /* Copy the string without trailing slashes. */
        filename = malloc((n + 1) * sizeof(WCHAR));
        if (!filename || wcsncpy_s(filename, n + 1, pszFile, n)) {
            result = FALSE;
            goto cleanup;
        }
    }

    hFind = FindFirstFileW(filename, &fileData);
    if (hFind == INVALID_HANDLE_VALUE) {
        result = FALSE;
        goto cleanup;
    }
    FindClose(hFind);
    find_data_to_file_info(&fileData, info, reparse_tag);

cleanup:
    if (filename && filename != pszFile) {
        free(filename);
    }
    return result;
}
History
Date User Action Args
2021-02-22 06:49:55eryksunsetrecipients: + eryksun, paul.moore, tim.golden, CrouZ, zach.ware, steve.dower, nw0
2021-02-22 06:49:55eryksunsetmessageid: <1613976595.83.0.455392741889.issue38822@roundup.psfhosted.org>
2021-02-22 06:49:55eryksunlinkissue38822 messages
2021-02-22 06:49:55eryksuncreate