/[path-sandbox]/trunk/src/libsandbox.c
Gentoo

Diff of /trunk/src/libsandbox.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 256 Revision 257
1271} 1271}
1272 1272
1273static int check_syscall(sbcontext_t * sbcontext, const char *func, const char *file) 1273static int check_syscall(sbcontext_t * sbcontext, const char *func, const char *file)
1274{ 1274{
1275 struct stat log_stat; 1275 struct stat log_stat;
1276 char buffer[512]; 1276 char *buffer;
1277 char *absolute_path = NULL; 1277 char *absolute_path = NULL;
1278 char *resolved_path = NULL; 1278 char *resolved_path = NULL;
1279 char *log_path = NULL, *debug_log_path = NULL; 1279 char *log_path = NULL, *debug_log_path = NULL;
1280 int old_errno = errno; 1280 int old_errno = errno;
1281 int result = 1; 1281 int result = 1;
1323 if ((0 == result) && (1 == sbcontext->show_access_violation)) 1323 if ((0 == result) && (1 == sbcontext->show_access_violation))
1324 access = 1; 1324 access = 1;
1325 1325
1326 if (((NULL != log_path) && (1 == access)) || 1326 if (((NULL != log_path) && (1 == access)) ||
1327 ((NULL != debug_log_path) && (1 == debug))) { 1327 ((NULL != debug_log_path) && (1 == debug))) {
1328 int bufsize = 0;
1329
1328 if (0 != strncmp(absolute_path, resolved_path, strlen(absolute_path))) { 1330 if (0 != strncmp(absolute_path, resolved_path, strlen(absolute_path))) {
1331 bufsize = 32 + strlen(absolute_path) + strlen(resolved_path);
1332 buffer = calloc(bufsize, sizeof(char));
1333 if (NULL == buffer)
1334 goto mem_error;
1335
1329 sprintf(buffer, "%s:%*s%s (symlink to %s)\n", func, 1336 snprintf(buffer, bufsize, "%s:%*s%s (symlink to %s)\n",
1330 (int)(10 - strlen(func)), "", 1337 func, (int)(10 - strlen(func)), "",
1331 absolute_path, resolved_path); 1338 absolute_path, resolved_path);
1332 } else { 1339 } else {
1340 bufsize = 32 + strlen(absolute_path);
1341 buffer = calloc(bufsize, sizeof(char));
1342 if (NULL == buffer)
1343 goto mem_error;
1344
1333 sprintf(buffer, "%s:%*s%s\n", func, 1345 snprintf(buffer, bufsize, "%s:%*s%s\n",
1334 (int)(10 - strlen(func)), "", 1346 func, (int)(10 - strlen(func)), "",
1335 absolute_path); 1347 absolute_path);
1336 } 1348 }
1337 if (1 == access) { 1349 if (1 == access) {
1338 if ((0 == lstat(log_path, &log_stat)) && 1350 if ((0 == lstat(log_path, &log_stat)) &&
1339 (0 == S_ISREG(log_stat.st_mode))) { 1351 (0 == S_ISREG(log_stat.st_mode))) {
1364 write(debug_log_file, buffer, strlen(buffer)); 1376 write(debug_log_file, buffer, strlen(buffer));
1365 close(debug_log_file); 1377 close(debug_log_file);
1366 } 1378 }
1367 } 1379 }
1368 } 1380 }
1381
1382 if (NULL != buffer)
1383 free (buffer);
1369 } 1384 }
1370 1385
1371 if (NULL != absolute_path) 1386 if (NULL != absolute_path)
1372 free(absolute_path); 1387 free(absolute_path);
1373 if (NULL != resolved_path) 1388 if (NULL != resolved_path)
1374 free(resolved_path); 1389 free(resolved_path);
1375 1390
1376 errno = old_errno; 1391 errno = old_errno;
1377 1392
1378 return result; 1393 return result;
1394
1395mem_error:
1396 EWARN(color, "OUT OF MEMORY", "%s\n", __FUNCTION__);
1397
1398 if (NULL != absolute_path)
1399 free(absolute_path);
1400 if (NULL != resolved_path)
1401 free(resolved_path);
1402
1403 errno = ENOMEM;
1404
1405 return 0;
1379 1406
1380fp_error: 1407fp_error:
1381 if (NULL != absolute_path) 1408 if (NULL != absolute_path)
1382 free(absolute_path); 1409 free(absolute_path);
1383 if (NULL != resolved_path) 1410 if (NULL != resolved_path)

Legend:
Removed from v.256  
changed lines
  Added in v.257

  ViewVC Help
Powered by ViewVC 1.1.20