From 170ff458a47b7b991999bfca013d006034ca875e Mon Sep 17 00:00:00 2001
From: Alec Leamas <leamas.alec@gmail.com>
Date: Fri, 1 May 2015 14:11:56 +0200
Subject: [PATCH] Convert strcpy to strncpy (bz #1208453):
---
src/SerialImp.c | 135 ++++++++++++++++++++++++++++----------------------------
1 file changed, 67 insertions(+), 68 deletions(-)
diff --git a/src/SerialImp.c b/src/SerialImp.c
index 8766c31..a6caa85 100644
--- a/src/SerialImp.c
+++ b/src/SerialImp.c
@@ -153,7 +153,6 @@ extern int errno;
JavaVM *javaVM = NULL;
-
struct preopened *preopened_port = NULL;
/* this is so diff will not generate noise when merging 1.4 and 1.5 changes
@@ -290,7 +289,7 @@ JNIEXPORT void JNICALL RXTXPort(Initialize)(
}
if(strcmp(name.release,UTS_RELEASE)!=0)
{
- sprintf( message, LINUX_KERNEL_VERSION_ERROR, UTS_RELEASE,
+ snprintf( message, sizeof(message), LINUX_KERNEL_VERSION_ERROR, UTS_RELEASE,
name.release );
report( message );
getchar();
@@ -641,14 +640,14 @@ JNIEXPORT jint JNICALL RXTXPort(open)(
ENTER( "RXTXPort:open" );
if ( LOCK( filename, pid ) )
{
- sprintf( message, "open: locking has failed for %s\n",
+ snprintf( message, sizeof(message), "open: locking has failed for %s\n",
filename );
report( message );
goto fail;
}
else
{
- sprintf( message, "open: locking worked for %s\n", filename );
+ snprintf( message, sizeof(message), "open: locking worked for %s\n", filename );
report( message );
}
/* This is used so DTR can remain low on 'open()' */
@@ -674,7 +673,7 @@ JNIEXPORT jint JNICALL RXTXPort(open)(
if (fd >= 0 && (ioctl(fd, TIOCEXCL) == -1))
{
- sprintf( message, "open: exclusive access denied for %s\n",
+ snprintf( message, sizeof(message), "open: exclusive access denied for %s\n",
filename );
report( message );
report_error( message );
@@ -686,7 +685,7 @@ JNIEXPORT jint JNICALL RXTXPort(open)(
if( configure_port( fd ) ) goto fail;
(*env)->ReleaseStringUTFChars( env, jstr, filename );
- sprintf( message, "open: fd returned is %i\n", fd );
+ snprintf( message, sizeof(message), "open: fd returned is %i\n", fd );
report( message );
LEAVE( "RXTXPort:open" );
report_time_end( );
@@ -1270,7 +1269,7 @@ void *drain_loop( void *arg )
if( eis && eis->writing )
{
/*
- sprintf(msg, "drain_loop: setting OUTPUT_BUFFER_EMPTY\n" );
+ snprintf( msg, sizeof(msg), "drain_loop: setting OUTPUT_BUFFER_EMPTY\n" );
report( msg );
*/
eis->output_buffer_empty_flag = 1;
@@ -1338,7 +1337,7 @@ static void warn_sig_abort( int signo )
{
/*
char msg[80];
- sprintf( msg, "RXTX Recieved Signal %i\n", signo );
+ snprintf( msg, sizeof(msg), "RXTX Recieved Signal %i\n", signo );
report_error( msg );
*/
}
@@ -1440,7 +1439,7 @@ JNIEXPORT void JNICALL RXTXPort(writeByte)( JNIEnv *env,
report_time_start();
ENTER( "RXTXPort:writeByte" );
do {
- sprintf( msg, "writeByte %c>>\n", byte );
+ snprintf( msg, sizeof(msg), "writeByte %c>>\n", byte );
report( msg );
result=WRITE (fd, (void * ) &byte, sizeof(unsigned char));
} while (result < 0 && errno==EINTR);
@@ -1470,7 +1469,7 @@ JNIEXPORT void JNICALL RXTXPort(writeByte)( JNIEnv *env,
report( "writeByte: index->writing = 1" );
}
#endif
- sprintf( msg, "RXTXPort:writeByte %i\n", result );
+ snprintf( msg, sizeof(msg), "RXTXPort:writeByte %i\n", result );
report( msg );
LEAVE( "RXTXPort:writeByte" );
if(result >= 0)
@@ -1526,7 +1525,7 @@ JNIEXPORT void JNICALL RXTXPort(writeArray)( JNIEnv *env,
ENTER( "writeArray" );
/* warning Roy Rogers */
/*
- sprintf( message, "::::RXTXPort:writeArray(%s);\n", (char *) body );
+ snprintf( message, sizeof(message), "::::RXTXPort:writeArray(%s);\n", (char *) body );
report_verbose( message );
*/
@@ -1612,7 +1611,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(nativeDrain)( JNIEnv *env,
count++;
} while (result && errno==EINTR && count <3);
- sprintf( message, "RXTXPort:drain() returns: %i\n", result );
+ snprintf( message, sizeof(message), "RXTXPort:drain() returns: %i\n", result );
report_verbose( message );
#if defined(__sun__)
/* FIXME: No time to test on all OS's for production */
@@ -1730,7 +1729,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(isDSR)( JNIEnv *env,
ENTER( "RXTXPort:isDSR" );
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "RXTXPort:isDSR returns %i\n", result & TIOCM_DSR );
+ snprintf( message, sizeof(message), "RXTXPort:isDSR returns %i\n", result & TIOCM_DSR );
report( message );
LEAVE( "RXTXPort:isDSR" );
if( result & TIOCM_DSR ) return JNI_TRUE;
@@ -1760,7 +1759,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(isCD)( JNIEnv *env,
ENTER( "RXTXPort:isCD" );
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "RXTXPort:isCD returns %i\n", result & TIOCM_CD );
+ snprintf( message, sizeof(message), "RXTXPort:isCD returns %i\n", result & TIOCM_CD );
LEAVE( "RXTXPort:isCD" );
if( result & TIOCM_CD ) return JNI_TRUE;
else return JNI_FALSE;
@@ -1785,7 +1784,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(isCTS)( JNIEnv *env,
ENTER( "RXTXPort:isCTS" );
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "RXTXPort:isCTS returns %i\n", result & TIOCM_CTS );
+ snprintf( message, sizeof(message), "RXTXPort:isCTS returns %i\n", result & TIOCM_CTS );
report( message );
LEAVE( "RXTXPort:isCTS" );
if( result & TIOCM_CTS ) return JNI_TRUE;
@@ -1811,7 +1810,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(isRI)( JNIEnv *env,
ENTER( "RXTXPort:isRI" );
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "RXTXPort:isRI returns %i\n", result & TIOCM_RI );
+ snprintf( message, sizeof(message), "RXTXPort:isRI returns %i\n", result & TIOCM_RI );
report( message );
LEAVE( "RXTXPort:isRI" );
if( result & TIOCM_RI ) return JNI_TRUE;
@@ -1837,7 +1836,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(isRTS)( JNIEnv *env,
ENTER( "RXTXPort:isRTS" );
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "RXTXPort:isRTS returns %i\n", result & TIOCM_RTS );
+ snprintf( message, sizeof(message), "RXTXPort:isRTS returns %i\n", result & TIOCM_RTS );
report( message );
LEAVE( "RXTXPort:isRTS" );
if( result & TIOCM_RTS ) return JNI_TRUE;
@@ -1867,7 +1866,7 @@ JNIEXPORT void JNICALL RXTXPort(setRTS)( JNIEnv *env,
if( state == JNI_TRUE ) result |= TIOCM_RTS;
else result &= ~TIOCM_RTS;
ioctl( fd, TIOCMSET, &result );
- sprintf( message, "setRTS( %i )\n", state );
+ snprintf( message, sizeof(message), "setRTS( %i )\n", state );
report( message );
LEAVE( "RXTXPort:setRTS" );
return;
@@ -1894,11 +1893,11 @@ JNIEXPORT void JNICALL RXTXPort(setDSR)( JNIEnv *env,
ENTER( "RXTXPort:setDSR()" );
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "setDSR( %i )\n", state );
+ snprintf( message, sizeof(message), "setDSR( %i )\n", state );
if( state == JNI_TRUE ) result |= TIOCM_DSR;
else result &= ~TIOCM_DSR;
ioctl( fd, TIOCMSET, &result );
- sprintf( message, "setDSR( %i )\n", state );
+ snprintf( message, sizeof(message), "setDSR( %i )\n", state );
report( message );
LEAVE( "RXTXPort:setDSR()" );
return;
@@ -1923,7 +1922,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(isDTR)( JNIEnv *env,
ENTER( "RXTXPort:isDTR" );
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "isDTR( ) returns %i\n", result& TIOCM_DTR );
+ snprintf( message, sizeof(message), "isDTR( ) returns %i\n", result& TIOCM_DTR );
report( message );
LEAVE( "RXTXPort:isDTR" );
if( result & TIOCM_DTR ) return JNI_TRUE;
@@ -1952,7 +1951,7 @@ JNIEXPORT void JNICALL RXTXPort(setDTR)( JNIEnv *env,
if( state == JNI_TRUE ) result |= TIOCM_DTR;
else result &= ~TIOCM_DTR;
ioctl( fd, TIOCMSET, &result );
- sprintf( message, "setDTR( %i )\n", state );
+ snprintf( message, sizeof(message), "setDTR( %i )\n", state );
report( message );
LEAVE( "RXTXPort:setDTR" );
return;
@@ -2491,7 +2490,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsRTS)( JNIEnv *env,
return JNI_FALSE;
}
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "nativeStaticIsRTS( ) returns %i\n", result& TIOCM_RTS );
+ snprintf( message, sizeof(message), "nativeStaticIsRTS( ) returns %i\n", result& TIOCM_RTS );
report( message );
LEAVE( "RXTXPort:nativeStaticIsRTS" );
if( result & TIOCM_RTS ) return JNI_TRUE;
@@ -2523,7 +2522,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsDSR)( JNIEnv *env,
return JNI_FALSE;
}
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "nativeStaticIsDSR( ) returns %i\n", result& TIOCM_DSR );
+ snprintf( message, sizeof(message), "nativeStaticIsDSR( ) returns %i\n", result& TIOCM_DSR );
report( message );
LEAVE( "RXTXPort:nativeStaticIsDSR" );
if( result & TIOCM_DSR ) return JNI_TRUE;
@@ -2555,7 +2554,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsDTR)( JNIEnv *env,
return JNI_FALSE;
}
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "nativeStaticIsDTR( ) returns %i\n", result& TIOCM_DTR );
+ snprintf( message, sizeof(message), "nativeStaticIsDTR( ) returns %i\n", result& TIOCM_DTR );
report( message );
LEAVE( "RXTXPort:nativeStaticIsDTR" );
if( result & TIOCM_DTR ) return JNI_TRUE;
@@ -2587,7 +2586,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsCD)( JNIEnv *env,
return JNI_FALSE;
}
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "nativeStaticIsCD( ) returns %i\n", result& TIOCM_CD );
+ snprintf( message, sizeof(message), "nativeStaticIsCD( ) returns %i\n", result& TIOCM_CD );
report( message );
LEAVE( "RXTXPort:nativeStaticIsCD" );
if( result & TIOCM_CD ) return JNI_TRUE;
@@ -2619,7 +2618,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsCTS)( JNIEnv *env,
return JNI_FALSE;
}
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "nativeStaticIsCTS( ) returns %i\n", result& TIOCM_CTS );
+ snprintf( message, sizeof(message), "nativeStaticIsCTS( ) returns %i\n", result& TIOCM_CTS );
report( message );
LEAVE( "RXTXPort:nativeStaticIsCTS" );
if( result & TIOCM_CTS ) return JNI_TRUE;
@@ -2651,7 +2650,7 @@ JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsRI)( JNIEnv *env,
return JNI_FALSE;
}
ioctl( fd, TIOCMGET, &result );
- sprintf( message, "nativeStaticRI( ) returns %i\n", result& TIOCM_RI );
+ snprintf( message, sizeof(message), "nativeStaticRI( ) returns %i\n", result& TIOCM_RI );
report( message );
LEAVE( "RXTXPort:nativeStaticIsRI" );
if( result & TIOCM_RI ) return JNI_TRUE;
@@ -3023,7 +3022,7 @@ int read_byte_array( JNIEnv *env,
eis->eventflags[SPE_DATA_AVAILABLE] = 0;
/*
ENTER( "read_byte_array" );
- sprintf(msg, "read_byte_array requests %i\n", length);
+ snprintf( msg, sizeof(msg), "read_byte_array requests %i\n", length);
report( msg );
*/
left = length;
@@ -3106,7 +3105,7 @@ int read_byte_array( JNIEnv *env,
"No data available" );
}
- sprintf(msg, "read_byte_array returns %i\n", bytes);
+ snprintf( msg, sizeof(msg), "read_byte_array returns %i\n", bytes);
report( msg );
LEAVE( "read_byte_array" );
report_time_end();
@@ -3129,7 +3128,7 @@ int read_byte_array( JNIEnv *env,
report_time_start();
ENTER( "read_byte_array" );
- sprintf(msg, "read_byte_array requests %i\n", length);
+ snprintf( msg, sizeof(msg), "read_byte_array requests %i\n", length);
report( msg );
left = length;
if (timeout >= 0)
@@ -3152,7 +3151,7 @@ RETRY: if ((ret = READ( fd, buffer + bytes, left )) < 0 )
bytes += ret;
left -= ret;
}
- sprintf(msg, "read_byte_array returns %i\n", bytes);
+ snprintf( msg, sizeof(msg), "read_byte_array returns %i\n", bytes);
report( msg );
LEAVE( "read_byte_array" );
report_time_end();
@@ -3436,7 +3435,7 @@ JNIEXPORT jint JNICALL RXTXPort(readByte)( JNIEnv *env,
}
/*
LEAVE( "RXTXPort:readByte" );
- sprintf( msg, "readByte return(%i)\n", bytes ? buffer[ 0 ] : -1 );
+ snprintf( msg, sizeof(msg), "readByte return(%i)\n", bytes ? buffer[ 0 ] : -1 );
report( msg );
report_time_end( );
*/
@@ -3490,7 +3489,7 @@ JNIEXPORT jint JNICALL RXTXPort(readArray)( JNIEnv *env,
return -1;
}
/*
- sprintf( msg, "RXTXPort:readArray: %i %i\n", (int) length, bytes);
+ snprintf( msg, sizeof(msg), "RXTXPort:readArray: %i %i\n", (int) length, bytes);
report( msg );
report_time_end( );
LEAVE( "RXTXPort:readArray" );
@@ -3580,7 +3579,7 @@ JNIEXPORT jint JNICALL RXTXPort(readTerminatedArray)( JNIEnv *env,
} while ( bytes > 0 && total < length );
(*env)->ReleaseByteArrayElements( env, jbarray, body, 0 );
/*
- sprintf( msg, "RXTXPort:readArray: %i %i\n", (int) length, bytes);
+ snprintf( msg, sizeof(msg), "RXTXPort:readArray: %i %i\n", (int) length, bytes);
report( msg );
report_time_end( );
LEAVE( "RXTXPort:readArray" );
@@ -3865,7 +3864,7 @@ int port_has_changed_fionread( struct event_info_struct *eis )
char message[80];
rc = ioctl( eis->fd, FIONREAD, &change );
- sprintf( message, "port_has_changed_fionread: change is %i ret is %i\n", change, eis->ret );
+ snprintf( message, sizeof(message), "port_has_changed_fionread: change is %i ret is %i\n", change, eis->ret );
report_verbose( message );
#if defined(__unixware__) || defined(__sun__)
/*
@@ -4285,7 +4284,7 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)(
if( !strcmp( name, "COM1" ) || !strcmp( name, "COM2") )
{
printf("%s is good\n",name);
- sprintf( message, "testRead: %s is good!\n", name );
+ snprintf( message, sizeof(message), "testRead: %s is good!\n", name );
report( message );
(*env)->ReleaseStringUTFChars( env, tty_name, name );
return( JNI_TRUE );
@@ -4631,7 +4630,7 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(registerKnownPorts)(JNIEnv *env,
case PORT_TYPE_RS485: break;
case PORT_TYPE_RAW: break;
default:
- sprintf( message, "unknown portType %d handed to \
+ snprintf( message, sizeof(message), "unknown portType %d handed to \
native RXTXCommDriver.registerKnownPorts() \
method.\n",
(int) portType
@@ -5144,7 +5143,7 @@ int lfs_lock( const char *filename, int pid )
if ( !connect( s, ( struct sockaddr * ) &addr, sizeof( addr ) ) == 0 )
return 1;
ret=recv( s, buffer, size, 0 );
- sprintf( buffer, "lock %s %i\n", filename, pid );
+ snprintf( buffer, size, "lock %s %i\n", filename, pid );
/* printf( "%s", buffer ); */
send( s, buffer, strlen(buffer), 0 );
ret=recv( s, buffer, size, 0 );
@@ -5187,7 +5186,7 @@ int lfs_unlock( const char *filename, int pid )
if ( !connect( s, ( struct sockaddr * ) &addr, sizeof( addr ) ) == 0 )
return 1;
- sprintf( buffer, "unlock %s %i\n", filename, pid );
+ snprintf( buffer, size, "unlock %s %i\n", filename, pid );
/* printf( "%s", buffer ); */
send( s, buffer, strlen(buffer), 0 );
ret = recv( s, buffer, size, 0 );
@@ -5256,7 +5255,7 @@ int lib_lock_dev_lock( const char *filename, int pid )
}
if ( dev_lock( filename ) )
{
- sprintf( message,
+ snprintf( message, sizeof(message),
"RXTX fhs_lock() Error: creating lock file for: %s: %s\n",
filename, strerror(errno) );
report_error( message );
@@ -5307,7 +5306,7 @@ int fhs_lock( const char *filename, int pid )
#endif /* __unixware__ */
p--;
}
- sprintf( file, "%s/LCK..%s", LOCKDIR, p );
+ snprintf( file, sizeof(file), "%s/LCK..%s", LOCKDIR, p );
if ( check_lock_status( filename ) )
{
report( "fhs_lock() lockstatus fail\n" );
@@ -5316,18 +5315,18 @@ int fhs_lock( const char *filename, int pid )
fd = open( file, O_CREAT | O_WRONLY | O_EXCL, 0444 );
if( fd < 0 )
{
- sprintf( message,
+ snprintf( message, sizeof(message),
"RXTX fhs_lock() Error: opening lock file: %s: %s\n",
file, strerror(errno) );
report_error( message );
return 1;
}
sprintf( lockinfo, "%10d\n",(int) getpid() );
- sprintf( message, "fhs_lock: creating lockfile: %s\n", lockinfo );
+ snprintf( message, sizeof(message), "fhs_lock: creating lockfile: %s\n", lockinfo );
report( message );
if( ( write( fd, lockinfo, 11 ) ) < 0 )
{
- sprintf( message,
+ snprintf( message, sizeof(message),
"RXTX fhs_lock() Error: writing lock file: %s: %s\n",
file, strerror(errno) );
report_error( message );
@@ -5387,7 +5386,7 @@ int uucp_lock( const char *filename, int pid )
int fd;
struct stat buf;
- sprintf( message, "uucp_lock( %s );\n", filename );
+ snprintf( message, sizeof(message), "uucp_lock( %s );\n", filename );
report( message );
if ( check_lock_status( filename ) )
@@ -5403,11 +5402,11 @@ int uucp_lock( const char *filename, int pid )
if ( stat( filename, &buf ) != 0 )
{
report( "RXTX uucp_lock() could not find device.\n" );
- sprintf( message, "uucp_lock: device was %s\n", name );
+ snprintf( message, sizeof(message), "uucp_lock: device was %s\n", name );
report( message );
return 1;
}
- sprintf( lockfilename, "%s/LK.%03d.%03d.%03d",
+ snprintf( lockfilename, sizeof(lockfilename), "%s/LK.%03d.%03d.%03d",
LOCKDIR,
(int) major( buf.st_dev ),
(int) major( buf.st_rdev ),
@@ -5416,7 +5415,7 @@ int uucp_lock( const char *filename, int pid )
sprintf( lockinfo, "%10d\n", (int) getpid() );
if ( stat( lockfilename, &buf ) == 0 )
{
- sprintf( message, "RXTX uucp_lock() %s is there\n",
+ snprintf( message, sizeof(message), "RXTX uucp_lock() %s is there\n",
lockfilename );
report( message );
report_error( message );
@@ -5425,7 +5424,7 @@ int uucp_lock( const char *filename, int pid )
fd = open( lockfilename, O_CREAT | O_WRONLY | O_EXCL, 0444 );
if( fd < 0 )
{
- sprintf( message,
+ snprintf( message, sizeof(message),
"RXTX uucp_lock() Error: opening lock file: %s: %s\n",
lockfilename, strerror(errno) );
report_error( message );
@@ -5433,7 +5432,7 @@ int uucp_lock( const char *filename, int pid )
}
if( ( write( fd, lockinfo, 11 ) ) < 0 )
{
- sprintf( message,
+ snprintf( message, sizeof(message),
"RXTX uucp_lock() Error: writing lock file: %s: %s\n",
lockfilename, strerror(errno) );
report_error( message );
@@ -5503,7 +5502,7 @@ void fhs_unlock( const char *filename, int openpid )
p = ( char * ) filename + i;
/* FIXME need to handle subdirectories /dev/cua/... */
while( *( p - 1 ) != '/' && i-- != 1 ) p--;
- sprintf( file, "%s/LCK..%s", LOCKDIR, p );
+ snprintf( file, sizeof(file), "%s/LCK..%s", LOCKDIR, p );
if( !check_lock_pid( file, openpid ) )
{
@@ -5531,7 +5530,7 @@ void uucp_unlock( const char *filename, int openpid )
char file[80], message[80];
/* FIXME */
- sprintf( message, "uucp_unlock( %s );\n", filename );
+ snprintf( message, sizeof(message), "uucp_unlock( %s );\n", filename );
report( message );
if ( stat( filename, &buf ) != 0 )
@@ -5540,7 +5539,7 @@ void uucp_unlock( const char *filename, int openpid )
report( "uucp_unlock() no such device\n" );
return;
}
- sprintf( file, LOCKDIR"/LK.%03d.%03d.%03d",
+ snprintf( file, sizeof(file), LOCKDIR"/LK.%03d.%03d.%03d",
(int) major( buf.st_dev ),
(int) major( buf.st_rdev ),
(int) minor( buf.st_rdev )
@@ -5553,13 +5552,13 @@ void uucp_unlock( const char *filename, int openpid )
}
if( !check_lock_pid( file, openpid ) )
{
- sprintf( message, "uucp_unlock: unlinking %s\n", file );
+ snprintf( message, sizeof(message), "uucp_unlock: unlinking %s\n", file );
report( message );
unlink(file);
}
else
{
- sprintf( message, "uucp_unlock: unlinking failed %s\n", file );
+ snprintf( message, sizeof(message), "uucp_unlock: unlinking failed %s\n", file );
report( message );
}
}
@@ -5595,7 +5594,7 @@ int check_lock_pid( const char *file, int openpid )
/* Native threads JVM's have multiple pids */
if ( lockpid != getpid() && lockpid != getppid() && lockpid != openpid )
{
- sprintf(message, "check_lock_pid: lock = %s pid = %i gpid=%i openpid=%i\n",
+ snprintf(message, sizeof(message), "check_lock_pid: lock = %s pid = %i gpid=%i openpid=%i\n",
pid_buffer, (int) getpid(), (int) getppid(), openpid );
report( message );
return( 1 );
@@ -5688,7 +5687,7 @@ int check_group_uucp()
if( stat( LOCKDIR, &buf) )
{
- sprintf( msg, "check_group_uucp: Can not find Lock Directory: %s\n", LOCKDIR );
+ snprintf( msg, sizeof(msg), "check_group_uucp: Can not find Lock Directory: %s\n", LOCKDIR );
report_error( msg );
return( 1 );
}
@@ -5712,7 +5711,7 @@ int check_group_uucp()
}
if( buf.st_gid == list[ group_count ] )
return 0;
- sprintf( msg, "%i %i\n", buf.st_gid, list[ group_count ] );
+ snprintf( msg, sizeof(msg), "%i %i\n", buf.st_gid, list[ group_count ] );
report_error( msg );
report_error( UUCP_ERROR );
return 1;
@@ -5827,11 +5826,11 @@ int is_device_locked( const char *port_filename )
while ( lockprefixes[k] )
{
/* FHS style */
- sprintf( file, "%s/%s%s", lockdirs[i],
+ snprintf( file, sizeof(file), "%s/%s%s", lockdirs[i],
lockprefixes[k], p );
if( stat( file, &buf ) == 0 )
{
- sprintf( message, UNEXPECTED_LOCK_FILE,
+ snprintf( message, sizeof(message), UNEXPECTED_LOCK_FILE,
file );
report_warning( message );
return 1;
@@ -5839,7 +5838,7 @@ int is_device_locked( const char *port_filename )
/* UUCP style */
stat(port_filename , &buf );
- sprintf( file, "%s/%s%03d.%03d.%03d",
+ snprintf( file, sizeof(file), "%s/%s%03d.%03d.%03d",
lockdirs[i],
lockprefixes[k],
(int) major( buf.st_dev ),
@@ -5848,7 +5847,7 @@ int is_device_locked( const char *port_filename )
);
if( stat( file, &buf ) == 0 )
{
- sprintf( message, UNEXPECTED_LOCK_FILE,
+ snprintf( message, sizeof(message), UNEXPECTED_LOCK_FILE,
file );
report_warning( message );
return 1;
@@ -5876,7 +5875,7 @@ int is_device_locked( const char *port_filename )
#endif /* __unixware__ */
p--;
}
- sprintf( file, "%s/%s%s", LOCKDIR, LOCKFILEPREFIX, p );
+ snprintf( file, sizeof(file), "%s/%s%s", LOCKDIR, LOCKFILEPREFIX, p );
#else
/* UUCP standard locks */
if ( stat( port_filename, &buf ) != 0 )
@@ -5884,7 +5883,7 @@ int is_device_locked( const char *port_filename )
report( "RXTX is_device_locked() could not find device.\n" );
return 1;
}
- sprintf( file, "%s/LK.%03d.%03d.%03d",
+ snprintf( file, sizeof(file), "%s/LK.%03d.%03d.%03d",
LOCKDIR,
(int) major( buf.st_dev ),
(int) major( buf.st_rdev ),
@@ -5900,7 +5899,7 @@ int is_device_locked( const char *port_filename )
fd=open( file, O_RDONLY );
if( fd < 0 )
{
- sprintf( message,
+ snprintf( message, sizeof(message),
"RXTX is_device_locked() Error: opening lock file: %s: %s\n",
file, strerror(errno) );
report_warning( message );
@@ -5908,7 +5907,7 @@ int is_device_locked( const char *port_filename )
}
if ( ( read( fd, pid_buffer, 11 ) ) < 0 )
{
- sprintf( message,
+ snprintf( message, sizeof(message),
"RXTX is_device_locked() Error: reading lock file: %s: %s\n",
file, strerror(errno) );
report_warning( message );
@@ -5921,7 +5920,7 @@ int is_device_locked( const char *port_filename )
if( kill( (pid_t) pid, 0 ) && errno==ESRCH )
{
- sprintf( message,
+ snprintf( message, sizeof(message),
"RXTX Warning: Removing stale lock file. %s\n",
file );
report_warning( message );
--
2.1.0