VirtualBox

Changeset 3186 in kBuild


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

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

Location:
trunk/src/kmk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/dir.c

    r3140 r3186  
    585585
    586586#ifdef WINDOWS32
     587          PATH_VAR (w32_fullpath);
    587588          char *w32_path;
    588589#endif
     
    593594          dc_key.dev = st.st_dev;
    594595#ifdef WINDOWS32
     596          w32_path = unix_slashes_resolved (name, w32_fullpath, GET_PATH_MAX);
    595597# ifndef CONFIG_WITH_STRCACHE2
    596           dc_key.path_key = w32_path = w32ify (name, 1);
     598          dc_key.path_key = w32_path; /* = w32ify (name, 1); - bird */
    597599# else  /* CONFIG_WITH_STRCACHE2 */
    598           w32_path = w32ify (name, 1);
    599           dc_key.path_key = strcache_add (w32_path);
     600          dc_key.path_key = strcache_add (w32_path);
    600601# endif /* CONFIG_WITH_STRCACHE2 */
    601           dc_key.ctime = st.st_ctime;
     602          dc_key.ctime = st.st_ctime;
    602603#else
    603604# ifdef VMS_INO_T
  • trunk/src/kmk/function.c

    r3159 r3186  
    28762876
    28772877#ifdef WINDOWS32                                                    /* bird */
    2878   dest = w32ify((char *)name, 1);
     2878  dest = unix_slashes_resolved (name, apath, GET_PATH_MAX);
    28792879  if (!dest)
    28802880    return NULL;
    2881   {
    2882   size_t len = strlen(dest);
    2883   memcpy(apath, dest, len);
    2884   dest = apath + len;
    2885   }
     2881  dest = strchr(apath, '\0');
    28862882
    28872883  (void)end; (void)start; (void)apath_limit;
  • trunk/src/kmk/job.c

    r3159 r3186  
    38303830    if (shell)
    38313831      {
     3832# if 1 /* bird */
     3833        unix_slashes (shell);
     3834# else
    38323835        char *p = w32ify (shell, 0);
    38333836        strcpy (shell, p);
     3837# endif
    38343838      }
    38353839#endif
  • trunk/src/kmk/main.c

    r3170 r3186  
    12421242      batch_mode_shell = 1;
    12431243      unixy_shell = 0;
     1244# if 1  /* bird: sprintf? wtf. */
     1245      default_shell = unix_slashes (xstrdup (search_token));
     1246# else
    12441247      sprintf (sh_path, "%s", search_token);
    12451248      default_shell = xstrdup (w32ify (sh_path, 0));
     1249# endif
    12461250      DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"),
    12471251                       default_shell));
     
    12571261    {
    12581262      /* search token path was found */
     1263# if 1  /* bird: sprintf? wtf. */
     1264      default_shell = unix_slashes (xstrdup (search_token));
     1265# else
    12591266      sprintf (sh_path, "%s", search_token);
    12601267      default_shell = xstrdup (w32ify (sh_path, 0));
     1268# endif
    12611269      DB (DB_VERBOSE, (_("find_and_set_shell() setting default_shell = %s\n"),
    12621270                       default_shell));
     
    12801288              *ep = '\0';
    12811289
     1290# if 1 /* bird: insanity insurance */
     1291              _snprintf (sh_path, GET_PATH_MAX, "%s/%s", p, search_token);
     1292# else
    12821293              sprintf (sh_path, "%s/%s", p, search_token);
     1294# endif
    12831295              if (_access (sh_path, 0) == 0)
    12841296                {
     1297# if 1  /* bird: we can modify sh_path directly. */
     1298                  default_shell = xstrdup (unix_slashes (sh_path));
     1299# else
    12851300                  default_shell = xstrdup (w32ify (sh_path, 0));
     1301# endif
    12861302                  sh_found = 1;
    12871303                  *ep = PATH_SEPARATOR_CHAR;
     
    13021318          if (p && *p)
    13031319            {
     1320# if 1 /* bird: insanity insurance */
     1321              _snprintf (sh_path, GET_PATH_MAX, "%s/%s", p, search_token);
     1322# else
    13041323              sprintf (sh_path, "%s/%s", p, search_token);
     1324# endif
    13051325              if (_access (sh_path, 0) == 0)
    13061326                {
     1327# if 1  /* bird: we can modify sh_path directly. */
     1328                  default_shell = xstrdup (unix_slashes (sh_path));
     1329# else
    13071330                  default_shell = xstrdup (w32ify (sh_path, 0));
     1331# endif
    13081332                  sh_found = 1;
    13091333                }
     
    21302154  if (strpbrk (argv[0], "/:\\") || strstr (argv[0], "..")
    21312155      || strneq (argv[0], "//", 2))
    2132     argv[0] = xstrdup (w32ify (argv[0], 1));
     2156# if 1  /* bird */
     2157    {
     2158      PATH_VAR (tmp_path_buf);
     2159      argv[0] = xstrdup (unix_slashes_resolved (argv[0], tmp_path_buf,
     2160                                                GET_PATH_MAX));
     2161    }
     2162# else  /* bird */
     2163      //argv[0] = xstrdup (w32ify (argv[0], 1));
     2164# endif /* bird */
    21332165#else /* WINDOWS32 */
    21342166#if defined (__MSDOS__) || defined (__EMX__)
  • trunk/src/kmk/w32/include/pathstuff.h

    r3140 r3186  
    2020char *convert_Path_to_windows32(char *Path, char to_delim);
    2121char *convert_vpath_to_windows32(char *Path, char to_delim);
     22#if 1
     23char *unix_slashes(char *filename); /* bird */
     24char *unix_slashes_resolved(const char *src, char *dst, unsigned len); /* bird */
     25#else
    2226char *w32ify(const char *filename, int resolve);
     27#endif
    2328char *getcwd_fs(char *buf, int len);
    2429
  • 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.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette