<commit_before>/***************************Copyright-DO-NOT-REMOVE-THIS-LINE**
 * CONDOR Copyright Notice
 *
 * See LICENSE.TXT for additional notices and disclaimers.
 *
 * Copyright (c)1990-1998 CONDOR Team, Computer Sciences Department, 
 * University of Wisconsin-Madison, Madison, WI.  All Rights Reserved.  
 * No use of the CONDOR Software Program Source Code is authorized 
 * without the express consent of the CONDOR Team.  For more information 
 * contact: CONDOR Team, Attention: Prof<NAME>, 
 * 7367 Computer Sciences, 1210 W. Dayton St., Madison, WI 53706-1685, 
 * (608) 262-0856 or <EMAIL>.
 *
 * U.S. Government Rights Restrictions: Use, duplication, or disclosure 
 * by the U.S. Government is subject to restrictions as set forth in 
 * subparagraph (c)(1)(ii) of The Rights in Technical Data and Computer 
 * Software clause at DFARS 252.227-7013 or subparagraphs (c)(1) and 
 * (2) of Commercial Computer Software-Restricted Rights at 48 CFR 
 * 52.227-19, as applicable, CONDOR Team, Attention: <NAME> 
 * Livny, 7367 Computer Sciences, 1210 W. Dayton St., Madison, 
 * WI 53706-1685, (608) 262-0856 or <EMAIL>.
****************************Copyright-DO-NOT-REMOVE-THIS-LINE**/

#include "condor_common.h"
#include "condor_config.h"

// Returns the full hostname of the given host in a static buffer.
// If the optional 2nd arg is non-NULL, set it to point to the hostent
// we get back. 
char*
get_full_hostname( const char* host, struct hostent **host_ptrp) 
{
	static char full_host[MAXHOSTNAMELEN];
	char* tmp;
	struct hostent *host_ptr;
	int i;

	if( (host_ptr = gethostbyname( host )) == NULL ) {
			// If the resolver can't find it, just return NULL
		if( host_ptrp ) {
			*host_ptrp = NULL;
		}
		return NULL;
	}
	if( host_ptrp ) {
		*host_ptrp = host_ptr;
	}

		// See if it's correct in the hostent we've got.
	if( host_ptr->h_name && 
		(tmp = strchr(host_ptr->h_name, '.')) ) { 
			// There's a '.' in the "name", use that as full.
		strcpy( full_host, host_ptr->h_name );
		return full_host;
	}

		// We still haven't found it yet, try all the aliases
		// until we find one with a '.'
	for( i=0; host_ptr->h_aliases[i]; i++ ) {
		if( (tmp = strchr(host_ptr->h_aliases[i], '.')) ) { 
			strcpy( full_host, host_ptr->h_aliases[i] );
			return full_host;
		}
	}

		// Still haven't found it, try to param for the domain.
	if( (tmp = param("DEFAULT_DOMAIN_NAME")) ) {
		if( tmp[0] == '.' ) {
			sprintf( full_host, "%s%s", host, tmp );
		} else {
			sprintf( full_host, "%s.%s", host, tmp );
		}
		free( tmp );
		return full_host;
	}

		// Still can't find it, just give up.
	strcpy( full_host, host );
	return full_host;
}<commit_msg>get_full_hostname() now returns a strnewp()'ed string, instead of a pointer to a static buffer, to make it more thread-safe and to prevent potential buffer overflow problems.<commit_after>/***************************Copyright-DO-NOT-REMOVE-THIS-LINE**
 * CONDOR Copyright Notice
 *
 * See LICENSE.TXT for additional notices and disclaimers.
 *
 * Copyright (c)1990-1998 CONDOR Team, Computer Sciences Department, 
 * University of Wisconsin-Madison, Madison, WI.  All Rights Reserved.  
 * No use of the CONDOR Software Program Source Code is authorized 
 * without the express consent of the CONDOR Team.  For more information 
 * contact: CONDOR Team, Attention: Prof<NAME>, 
 * 7367 Computer Sciences, 1210 W. Dayton St., Madison, WI 53706-1685, 
 * (608) 262-0856 or <EMAIL>.
 *
 * U.S. Government Rights Restrictions: Use, duplication, or disclosure 
 * by the U.S. Government is subject to restrictions as set forth in 
 * subparagraph (c)(1)(ii) of The Rights in Technical Data and Computer 
 * Software clause at DFARS 252.227-7013 or subparagraphs (c)(1) and 
 * (2) of Commercial Computer Software-Restricted Rights at 48 CFR 
 * 52.227-19, as applicable, CONDOR Team, Attention: Professor Miron 
 * Livny, 7367 Computer Sciences, 1210 W. Dayton St., Madison, 
 * WI 53706-1685, (608) 262-0856 or <EMAIL>.
****************************Copyright-DO-NOT-REMOVE-THIS-LINE**/

#include "condor_common.h"
#include "condor_string.h"
#include "condor_config.h"


// Returns the full hostname of the given host in a newly allocated
// string, which should be de-allocated with delete [].  If the
// optional 2nd arg is non-NULL, set it to point to the hostent we get
// back.  WARNING: Using the 2nd arg is _not_ thread-safe.

char*
get_full_hostname( const char* host, struct hostent **host_ptrp) 
{
	char* full_host;
	char* tmp;
	struct hostent *host_ptr;
	int h, i;

	if( (host_ptr = gethostbyname( host )) == NULL ) {
			// If the resolver can't find it, just return NULL
		if( host_ptrp ) {
			*host_ptrp = NULL;
		}
		return NULL;
	}
	if( host_ptrp ) {
		*host_ptrp = host_ptr;
	}

		// See if it's correct in the hostent we've got.
	if( host_ptr->h_name && 
		(tmp = strchr(host_ptr->h_name, '.')) ) { 
			// There's a '.' in the "name", use that as full.
		full_host = strnewp( host_ptr->h_name );
		return full_host;
	}

		// We still haven't found it yet, try all the aliases
		// until we find one with a '.'
	for( i=0; host_ptr->h_aliases[i]; i++ ) {
		if( (tmp = strchr(host_ptr->h_aliases[i], '.')) ) { 
			full_host = strnewp( host_ptr->h_aliases[i] );
			return full_host;
		}
	}

		// Still haven't found it, try to param for the domain.
	if( (tmp = param("DEFAULT_DOMAIN_NAME")) ) {
		h = strlen( host );
		i = strlen( tmp );
		if( tmp[0] == '.' ) {
			full_host = new char[h+i+1];
			sprintf( full_host, "%s%s", host, tmp );
		} else {
				// There's no . at the front, so we have to add that.
			full_host = new char[h+i+2];
			sprintf( full_host, "%s.%s", host, tmp );
		}
		free( tmp );
		return full_host;
	}

		// Still can't find it, just give up.
	full_host = strnewp( host );
	return full_host;
}
{'fraction_non_alphanumeric': 0.14196891191709846, 'fraction_numerical': 0.030569948186528497, 'mean_word_length': 3.4926299456943366, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6599630', 'n_tokens_mistral': 2241, 'n_tokens_neox': 1974, 'n_words': 686}