Blame inet/tst-if_index-long.c

Packit Service 2ce813
/* Check for descriptor leak in if_nametoindex with a long interface name.
Packit Service 2ce813
   Copyright (C) 2018 Free Software Foundation, Inc.
Packit Service 2ce813
   This file is part of the GNU C Library.
Packit Service 2ce813
Packit Service 2ce813
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 2ce813
   modify it under the terms of the GNU Lesser General Public
Packit Service 2ce813
   License as published by the Free Software Foundation; either
Packit Service 2ce813
   version 2.1 of the License, or (at your option) any later version.
Packit Service 2ce813
Packit Service 2ce813
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 2ce813
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 2ce813
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 2ce813
   Lesser General Public License for more details.
Packit Service 2ce813
Packit Service 2ce813
   You should have received a copy of the GNU Lesser General Public
Packit Service 2ce813
   License along with the GNU C Library; if not, see
Packit Service 2ce813
   <http://www.gnu.org/licenses/>.  */
Packit Service 2ce813
Packit Service 2ce813
/* This test checks for a descriptor leak in case of a long interface
Packit Service 2ce813
   name (CVE-2018-19591, bug 23927).  */
Packit Service 2ce813
Packit Service 2ce813
#include <errno.h>
Packit Service 2ce813
#include <net/if.h>
Packit Service 2ce813
#include <netdb.h>
Packit Service 2ce813
#include <string.h>
Packit Service 2ce813
#include <support/check.h>
Packit Service 2ce813
#include <support/descriptors.h>
Packit Service 2ce813
#include <support/support.h>
Packit Service 2ce813
Packit Service 2ce813
static int
Packit Service 2ce813
do_test (void)
Packit Service 2ce813
{
Packit Service 2ce813
  struct support_descriptors *descrs = support_descriptors_list ();
Packit Service 2ce813
Packit Service 2ce813
  /* Prepare a name which is just as long as required for trigging the
Packit Service 2ce813
     bug.  */
Packit Service 2ce813
  char name[IFNAMSIZ + 1];
Packit Service 2ce813
  memset (name, 'A', IFNAMSIZ);
Packit Service 2ce813
  name[IFNAMSIZ] = '\0';
Packit Service 2ce813
  TEST_COMPARE (strlen (name), IFNAMSIZ);
Packit Service 2ce813
  struct ifreq ifr;
Packit Service 2ce813
  TEST_COMPARE (strlen (name), sizeof (ifr.ifr_name));
Packit Service 2ce813
Packit Service 2ce813
  /* Test directly via if_nametoindex.  */
Packit Service 2ce813
  TEST_COMPARE (if_nametoindex (name), 0);
Packit Service 2ce813
  TEST_COMPARE (errno, ENODEV);
Packit Service 2ce813
  support_descriptors_check (descrs);
Packit Service 2ce813
Packit Service 2ce813
  /* Same test via getaddrinfo.  */
Packit Service 2ce813
  char *host = xasprintf ("fea0::%%%s", name);
Packit Service 2ce813
  struct addrinfo hints = { .ai_flags = AI_NUMERICHOST, };
Packit Service 2ce813
  struct addrinfo *ai;
Packit Service 2ce813
  TEST_COMPARE (getaddrinfo (host, NULL, &hints, &ai), EAI_NONAME);
Packit Service 2ce813
  support_descriptors_check (descrs);
Packit Service 2ce813
Packit Service 2ce813
  support_descriptors_free (descrs);
Packit Service 2ce813
Packit Service 2ce813
  return 0;
Packit Service 2ce813
}
Packit Service 2ce813
Packit Service 2ce813
#include <support/test-driver.c>