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

Diff of /trunk/libsandbox.c

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

Revision 99 Revision 100
829 829
830 if FUNCTION_SANDBOX_SAFE 830 if FUNCTION_SANDBOX_SAFE
831 ("execve", canonic) { 831 ("execve", canonic) {
832 while (envp[count] != NULL) { 832 while (envp[count] != NULL) {
833 /* Check if we do not have to do anything */ 833 /* Check if we do not have to do anything */
834 if (strstr(envp[count], "LD_PRELOAD=") == envp[count]) { 834 if (strstr(envp[count], LD_PRELOAD_EQ) == envp[count]) {
835 if (NULL != strstr(envp[count], sandbox_lib)) { 835 if (NULL != strstr(envp[count], sandbox_lib)) {
836 my_env = (char **)envp; 836 my_env = (char **)envp;
837 kill_env = 0; 837 kill_env = 0;
838 goto end_loop; 838 goto end_loop;
839 } 839 }
840 } 840 }
841 841
842 /* If LD_PRELOAD is set and sandbox_lib not in it */ 842 /* If LD_PRELOAD is set and sandbox_lib not in it */
843 if (((strstr(envp[count], "LD_PRELOAD=") == envp[count]) && 843 if (((strstr(envp[count], LD_PRELOAD_EQ) == envp[count]) &&
844 (NULL == strstr(envp[count], sandbox_lib))) || 844 (NULL == strstr(envp[count], sandbox_lib))) ||
845 /* Or LD_PRELOAD is not set, and this is the last loop */ 845 /* Or LD_PRELOAD is not set, and this is the last loop */
846 ((strstr(envp[count], "LD_PRELOAD=") != envp[count]) && 846 ((strstr(envp[count], LD_PRELOAD_EQ) != envp[count]) &&
847 (NULL == envp[count + 1]))) { 847 (NULL == envp[count + 1]))) {
848 int i = 0; 848 int i = 0;
849 int add_ldpreload = 0; 849 int add_ldpreload = 0;
850 const int max_envp_len = strlen(envp[count]) + strlen(sandbox_lib) + 1; 850 const int max_envp_len = strlen(envp[count]) + strlen(sandbox_lib) + 1;
851 851
861 do 861 do
862 env_len++; 862 env_len++;
863 while (NULL != *my_env++); 863 while (NULL != *my_env++);
864 864
865 /* Should we add LD_PRELOAD ? */ 865 /* Should we add LD_PRELOAD ? */
866 if (strstr(envp[count], "LD_PRELOAD=") != envp[count]) 866 if (strstr(envp[count], LD_PRELOAD_EQ) != envp[count])
867 add_ldpreload = 1; 867 add_ldpreload = 1;
868 868
869 my_env = (char **)calloc(env_len + add_ldpreload, sizeof(char *)); 869 my_env = (char **)calloc(env_len + add_ldpreload, sizeof(char *));
870 if (NULL == my_env) { 870 if (NULL == my_env) {
871 errno = ENOMEM; 871 errno = ENOMEM;
876 /* Leave a space for LD_PRELOAD if needed */ 876 /* Leave a space for LD_PRELOAD if needed */
877 my_env[i + add_ldpreload] = envp[i]; 877 my_env[i + add_ldpreload] = envp[i];
878 while (NULL != envp[i++]); 878 while (NULL != envp[i++]);
879 879
880 /* Add 'LD_PRELOAD=' to the beginning of our new string */ 880 /* Add 'LD_PRELOAD=' to the beginning of our new string */
881 snprintf(tmp_str, max_envp_len, "LD_PRELOAD=%s", sandbox_lib); 881 snprintf(tmp_str, max_envp_len, "%s%s", LD_PRELOAD_EQ, sandbox_lib);
882 882
883 /* LD_PRELOAD already have variables other than sandbox_lib, 883 /* LD_PRELOAD already have variables other than sandbox_lib,
884 * thus we have to add sandbox_lib seperated via a whitespace. */ 884 * thus we have to add sandbox_lib seperated via a whitespace. */
885 if (0 == add_ldpreload) { 885 if (0 == add_ldpreload) {
886 snprintf(&(tmp_str[strlen(tmp_str)]), 886 snprintf(&(tmp_str[strlen(tmp_str)]),
887 max_envp_len - strlen(tmp_str) + 1, " %s", 887 max_envp_len - strlen(tmp_str) + 1, " %s",
888 &(envp[count][strlen("LD_PRELOAD=")])); 888 &(envp[count][strlen(LD_PRELOAD_EQ)]));
889 } 889 }
890 890
891 /* Valid string? */ 891 /* Valid string? */
892 tmp_str[max_envp_len] = '\0'; 892 tmp_str[max_envp_len] = '\0';
893 893

Legend:
Removed from v.99  
changed lines
  Added in v.100

  ViewVC Help
Powered by ViewVC 1.1.20