All of lore.kernel.org
 help / color / mirror / Atom feed
* [Powertop] [PATCH 1/2] prevent segment fault for android built 2
@ 2015-07-01 11:52 Zhaoyang Huang
  0 siblings, 0 replies; 4+ messages in thread
From: Zhaoyang Huang @ 2015-07-01 11:52 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 734 bytes --]

the buffer will be turn into NULL after invoking the mbsrtowcs function
of bionic libc. Add a condition judgement for that

Signed-off-by: Zhaoyang Huang <zhaoyang.huang(a)linaro.org>
---
 src/lib.cpp |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lib.cpp b/src/lib.cpp
index 88fe5f3..8d1ca9f 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -285,7 +285,7 @@ void align_string(char *buffer, size_t min_sz, size_t max_sz)
 	/* start with mbsrtowcs() local mbstate_t * and
 	 * NULL dst pointer*/
 	sz = mbsrtowcs(NULL, (const char **)&buffer, max_sz, NULL);
-	if (sz == (size_t)-1) {
+	if ((sz == (size_t)-1) && (NULL != buffer)) {
 		buffer[min_sz] = 0x00;
 		return;
 	}
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Powertop] [PATCH 1/2] prevent segment fault for android built 2
@ 2015-07-06 21:44 Daniel Leung
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Leung @ 2015-07-06 21:44 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 1050 bytes --]

On Wed,  1 Jul 2015 19:52:24 +0800
Zhaoyang Huang <zhaoyang.huang(a)linaro.org> wrote:

> the buffer will be turn into NULL after invoking the mbsrtowcs function
> of bionic libc. Add a condition judgement for that
> 
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang(a)linaro.org>
> ---
>  src/lib.cpp |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/lib.cpp b/src/lib.cpp
> index 88fe5f3..8d1ca9f 100644
> --- a/src/lib.cpp
> +++ b/src/lib.cpp
> @@ -285,7 +285,7 @@ void align_string(char *buffer, size_t min_sz, size_t max_sz)
>  	/* start with mbsrtowcs() local mbstate_t * and
>  	 * NULL dst pointer*/
>  	sz = mbsrtowcs(NULL, (const char **)&buffer, max_sz, NULL);
> -	if (sz == (size_t)-1) {
> +	if ((sz == (size_t)-1) && (NULL != buffer)) {
>  		buffer[min_sz] = 0x00;
>  		return;
>  	}
> -- 
> 1.7.9.5
> 

If you are on master branch, there is a patch (patches/android/prevent_segfaults.patch) to workaround the NULL pointer.

-- 
Daniel Leung <daniel.leung(a)linux.intel.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Powertop] [PATCH 1/2] prevent segment fault for android built 2
@ 2015-07-07  2:16 Zhaoyang Huang
  0 siblings, 0 replies; 4+ messages in thread
From: Zhaoyang Huang @ 2015-07-07  2:16 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 2100 bytes --]

Hi Daniel,
Thank you for your feedback.
I have noticed the patch you mentioned. However, under the android(use
bionic libc) environment, the bellowing condition maybe true which will
cause a NULL pointer access to buffer. I add another one more condition to
prevent it. This problem can also be reproduced by android.

diff --git a/src/lib.cpp b/src/lib.cpp
index 88fe5f3..8d1ca9f 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -285,7 +285,7 @@ void align_string(char *buffer, size_t min_sz, size_t
max_sz)
        /* start with mbsrtowcs() local mbstate_t * and
         * NULL dst pointer*/
        sz = mbsrtowcs(NULL, (const char **)&buffer, max_sz, NULL);
-       if (sz == (size_t)-1) {
+       if ((sz == (size_t)-1) && (NULL != buffer)) {
                buffer[min_sz] = 0x00;
                return;
        }
-- 
1.7.9.5


On 7 July 2015 at 05:44, Daniel Leung <daniel.leung(a)linux.intel.com> wrote:

> On Wed,  1 Jul 2015 19:52:24 +0800
> Zhaoyang Huang <zhaoyang.huang(a)linaro.org> wrote:
>
> > the buffer will be turn into NULL after invoking the mbsrtowcs function
> > of bionic libc. Add a condition judgement for that
> >
> > Signed-off-by: Zhaoyang Huang <zhaoyang.huang(a)linaro.org>
> > ---
> >  src/lib.cpp |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/lib.cpp b/src/lib.cpp
> > index 88fe5f3..8d1ca9f 100644
> > --- a/src/lib.cpp
> > +++ b/src/lib.cpp
> > @@ -285,7 +285,7 @@ void align_string(char *buffer, size_t min_sz,
> size_t max_sz)
> >       /* start with mbsrtowcs() local mbstate_t * and
> >        * NULL dst pointer*/
> >       sz = mbsrtowcs(NULL, (const char **)&buffer, max_sz, NULL);
> > -     if (sz == (size_t)-1) {
> > +     if ((sz == (size_t)-1) && (NULL != buffer)) {
> >               buffer[min_sz] = 0x00;
> >               return;
> >       }
> > --
> > 1.7.9.5
> >
>
> If you are on master branch, there is a patch
> (patches/android/prevent_segfaults.patch) to workaround the NULL pointer.
>
> --
> Daniel Leung <daniel.leung(a)linux.intel.com>
>

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 2953 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Powertop] [PATCH 1/2] prevent segment fault for android built 2
@ 2015-09-18  0:21 Alexandra Yates
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandra Yates @ 2015-09-18  0:21 UTC (permalink / raw)
  To: powertop

[-- Attachment #1: Type: text/plain, Size: 2788 bytes --]

Rejecting this patch.  This is already handled on the Android patches.

On 07/06/2015 07:16 PM, Zhaoyang Huang wrote:
> Hi Daniel,
> Thank you for your feedback.
> I have noticed the patch you mentioned. However, under the android(use 
> bionic libc) environment, the bellowing condition maybe true which 
> will cause a NULL pointer access to buffer. I add another one more 
> condition to prevent it. This problem can also be reproduced by android.
>
> diff --git a/src/lib.cpp b/src/lib.cpp
> index 88fe5f3..8d1ca9f 100644
> --- a/src/lib.cpp
> +++ b/src/lib.cpp
> @@ -285,7 +285,7 @@ void align_string(char *buffer, size_t min_sz, 
> size_t max_sz)
>         /* start with mbsrtowcs() local mbstate_t * and
>          * NULL dst pointer*/
>         sz = mbsrtowcs(NULL, (const char **)&buffer, max_sz, NULL);
> -       if (sz == (size_t)-1) {
> +       if ((sz == (size_t)-1) && (NULL != buffer)) {
>                 buffer[min_sz] = 0x00;
>                 return;
>         }
> -- 
> 1.7.9.5
>
>
> On 7 July 2015 at 05:44, Daniel Leung <daniel.leung(a)linux.intel.com 
> <mailto:daniel.leung(a)linux.intel.com>> wrote:
>
>     On Wed,  1 Jul 2015 19:52:24 +0800
>     Zhaoyang Huang <zhaoyang.huang(a)linaro.org
>     <mailto:zhaoyang.huang(a)linaro.org>> wrote:
>
>     > the buffer will be turn into NULL after invoking the mbsrtowcs
>     function
>     > of bionic libc. Add a condition judgement for that
>     >
>     > Signed-off-by: Zhaoyang Huang <zhaoyang.huang(a)linaro.org
>     <mailto:zhaoyang.huang(a)linaro.org>>
>     > ---
>     >  src/lib.cpp |    2 +-
>     >  1 file changed, 1 insertion(+), 1 deletion(-)
>     >
>     > diff --git a/src/lib.cpp b/src/lib.cpp
>     > index 88fe5f3..8d1ca9f 100644
>     > --- a/src/lib.cpp
>     > +++ b/src/lib.cpp
>     > @@ -285,7 +285,7 @@ void align_string(char *buffer, size_t
>     min_sz, size_t max_sz)
>     >       /* start with mbsrtowcs() local mbstate_t * and
>     >        * NULL dst pointer*/
>     >       sz = mbsrtowcs(NULL, (const char **)&buffer, max_sz, NULL);
>     > -     if (sz == (size_t)-1) {
>     > +     if ((sz == (size_t)-1) && (NULL != buffer)) {
>     >               buffer[min_sz] = 0x00;
>     >               return;
>     >       }
>     > --
>     > 1.7.9.5
>     >
>
>     If you are on master branch, there is a patch
>     (patches/android/prevent_segfaults.patch) to workaround the NULL
>     pointer.
>
>     --
>     Daniel Leung <daniel.leung(a)linux.intel.com
>     <mailto:daniel.leung(a)linux.intel.com>>
>
>
>
>
> _______________________________________________
> PowerTop mailing list
> PowerTop(a)lists.01.org
> https://lists.01.org/mailman/listinfo/powertop

-- 
Thank you,
<Alexandra>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-18  0:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-18  0:21 [Powertop] [PATCH 1/2] prevent segment fault for android built 2 Alexandra Yates
  -- strict thread matches above, loose matches on Subject: below --
2015-07-07  2:16 Zhaoyang Huang
2015-07-06 21:44 Daniel Leung
2015-07-01 11:52 Zhaoyang Huang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.