alpine 3.8
tmpfile weakness #17


Weakness Breakdown


A temporary file weakness occurs when a temporary file that is created and used by a high-privilege process is accidentally shared with a low-privilege process, on account of it being temporary and generated after all security controls have been applied. This allows the low-privilege process to read data from the high-privilege process (information leakage), or worse, influence the high-privilege process by modifying the shared temporary file.

Warning code(s):

Temporary file race condition.

File Name:



The highlighted line of code below is the trigger point of this particular Alpine 3.8 tmpfile weakness.

   mib[0] = CTL_HW;
  mib[1] = HW_NCPU;
  if (!sysctl(mib, 2, &cpus, &sz, NULL, 0)
      && cpus >= 1)
    return cpus;
  cpus = -1;
#  endif /* CTL_HW */

  /* no idea / failure, just return 1. */
  return 1;
# endif
#endif /* KMK */

#ifdef __MSDOS__
static void
msdos_return_to_initial_directory (void)
  if (directory_before_chdir)
    chdir (directory_before_chdir);
#endif  /* __MSDOS__ */

#ifndef _MSC_VER /* bird */
char *mktemp (char *template);
int mkstemp (char *template);

open_tmpfile(char **name, const char *template)
  int fd;

#if defined HAVE_MKSTEMP || defined HAVE_MKTEMP
# define TEMPLATE_LEN   strlen (template)
# define TEMPLATE_LEN   L_tmpnam
  *name = xmalloc (TEMPLATE_LEN + 1);
  strcpy (*name, template);

#if defined HAVE_MKSTEMP && defined HAVE_FDOPEN
  /* It's safest to use mkstemp(), if we can.  */
  fd = mkstemp (*name);
  if (fd == -1)
    return 0;
  return fdopen (fd, "w");

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.