Ignore:
Timestamp:
Mar 23, 2018, 11:44:44 PM (7 years ago)
Author:
bird
Message:

kmk: replaced w32ify() as it uses unsafe static buffer and encourages buffer size assumptions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/w32/pathstuff.c

    r3140 r3186  
    2121#if 1 /* bird */
    2222# include "nt_fullpath.h"
     23# include <assert.h>
    2324#endif
    2425
     
    9596
    9697/*
     98 * Convert to forward slashes directly (w32ify(filename, 0)).
     99 */
     100char *unix_slashes(char *filename) /* bird */
     101{
     102    char *slash = filename ;
     103    while ((slash = strchr(slash, '\\')) != NULL)
     104        *slash++ = '/';
     105    return filename;
     106}
     107
     108/*
     109 * Resolve and convert to forward slashes directly (w32ify(filename, 1)).
     110 * Returns if out of buffer space.
     111 */
     112char *unix_slashes_resolved(const char *src, char *dst, unsigned len)
     113{
     114    assert(len >= FILENAME_MAX);
     115    *dst = '\0'; /** @todo nt_fullpath_cached needs to return some indication of overflow. */
     116#if 1
     117    nt_fullpath_cached(src, dst, len);
     118#else
     119    _fullpath(dst, src, len);
     120#endif
     121
     122    return unix_slashes(dst);
     123}
     124
     125#if 0 /* bird: replaced by unix_slashes and unix_slahes_resolved. */
     126/*
    97127 * Convert to forward slashes. Resolve to full pathname optionally
    98128 */
     
    101131{
    102132    static char w32_path[FILENAME_MAX];
    103     char *p;
    104 
    105133#if 1 /* bird */
     134
    106135    if (resolve) {
    107136        nt_fullpath_cached(filename, w32_path, sizeof(w32_path));
     
    110139        strncat(w32_path, filename, sizeof(w32_path));
    111140    }
     141    return unix_slashes(w32_path);
     142
    112143#else   /* !bird */
     144    char *p;
     145
    113146    if (resolve) {
    114147        _fullpath(w32_path, filename, sizeof (w32_path));
    115148    } else
    116149        strncpy(w32_path, filename, sizeof (w32_path));
    117 #endif  /* !bird */
    118150
    119151    for (p = w32_path; p && *p; p++)
     
    122154
    123155    return w32_path;
    124 }
     156#endif  /* !bird */
     157}
     158#endif
    125159
    126160char *
     
    130164
    131165        if (p) {
     166#if 1
     167                p = unix_slashes(p);
     168#else
    132169                char *q = w32ify(buf, 0);
    133170#if 1  /* bird - UPSTREAM? */
    134                 buf[0] = '\0';
    135                 strncat(buf, q, len);
     171                buf[0] = '\0';
     172                strncat(buf, q, len);
    136173#else  /* !bird */
    137174                strncpy(buf, q, len);
     175#endif
    138176#endif
    139177        }
Note: See TracChangeset for help on using the changeset viewer.