kdumpd/kdumpd.c
int 
validate_access(char **filep, int mode)
{
  struct stat stbuf;
  int	fd;
  char *filename = *filep;
  static char pathname[MAXPATHLEN]; 

  if (strstr(filename, "/") || strstr(filename, ".."))
    return (EACCESS);
  
  snprintf(pathname, sizeof(pathname), "./%s", filename);

  if (0 == stat(pathname, &stbuf))
    return (EEXIST);
  
  if (errno != ENOENT)
    return (errno);


  fd = open(filename, O_RDWR|O_CREAT|O_TRUNC , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);

  if (fd < 0)
    return (errno + 100);
  
  file = fdopen(fd, (mode == RRQ)? "r":"w");
  if (file == NULL) {
    return errno+100;
  }

  return (0);  
}
/*
 * Validate file access. We only allow storage of files that do not already
 * exist, and that do not include directory specifiers in their pathnames. 
 * This is because kernel coredump filenames should always be of the form 
 * "core-version-IP as dotted quad-random string" as in :
 * core-custom-17.202.40.204-a75b4eec
 * The file is written to the directory supplied as the first argument
 * in inetd.conf
 */
Validate file access. We only allow storage of files that do not already
exist, and that do not include directory specifiers in their pathnames.
Validate file access . We only allow storage of files that do not already exist and that do not include directory specifiers in their pathnames .
int 
validate_access(char **filep, int mode)
{
  struct stat stbuf;
  int	fd;
  char *filename = *filep;
  static char pathname[MAXPATHLEN]; 
  if (strstr(filename, "/") || strstr(filename, ".."))
    return (EACCESS);
  snprintf(pathname, sizeof(pathname), "./%s", filename);
  if (0 == stat(pathname, &stbuf))
    return (EEXIST);
  if (errno != ENOENT)
    return (errno);
  fd = open(filename, O_RDWR|O_CREAT|O_TRUNC , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  if (fd < 0)
    return (errno + 100);
  file = fdopen(fd, (mode == RRQ)? "r":"w");
  if (file == NULL) {
    return errno+100;
  }
  return (0);  
}
int validate_access ( char * * filep , int mode ) { struct stat stbuf ; int fd ; char * filename = * filep ; static char pathname [ MAXPATHLEN ] ; if ( strstr ( filename , " " ) || strstr ( filename , " " ) ) return ( EACCESS ) ; snprintf ( pathname , sizeof ( pathname ) , " " , filename ) ; if ( 0 == stat ( pathname , & stbuf ) ) return ( EEXIST ) ; if ( errno != ENOENT ) return ( errno ) ; fd = open ( filename , O_RDWR | O_CREAT | O_TRUNC , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH ) ; if ( fd < 0 ) return ( errno + 100 ) ; file = fdopen ( fd , ( mode == RRQ ) ? " " : " " ) ; if ( file == NULL ) { return errno + 100 ; } return ( 0 ) ; }
Validate file access.
Validate file access .