| 1 |
Fromscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/patches/`fix_snprintf.patch`#From.: Jose Luis Guardiola <[email protected]scip-debian . . . identity/`[email protected]`.> |
| 2 |
Forwardedscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/patches/`fix_snprintf.patch`#Forwarded.: no |
| 3 |
Descriptionscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/patches/`fix_snprintf.patch`#Description.: replace s[n]printf with asprintf/free |
| 4 |
Bug-Debianscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/patches/`fix_snprintf.patch`#Bug-Debian.: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=731151 |
| 5 |
|
| 6 |
--- a/src/SerialImp.cscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/upstream/`src/SerialImp.c`: |
| 7 |
+++ b/src/SerialImp.cscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/upstream/`src/SerialImp.c`: |
| 8 |
@@ -5827,7 +5827,7 @@ |
| 9 |
LOCKDIR, NULL |
| 10 |
}; |
| 11 |
const char *lockprefixes[] = { "LCK..", "lk..", "LK.", NULL }; |
| 12 |
|
| 13 |
+ char *p, *file, pid_buffer[20], *message; |
| 14 |
int i = 0, j, k, fd , pid; |
| 15 |
struct stat buf, buf2, lockbuf; |
| 16 |
|
| 17 |
@@ -5868,19 +5868,22 @@ |
| 18 |
while ( lockprefixes[k] ) |
| 19 |
{ |
| 20 |
/* FHS style */ |
| 21 |
|
| 22 |
+ asprintf( &file, "%s/%s%s", lockdirs[i], |
| 23 |
lockprefixes[k], p ); |
| 24 |
if( stat( file, &buf ) == 0 ) |
| 25 |
{ |
| 26 |
|
| 27 |
+ asprintf( &message, UNEXPECTED_LOCK_FILE, |
| 28 |
file ); |
| 29 |
report_warning( message ); |
| 30 |
+ free( message ); |
| 31 |
+ free( file ); |
| 32 |
return 1; |
| 33 |
} |
| 34 |
+ free( file ); |
| 35 |
|
| 36 |
/* UUCP style */ |
| 37 |
stat(port_filename , &buf ); |
| 38 |
|
| 39 |
+ asprintf( &file, "%s/%s%03d.%03d.%03d", |
| 40 |
lockdirs[i], |
| 41 |
lockprefixes[k], |
| 42 |
(int) major( buf.st_dev ), |
| 43 |
@@ -5889,11 +5892,14 @@ |
| 44 |
); |
| 45 |
if( stat( file, &buf ) == 0 ) |
| 46 |
{ |
| 47 |
|
| 48 |
+ asprintf( &message, UNEXPECTED_LOCK_FILE, |
| 49 |
file ); |
| 50 |
report_warning( message ); |
| 51 |
+ free( message ); |
| 52 |
+ free( file ); |
| 53 |
return 1; |
| 54 |
} |
| 55 |
+ free( file ); |
| 56 |
k++; |
| 57 |
} |
| 58 |
} |
| 59 |
@@ -5917,7 +5923,7 @@ |
| 60 |
#endif /* __unixware__ */ |
| 61 |
p--; |
| 62 |
} |
| 63 |
|
| 64 |
+ asprintf( &file, "%s/%s%s", LOCKDIR, LOCKFILEPREFIX, p ); |
| 65 |
#else |
| 66 |
/* UUCP standard locks */ |
| 67 |
if ( stat( port_filename, &buf ) != 0 ) |
| 68 |
@@ -5925,7 +5931,7 @@ |
| 69 |
report( "RXTX is_device_locked() could not find device.\n" ); |
| 70 |
return 1; |
| 71 |
} |
| 72 |
|
| 73 |
+ asprintf( &file, "%s/LK.%03d.%03d.%03d", |
| 74 |
LOCKDIR, |
| 75 |
(int) major( buf.st_dev ), |
| 76 |
(int) major( buf.st_rdev ), |
| 77 |
@@ -5946,21 +5952,25 @@ |
| 78 |
|
| 79 |
if( kill( (pid_t) pid, 0 ) && errno==ESRCH ) |
| 80 |
{ |
| 81 |
|
| 82 |
+ asprintf( &message, |
| 83 |
"RXTX Warning: Removing stale lock file. %s\n", |
| 84 |
file ); |
| 85 |
report_warning( message ); |
| 86 |
+ free( message ); |
| 87 |
if( unlink( file ) != 0 ) |
| 88 |
{ |
| 89 |
|
| 90 |
+ asprintf( &message, "RXTX Error: Unable to \ |
| 91 |
remove stale lock file: %s\n", |
| 92 |
file |
| 93 |
); |
| 94 |
report_warning( message ); |
| 95 |
+ free( message ); |
| 96 |
+ free( file ); |
| 97 |
return 1; |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
+ free(file); |
| 102 |
return 0; |
| 103 |
} |
| 104 |
#endif /* WIN32 */ |
| 105 |
--- a/src/lfd/lockdaemon.cscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/upstream/`src/lfd/lockdaemon.c`: |
| 106 |
+++ b/src/lfd/lockdaemon.cscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/upstream/`src/lfd/lockdaemon.c`: |
| 107 |
@@ -120,8 +120,8 @@ |
| 108 |
* |
| 109 |
*/ |
| 110 |
int fd,j; |
| 111 |
|
| 112 |
|
| 113 |
+ char lockinfo[12]; |
| 114 |
+ char *file, *p, *message; |
| 115 |
|
| 116 |
j = strlen( filename ); |
| 117 |
p = ( char * ) filename + j; |
| 118 |
@@ -136,24 +136,28 @@ |
| 119 |
#endif /* __unixware__ */ |
| 120 |
p--; |
| 121 |
} |
| 122 |
|
| 123 |
if ( check_lock_status( filename ) ) |
| 124 |
{ |
| 125 |
/* syslog( LOG_INFO, "fhs_lock() lockstatus fail\n" ); */ |
| 126 |
return 1; |
| 127 |
} |
| 128 |
+ asprintf( &file, "%s/LCK..%s", LOCKDIR, p ); |
| 129 |
fd = open( file, O_CREAT | O_WRONLY | O_EXCL, 0444 ); |
| 130 |
if( fd < 0 ) |
| 131 |
{ |
| 132 |
|
| 133 |
+ asprintf( &message, |
| 134 |
"RXTX fhs_lock() Error: creating lock file: %s: %s\n", |
| 135 |
file, strerror(errno) ); |
| 136 |
syslog( LOG_INFO, message ); |
| 137 |
+ free(message); |
| 138 |
+ free(file); |
| 139 |
return 1; |
| 140 |
} |
| 141 |
sprintf( lockinfo, "%10d\n", pid ); |
| 142 |
|
| 143 |
+ //asprintf( &message, "fhs_lock: creating lockfile: %s\n", lockinfo ); |
| 144 |
//syslog( LOG_INFO, message ); |
| 145 |
+ //free(message); |
| 146 |
+ free(file); |
| 147 |
write( fd, lockinfo, 11 ); |
| 148 |
close( fd ); |
| 149 |
return 0; |
| 150 |
@@ -563,7 +567,7 @@ |
| 151 |
LOCKDIR, NULL |
| 152 |
}; |
| 153 |
const char *lockprefixes[] = { "LCK..", "lk..", "LK.", NULL }; |
| 154 |
|
| 155 |
+ char *p, *file, pid_buffer[20], *message; |
| 156 |
int i = 0, j, k, fd , pid; |
| 157 |
struct stat buf; |
| 158 |
struct stat buf2; |
| 159 |
@@ -602,19 +606,22 @@ |
| 160 |
while ( lockprefixes[k] ) |
| 161 |
{ |
| 162 |
/* FHS style */ |
| 163 |
|
| 164 |
+ asprintf( &file, "%s/%s%s", lockdirs[i], |
| 165 |
lockprefixes[k], p ); |
| 166 |
if( stat( file, &buf ) == 0 ) |
| 167 |
{ |
| 168 |
|
| 169 |
+ asprintf( &message, UNEXPECTED_LOCK_FILE, |
| 170 |
file ); |
| 171 |
syslog( LOG_INFO, message ); |
| 172 |
+ free( message ); |
| 173 |
+ free( file ); |
| 174 |
return 1; |
| 175 |
} |
| 176 |
+ free( file ); |
| 177 |
|
| 178 |
/* UUCP style */ |
| 179 |
stat(port_filename , &buf ); |
| 180 |
|
| 181 |
+ asprintf( &file, "%s/%s%03d.%03d.%03d", |
| 182 |
lockdirs[i], |
| 183 |
lockprefixes[k], |
| 184 |
(int) major( buf.st_dev ), |
| 185 |
@@ -623,11 +630,14 @@ |
| 186 |
); |
| 187 |
if( stat( file, &buf ) == 0 ) |
| 188 |
{ |
| 189 |
|
| 190 |
+ asprintf( &message, UNEXPECTED_LOCK_FILE, |
| 191 |
file ); |
| 192 |
syslog( LOG_INFO, message ); |
| 193 |
+ free( message ); |
| 194 |
+ free( file ); |
| 195 |
return 1; |
| 196 |
} |
| 197 |
+ free( file ); |
| 198 |
k++; |
| 199 |
} |
| 200 |
} |
| 201 |
@@ -651,10 +661,10 @@ |
| 202 |
#endif /* __unixware__ */ |
| 203 |
p--; |
| 204 |
} |
| 205 |
|
| 206 |
+ asprintf( &file, "%s/%s%s", LOCKDIR, LOCKFILEPREFIX, p ); |
| 207 |
#else |
| 208 |
/* UUCP standard locks */ |
| 209 |
|
| 210 |
+ asprintf( &file, "%s/LK.%03d.%03d.%03d", |
| 211 |
LOCKDIR, |
| 212 |
(int) major( buf.st_dev ), |
| 213 |
(int) major( buf.st_rdev ), |
| 214 |
@@ -672,32 +682,39 @@ |
| 215 |
/* FIXME null terminiate pid_buffer? need to check in Solaris */ |
| 216 |
close( fd ); |
| 217 |
sscanf( pid_buffer, "%d", &pid ); |
| 218 |
|
| 219 |
+ /* asprintf( &message, "found lock for %s with pid %i\n", file, pid ); */ |
| 220 |
/* syslog( LOG_INFO, message ); */ |
| 221 |
+ /* free( message ); */ |
| 222 |
|
| 223 |
if( kill( (pid_t) pid, 0 ) && errno==ESRCH ) |
| 224 |
{ |
| 225 |
|
| 226 |
+ asprintf( &message, |
| 227 |
"RXTX Warning: Removing stale lock file. %s\n", |
| 228 |
file ); |
| 229 |
syslog( LOG_INFO, message ); |
| 230 |
+ free( message ); |
| 231 |
if( unlink( file ) != 0 ) |
| 232 |
{ |
| 233 |
|
| 234 |
+ asprintf( &message, "RXTX Error: Unable to \ |
| 235 |
remove stale lock file: %s\n", |
| 236 |
file |
| 237 |
); |
| 238 |
syslog( LOG_INFO, message ); |
| 239 |
+ free( message ); |
| 240 |
+ free( file ); |
| 241 |
return 0; |
| 242 |
} |
| 243 |
} |
| 244 |
else |
| 245 |
{ |
| 246 |
|
| 247 |
+ /* asprintf( &message, "could not kill %i\n", pid ); */ |
| 248 |
/* syslog( LOG_INFO, message ); */ |
| 249 |
+ /* free( message ); */ |
| 250 |
+ free( file ); |
| 251 |
return 1; |
| 252 |
} |
| 253 |
} |
| 254 |
+ free( file ); |
| 255 |
return 0; |
| 256 |
} |
| 257 |
int init( void ) |
| 258 |
--- a/src/lfd/lockdaemon.c.noinetdscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/upstream/`src/lfd/lockdaemon.c.noinetd`: |
| 259 |
+++ b/src/lfd/lockdaemon.c.noinetdscip-debian debian rxtx 2.2.0+dfsg-3.1 rxtx/upstream/`src/lfd/lockdaemon.c.noinetd`: |
| 260 |
@@ -119,8 +119,8 @@ |
| 261 |
* |
| 262 |
*/ |
| 263 |
int fd,j; |
| 264 |
|
| 265 |
|
| 266 |
+ char lockinfo[12]; |
| 267 |
+ char *file, *p, *message; |
| 268 |
|
| 269 |
j = strlen( filename ); |
| 270 |
p = ( char * ) filename + j; |
| 271 |
@@ -135,24 +135,28 @@ |
| 272 |
#endif /* __unixware__ */ |
| 273 |
p--; |
| 274 |
} |
| 275 |
|
| 276 |
if ( check_lock_status( filename ) ) |
| 277 |
{ |
| 278 |
syslog( LOG_INFO, "fhs_lock() lockstatus fail\n" ); |
| 279 |
return 1; |
| 280 |
} |
| 281 |
+ asprintf( &file, "%s/LCK..%s", LOCKDIR, p ); |
| 282 |
fd = open( file, O_CREAT | O_WRONLY | O_EXCL, 0444 ); |
| 283 |
if( fd < 0 ) |
| 284 |
{ |
| 285 |
|
| 286 |
+ asprintf( &message, |
| 287 |
"RXTX fhs_lock() Error: creating lock file: %s: %s\n", |
| 288 |
file, strerror(errno) ); |
| 289 |
syslog( LOG_INFO, message ); |
| 290 |
+ free(message); |
| 291 |
+ free(file); |
| 292 |
return 1; |
| 293 |
} |
| 294 |
sprintf( lockinfo, "%10d\n", pid ); |
| 295 |
|
| 296 |
+ asprintf( &message, "fhs_lock: creating lockfile: %s\n", lockinfo ); |
| 297 |
syslog( LOG_INFO, message ); |
| 298 |
+ free( message ); |
| 299 |
+ free( file ); |
| 300 |
write( fd, lockinfo, 11 ); |
| 301 |
close( fd ); |
| 302 |
return 0; |
| 303 |
@@ -556,7 +560,7 @@ |
| 304 |
LOCKDIR, NULL |
| 305 |
}; |
| 306 |
const char *lockprefixes[] = { "LCK..", "lk..", "LK.", NULL }; |
| 307 |
|
| 308 |
+ char *p, *file, pid_buffer[20], *message; |
| 309 |
int i = 0, j, k, fd , pid; |
| 310 |
struct stat buf; |
| 311 |
struct stat buf2; |
| 312 |
@@ -595,19 +599,22 @@ |
| 313 |
while ( lockprefixes[k] ) |
| 314 |
{ |
| 315 |
/* FHS style */ |
| 316 |
|
| 317 |
+ asprintf( &file, "%s/%s%s", lockdirs[i], |
| 318 |
lockprefixes[k], p ); |
| 319 |
if( stat( file, &buf ) == 0 ) |
| 320 |
{ |
| 321 |
|
| 322 |
+ asprintf( &message, UNEXPECTED_LOCK_FILE, |
| 323 |
file ); |
| 324 |
syslog( LOG_INFO, message ); |
| 325 |
+ free( message ); |
| 326 |
+ free( file ); |
| 327 |
return 1; |
| 328 |
} |
| 329 |
+ free( file ); |
| 330 |
|
| 331 |
/* UUCP style */ |
| 332 |
stat(port_filename , &buf ); |
| 333 |
|
| 334 |
+ asprintf( &file, "%s/%s%03d.%03d.%03d", |
| 335 |
lockdirs[i], |
| 336 |
lockprefixes[k], |
| 337 |
(int) major( buf.st_dev ), |
| 338 |
@@ -616,11 +623,14 @@ |
| 339 |
); |
| 340 |
if( stat( file, &buf ) == 0 ) |
| 341 |
{ |
| 342 |
|
| 343 |
+ asprintf( &message, UNEXPECTED_LOCK_FILE, |
| 344 |
file ); |
| 345 |
syslog( LOG_INFO, message ); |
| 346 |
+ free( message ); |
| 347 |
+ free( file ); |
| 348 |
return 1; |
| 349 |
} |
| 350 |
+ free( file ); |
| 351 |
k++; |
| 352 |
} |
| 353 |
} |
| 354 |
@@ -644,7 +654,7 @@ |
| 355 |
#endif /* __unixware__ */ |
| 356 |
p--; |
| 357 |
} |
| 358 |
|
| 359 |
+ asprintf( &file, "%s/%s%s", LOCKDIR, LOCKFILEPREFIX, p ); |
| 360 |
#else |
| 361 |
/* UUCP standard locks */ |
| 362 |
if ( stat( port_filename, &buf ) != 0 ) |
| 363 |
@@ -656,7 +666,7 @@ |
| 364 |
syslog( LOG_INFO, message ); |
| 365 |
return 1; |
| 366 |
} |
| 367 |
|
| 368 |
+ asprintf( &file, "%s/LK.%03d.%03d.%03d", |
| 369 |
LOCKDIR, |
| 370 |
(int) major( buf.st_dev ), |
| 371 |
(int) major( buf.st_rdev ), |
| 372 |
@@ -677,10 +687,11 @@ |
| 373 |
|
| 374 |
if( kill( (pid_t) pid, 0 ) && errno==ESRCH ) |
| 375 |
{ |
| 376 |
|
| 377 |
+ asprintf( &message, |
| 378 |
"RXTX Warning: Removing stale lock file. %s\n", |
| 379 |
file ); |
| 380 |
syslog( LOG_INFO, message ); |
| 381 |
+ free( message ); |
| 382 |
if( unlink( file ) != 0 ) |
| 383 |
{ |
| 384 |
snprintf( message, 80, "RXTX Error: Unable to \ |
| 385 |
@@ -688,10 +699,13 @@ |
| 386 |
file |
| 387 |
); |
| 388 |
syslog( LOG_INFO, message ); |
| 389 |
+ free( message ); |
| 390 |
+ free( file ); |
| 391 |
return 1; |
| 392 |
} |
| 393 |
} |
| 394 |
} |
| 395 |
+ free( file ); |
| 396 |
return 0; |
| 397 |
} |
| 398 |
int init( void ) |