[libcamera-devel,v2,2/2] libcamera: utils: call secure_getenv() if it exists or workaround with issetugid()

Message ID 20190426084220.71500-3-giulio.benetti@micronovasrl.com
State Accepted
Headers show
Series
  • improve secure_getenv()
Related show

Commit Message

Giulio Benetti April 26, 2019, 8:42 a.m. UTC
When secure_getenv() is not available, need to have a workaround.

Check if secure_getenv() is present, otherwise call issetugid() on its
place.

Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com>
---
Changes:
V1->V2: call ::secure_getenv() instead of secure_getenv() recursively.

 src/libcamera/utils.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Laurent Pinchart April 26, 2019, 10:10 a.m. UTC | #1
Hi Giulio,

Thank you for the patch.

On Fri, Apr 26, 2019 at 10:42:20AM +0200, Giulio Benetti wrote:
> When secure_getenv() is not available, need to have a workaround.
> 
> Check if secure_getenv() is present, otherwise call issetugid() on its
> place.
> 
> Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com>
> ---
> Changes:
> V1->V2: call ::secure_getenv() instead of secure_getenv() recursively.
> 
>  src/libcamera/utils.cpp | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
> index 66123b1..5d85b5c 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/utils.cpp
> @@ -8,7 +8,7 @@
>  #include "utils.h"
>  
>  #include <string.h>
> -#include <sys/auxv.h>
> +#include <unistd.h>

You need to also include stdlib.h as that's where secure_getenv() is
defined. Kieran will fix this when applying, there's no need to resend.

>  
>  /**
>   * \file utils.h
> @@ -57,10 +57,14 @@ const char *basename(const char *path)
>   */
>  char *secure_getenv(const char *name)
>  {
> -	if (getauxval(AT_SECURE))
> +#if HAVE_SECURE_GETENV
> +	return ::secure_getenv(name);
> +#else
> +	if (issetugid())
>  		return NULL;
>  
>  	return getenv(name);
> +#endif
>  }
>  
>  /**
Giulio Benetti April 26, 2019, 10:25 a.m. UTC | #2
Hi Laurant,

Il 26/04/2019 12:10, Laurent Pinchart ha scritto:
> Hi Giulio,
> 
> Thank you for the patch.
> 
> On Fri, Apr 26, 2019 at 10:42:20AM +0200, Giulio Benetti wrote:
>> When secure_getenv() is not available, need to have a workaround.
>>
>> Check if secure_getenv() is present, otherwise call issetugid() on its
>> place.
>>
>> Signed-off-by: Giulio Benetti <giulio.benetti@micronovasrl.com>
>> ---
>> Changes:
>> V1->V2: call ::secure_getenv() instead of secure_getenv() recursively.
>>
>>   src/libcamera/utils.cpp | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
>> index 66123b1..5d85b5c 100644
>> --- a/src/libcamera/utils.cpp
>> +++ b/src/libcamera/utils.cpp
>> @@ -8,7 +8,7 @@
>>   #include "utils.h"
>>   
>>   #include <string.h>
>> -#include <sys/auxv.h>
>> +#include <unistd.h>
> 
> You need to also include stdlib.h as that's where secure_getenv() is
> defined. Kieran will fix this when applying, there's no need to resend.

Ok, thank you!

Giulio

>>   
>>   /**
>>    * \file utils.h
>> @@ -57,10 +57,14 @@ const char *basename(const char *path)
>>    */
>>   char *secure_getenv(const char *name)
>>   {
>> -	if (getauxval(AT_SECURE))
>> +#if HAVE_SECURE_GETENV
>> +	return ::secure_getenv(name);
>> +#else
>> +	if (issetugid())
>>   		return NULL;
>>   
>>   	return getenv(name);
>> +#endif
>>   }
>>   
>>   /**
>

Patch

diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
index 66123b1..5d85b5c 100644
--- a/src/libcamera/utils.cpp
+++ b/src/libcamera/utils.cpp
@@ -8,7 +8,7 @@ 
 #include "utils.h"
 
 #include <string.h>
-#include <sys/auxv.h>
+#include <unistd.h>
 
 /**
  * \file utils.h
@@ -57,10 +57,14 @@  const char *basename(const char *path)
  */
 char *secure_getenv(const char *name)
 {
-	if (getauxval(AT_SECURE))
+#if HAVE_SECURE_GETENV
+	return ::secure_getenv(name);
+#else
+	if (issetugid())
 		return NULL;
 
 	return getenv(name);
+#endif
 }
 
 /**