kopia lustrzana https://github.com/jamescoxon/dl-fldigi
				
				
				
			Fork open file descriptors
* Add O_CLOEXEC to all open(...) calls
  * Add "e" to all fopen(...) calls
  * Prevents passing open file descriptors to child
    processes.  Leaving psid's available to the child
    could cause unwanted i/o problems and possibly a
    security leak.
			
			
				pull/2/head
			
			
		
							rodzic
							
								
									81a9f43e67
								
							
						
					
					
						commit
						cb392e471c
					
				| 
						 | 
				
			
			@ -123,6 +123,8 @@ AC_FUNC_STRFTIME
 | 
			
		|||
AC_FUNC_STRTOD
 | 
			
		||||
AC_CHECK_FUNCS([getaddrinfo gethostbyname hstrerror gmtime_r localtime_r memmove memset mkdir select setenv snprintf socket socketpair strcasecmp strcasestr strchr strdup strerror strlcpy strncasecmp strrchr strstr strtol uname unsetenv vsnprintf])
 | 
			
		||||
 | 
			
		||||
# Check for O_CLOEXEC
 | 
			
		||||
AC_FCNTL_FLAGS
 | 
			
		||||
 | 
			
		||||
AC_PRESERVE_HELP_ORDER
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										22
									
								
								m4/funcs.m4
								
								
								
								
							
							
						
						
									
										22
									
								
								m4/funcs.m4
								
								
								
								
							| 
						 | 
				
			
			@ -13,3 +13,25 @@ AC_DEFINE_UNQUOTED([HAVE_]FUNC_NAME_UC, $ac_cv_have_func_[]$1, [Define to 1 if w
 | 
			
		|||
LIBS="$LIBS_search_libs_save"
 | 
			
		||||
 | 
			
		||||
])
 | 
			
		||||
 | 
			
		||||
# ---------------------------------------------------------------------------
 | 
			
		||||
# Macro: FCNTL_FLAGS
 | 
			
		||||
# ---------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
AC_DEFUN([AC_FCNTL_FLAGS],
 | 
			
		||||
[
 | 
			
		||||
  AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_o_cloexec], [
 | 
			
		||||
    AC_LANG_PUSH([C])
 | 
			
		||||
    save_CFLAGS="$CFLAGS"
 | 
			
		||||
    CFLAGS="$CFLAGS -I${srcdir}"
 | 
			
		||||
 | 
			
		||||
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <fcntl.h>], [ int flags= O_CLOEXEC])], [ac_cv_o_cloexec="yes"], [ac_cv_o_cloexec="no"])
 | 
			
		||||
    AC_LANG_POP
 | 
			
		||||
  ])
 | 
			
		||||
 | 
			
		||||
  AS_IF([test "x$ac_cv_o_cloexec" = "xyes"],[ AC_DEFINE(HAVE_O_CLOEXEC, 1, [Define to 1 if you have O_CLOEXEC defined])])
 | 
			
		||||
])
 | 
			
		||||
 | 
			
		||||
# ---------------------------------------------------------------------------
 | 
			
		||||
# End Macro: FCNTL_FLAGS
 | 
			
		||||
# ---------------------------------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -883,7 +883,7 @@ static bool open_serial(const char* dev)
 | 
			
		|||
{
 | 
			
		||||
	bool ret = false;
 | 
			
		||||
#ifdef __CYGWIN__
 | 
			
		||||
	int fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY);
 | 
			
		||||
	int fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY | O_CLOEXEC);
 | 
			
		||||
	if (fd != -1) {
 | 
			
		||||
		close(fd);
 | 
			
		||||
		ret = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -204,7 +204,12 @@ void PTT::open_tty(void)
 | 
			
		|||
	com_to_tty(pttdevName);
 | 
			
		||||
#    endif
 | 
			
		||||
 | 
			
		||||
	if ((pttfd = open(pttdevName.c_str(), O_RDWR | O_NOCTTY | O_NDELAY)) < 0) {
 | 
			
		||||
	int oflags = O_RDWR | O_NOCTTY | O_NDELAY;
 | 
			
		||||
#	ifdef HAVE_O_CLOEXEC
 | 
			
		||||
		oflags = oflags | O_CLOEXEC;
 | 
			
		||||
#	endif
 | 
			
		||||
 | 
			
		||||
	if ((pttfd = open(pttdevName.c_str(), oflags)) < 0) {
 | 
			
		||||
		LOG_ERROR("Could not open \"%s\": %s", pttdevName.c_str(), strerror(errno));
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -296,7 +301,12 @@ void PTT::open_parport(void)
 | 
			
		|||
{
 | 
			
		||||
    if (progdefaults.PTTdev.find("tty") != string::npos) return;
 | 
			
		||||
 | 
			
		||||
	if ((pttfd = open(progdefaults.PTTdev.c_str(), O_RDWR | O_NDELAY)) == -1) {
 | 
			
		||||
	int oflags = O_RDWR | O_NDELAY;
 | 
			
		||||
#	ifdef HAVE_O_CLOEXEC
 | 
			
		||||
		oflags = oflags | O_CLOEXEC;
 | 
			
		||||
#	endif
 | 
			
		||||
 | 
			
		||||
	if ((pttfd = open(progdefaults.PTTdev.c_str(),  oflags)) == -1) {
 | 
			
		||||
		LOG_ERROR("Could not open %s: %s", progdefaults.PTTdev.c_str(), strerror(errno));
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -417,7 +427,13 @@ static bool open_fifos(const char* base, int fd[2])
 | 
			
		|||
		LOG_ERROR("%s is not a fifo", fifo.c_str());
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	if ((fd[0] = open(fifo.c_str(), O_RDONLY | O_NONBLOCK)) == -1) {
 | 
			
		||||
 | 
			
		||||
	int oflags = O_RDONLY | O_NONBLOCK;
 | 
			
		||||
#	ifdef HAVE_O_CLOEXEC
 | 
			
		||||
		oflags = oflags | O_CLOEXEC;
 | 
			
		||||
#	endif
 | 
			
		||||
 | 
			
		||||
	if ((fd[0] = open(fifo.c_str(), oflags)) == -1) {
 | 
			
		||||
		LOG_ERROR("Could not open %s: %s", fifo.c_str(), strerror(errno));
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -428,7 +444,13 @@ static bool open_fifos(const char* base, int fd[2])
 | 
			
		|||
		LOG_ERROR("%s is not a fifo", fifo.c_str());
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	if ((fd[1] = open(fifo.c_str(), O_WRONLY | O_NONBLOCK)) == -1) {
 | 
			
		||||
	oflags = O_WRONLY | O_NONBLOCK;
 | 
			
		||||
 | 
			
		||||
#	ifdef HAVE_O_CLOEXEC
 | 
			
		||||
		oflags = oflags | O_CLOEXEC;
 | 
			
		||||
#	endif
 | 
			
		||||
 | 
			
		||||
	if ((fd[1] = open(fifo.c_str(), oflags)) == -1) {
 | 
			
		||||
		LOG_ERROR("Could not open %s: %s", fifo.c_str(), strerror(errno));
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -301,7 +301,7 @@ static void *rigMEM_loop(void *args)
 | 
			
		|||
			break;
 | 
			
		||||
 | 
			
		||||
		if (TogglePTT || rig_qsy || change_mode) {
 | 
			
		||||
			IOout = fopen("c:/RIGCTL/ptt", "w");
 | 
			
		||||
			IOout = fopen("c:/RIGCTL/ptt", "we");
 | 
			
		||||
			if (IOout) {
 | 
			
		||||
				LOG_VERBOSE("sent %d, %c, %s",
 | 
			
		||||
					 (int)qsy_f,
 | 
			
		||||
| 
						 | 
				
			
			@ -318,7 +318,7 @@ static void *rigMEM_loop(void *args)
 | 
			
		|||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		IOin = fopen("c:/RIGCTL/rig", "r");
 | 
			
		||||
		IOin = fopen("c:/RIGCTL/rig", "re");
 | 
			
		||||
		if (IOin) {
 | 
			
		||||
			fscanf(IOin, "%ld\n", &IOfreq);
 | 
			
		||||
			fscanf(IOin, "%s", szmode);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,7 +71,13 @@ bool Cserial::OpenPort()  {
 | 
			
		|||
#ifdef __CYGWIN__
 | 
			
		||||
	com_to_tty(device);
 | 
			
		||||
#endif
 | 
			
		||||
	if ((fd = open( device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY)) < 0)
 | 
			
		||||
 | 
			
		||||
	int oflags = O_RDWR | O_NOCTTY | O_NDELAY;
 | 
			
		||||
#	ifdef HAVE_O_CLOEXEC
 | 
			
		||||
		oflags = oflags | O_CLOEXEC;
 | 
			
		||||
#	endif
 | 
			
		||||
 | 
			
		||||
	if ((fd = open( device.c_str(), oflags)) < 0)
 | 
			
		||||
		return false;
 | 
			
		||||
// save current port settings
 | 
			
		||||
	tcflush (fd, TCIFLUSH);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,7 +73,13 @@ void MixerOSS::openMixer(const char *dev)
 | 
			
		|||
	if (mixer_fd != -1) closeMixer();
 | 
			
		||||
	mixer = dev;
 | 
			
		||||
	try {
 | 
			
		||||
		mixer_fd =  open(mixer.c_str(), O_RDWR);
 | 
			
		||||
 | 
			
		||||
	int oflags = O_RDWR;
 | 
			
		||||
#	ifdef HAVE_O_CLOEXEC
 | 
			
		||||
		oflags = oflags | O_CLOEXEC;
 | 
			
		||||
#	endif
 | 
			
		||||
 | 
			
		||||
		mixer_fd =  open(mixer.c_str(), oflags);
 | 
			
		||||
		if (mixer_fd == -1)
 | 
			
		||||
			throw MixerException(errno);
 | 
			
		||||
		if ((err = initMask()) != 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -144,7 +150,12 @@ void MixerOSS::findNumMixers()
 | 
			
		|||
			szDevice[10] = 0;
 | 
			
		||||
		else
 | 
			
		||||
			szDevice[10] = '0'+(i-1);
 | 
			
		||||
		fd = open(szDevice, O_RDWR);
 | 
			
		||||
		int oflags = O_RDWR;
 | 
			
		||||
#		ifdef HAVE_O_CLOEXEC
 | 
			
		||||
			oflags = oflags | O_CLOEXEC;
 | 
			
		||||
#		endif
 | 
			
		||||
 | 
			
		||||
		fd = open(szDevice, oflags);
 | 
			
		||||
		if (fd >= 0) {
 | 
			
		||||
			Devices[NumMixers] = i;
 | 
			
		||||
			NumMixers++;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -399,7 +399,12 @@ int SoundOSS::Open(int md, int freq)
 | 
			
		|||
 | 
			
		||||
	mode = md;
 | 
			
		||||
	try {
 | 
			
		||||
		device_fd = open(device.c_str(), mode, 0);
 | 
			
		||||
		int oflags = md;
 | 
			
		||||
#		ifdef HAVE_O_CLOEXEC
 | 
			
		||||
			oflags = oflags | O_CLOEXEC;
 | 
			
		||||
#		endif
 | 
			
		||||
 | 
			
		||||
		device_fd = open(device.c_str(), oflags, 0);
 | 
			
		||||
		if (device_fd == -1)
 | 
			
		||||
			throw SndException(errno);
 | 
			
		||||
		Format(AFMT_S16_LE);	// default: 16 bit little endian
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue