Browse Source

* Android: There are cases when libc "environ" var may be NULL. Check for such case and provide fake valid environment. Bug #24519.

git-svn-id: trunk@24804 -
yury 12 years ago
parent
commit
7e5af23ace
2 changed files with 16 additions and 0 deletions
  1. 7 0
      rtl/android/arm/dllprt0.as
  2. 9 0
      rtl/android/i386/dllprt0.as

+ 7 - 0
rtl/android/arm/dllprt0.as

@@ -31,6 +31,9 @@ FPC_SHARED_LIB_START:
         /* Get environment info from libc */
         /* Get environment info from libc */
         ldr ip,=environ
         ldr ip,=environ
         ldr r0,[ip]
         ldr r0,[ip]
+        /* Check if environment is NULL */
+        cmp r0,#0
+        ldreq r0,=EmptyEnv
         ldr ip,=operatingsystem_parameter_envp
         ldr ip,=operatingsystem_parameter_envp
         str r0,[ip]
         str r0,[ip]
         
         
@@ -69,6 +72,10 @@ EmptyCmdLine:
         .long EmptyCmdStr
         .long EmptyCmdStr
 EmptyCmdStr:
 EmptyCmdStr:
         .ascii "\0"
         .ascii "\0"
+EmptyEnv:
+        .long 0
+        .long 0
+        .long 0
 
 
 /* --------------------------------------------------------- */
 /* --------------------------------------------------------- */
       	.section .init_array, "aw"
       	.section .init_array, "aw"

+ 9 - 0
rtl/android/i386/dllprt0.as

@@ -30,6 +30,11 @@ FPC_SHARED_LIB_START:
 
 
         /* Get environment info from libc */
         /* Get environment info from libc */
         movl    environ,%eax
         movl    environ,%eax
+        /* Check if environment is NULL */
+        cmpl    %eax,0
+        jne     env_ok
+        leal    EmptyEnv,%eax
+env_ok:
         movl    %eax,operatingsystem_parameter_envp
         movl    %eax,operatingsystem_parameter_envp
 
 
         /* Register exit handler. It is called only when the main process terminates */
         /* Register exit handler. It is called only when the main process terminates */
@@ -66,6 +71,10 @@ EmptyCmdLine:
         .long EmptyCmdStr
         .long EmptyCmdStr
 EmptyCmdStr:
 EmptyCmdStr:
         .ascii "\0"
         .ascii "\0"
+EmptyEnv:
+        .long 0
+        .long 0
+        .long 0
 
 
 /* --------------------------------------------------------- */
 /* --------------------------------------------------------- */
       	.section .init_array, "aw"
       	.section .init_array, "aw"