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

Diff of /trunk/src/sandbox.c

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

Revision 286 Revision 287
447 447
448 if (NULL != getenv(ENV_LD_PRELOAD)) { 448 if (NULL != getenv(ENV_LD_PRELOAD)) {
449 have_ld_preload = 1; 449 have_ld_preload = 1;
450 orig_ld_preload_envvar = getenv(ENV_LD_PRELOAD); 450 orig_ld_preload_envvar = getenv(ENV_LD_PRELOAD);
451 451
452 /* FIXME: Should probably free this at some stage - more neatness
453 * than a real leak that will cause issues. */
454 ld_preload_envvar = calloc(strlen(orig_ld_preload_envvar) + 452 ld_preload_envvar = calloc(strlen(orig_ld_preload_envvar) +
455 strlen(sandbox_info->sandbox_lib) + 2, 453 strlen(sandbox_info->sandbox_lib) + 2,
456 sizeof(char *)); 454 sizeof(char *));
457 if (NULL == ld_preload_envvar) 455 if (NULL == ld_preload_envvar)
458 return NULL; 456 return NULL;
459 snprintf(ld_preload_envvar, strlen(orig_ld_preload_envvar) + 457 snprintf(ld_preload_envvar, strlen(orig_ld_preload_envvar) +
460 strlen(sandbox_info->sandbox_lib) + 2, "%s %s", 458 strlen(sandbox_info->sandbox_lib) + 2, "%s %s",
461 sandbox_info->sandbox_lib, orig_ld_preload_envvar); 459 sandbox_info->sandbox_lib, orig_ld_preload_envvar);
462 } else { 460 } else {
463 /* FIXME: Should probably free this at some stage - more neatness
464 * than a real leak that will cause issues. */
465 ld_preload_envvar = rc_strndup(sandbox_info->sandbox_lib, 461 ld_preload_envvar = rc_strndup(sandbox_info->sandbox_lib,
466 strlen(sandbox_info->sandbox_lib)); 462 strlen(sandbox_info->sandbox_lib));
467 if (NULL == ld_preload_envvar) 463 if (NULL == ld_preload_envvar)
468 return NULL; 464 return NULL;
469 } 465 }
477 473
478 /* FIXME: Should probably free this at some stage - more neatness than 474 /* FIXME: Should probably free this at some stage - more neatness than
479 * a real leak that will cause issues. */ 475 * a real leak that will cause issues. */
480 new_environ = calloc((env_size + 15 + 1) * sizeof(char *), sizeof(char *)); 476 new_environ = calloc((env_size + 15 + 1) * sizeof(char *), sizeof(char *));
481 if (NULL == new_environ) 477 if (NULL == new_environ)
482 return NULL; 478 goto error;
483 479
484 snprintf(sb_pid, sizeof(sb_pid), "%i", getpid()); 480 snprintf(sb_pid, sizeof(sb_pid), "%i", getpid());
485 481
486 /* First add our new variables to the beginning - this is due to some 482 /* First add our new variables to the beginning - this is due to some
487 * weirdness that I cannot remember */ 483 * weirdness that I cannot remember */
536 else 532 else
537 new_environ[env_size + (env_ptr - environ)] = *env_ptr; 533 new_environ[env_size + (env_ptr - environ)] = *env_ptr;
538 env_ptr++; 534 env_ptr++;
539 } 535 }
540 536
537 if (NULL != ld_preload_envvar)
538 free(ld_preload_envvar);
539
541 return new_environ; 540 return new_environ;
541
542error:
543 if (NULL != ld_preload_envvar)
544 free(ld_preload_envvar);
545
546 return NULL;
542} 547}
543 548
544int spawn_shell(char *argv_bash[], char *env[], int debug) 549int spawn_shell(char *argv_bash[], char *env[], int debug)
545{ 550{
546 int status = 0; 551 int status = 0;
690 695
691 /* Start Bash */ 696 /* Start Bash */
692 if (!spawn_shell(argv_bash, sandbox_environ, print_debug)) 697 if (!spawn_shell(argv_bash, sandbox_environ, print_debug))
693 success = 0; 698 success = 0;
694 699
700 /* Free environ */
701 free(sandbox_environ);
702
695 /* Free bash stuff */ 703 /* Free bash stuff */
696 for (i = 0; i < 6; i++) { 704 for (i = 0; i < 6; i++) {
697 if (argv_bash[i]) 705 if (argv_bash[i])
698 free(argv_bash[i]); 706 free(argv_bash[i]);
699 argv_bash[i] = NULL; 707 argv_bash[i] = NULL;

Legend:
Removed from v.286  
changed lines
  Added in v.287

  ViewVC Help
Powered by ViewVC 1.1.20