public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, libgomp] Fix segfault with plugin-hsa
@ 2019-09-11  9:30 Tobias Burnus
  2019-09-11  9:49 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Burnus @ 2019-09-11  9:30 UTC (permalink / raw)
  To: gcc-patches, Jakub Jelinek

Hi all, hi Jakub,

when playing around with offloading, I got an hsa initialization error 
(/dev/... lacked write permission) and the library call returned with an 
error status – but hsa_fns.hsa_status_string_fn didn't set the message 
to the string variable.

Hence, the string variable was uninitialized and libgomp crashed when 
printing the error message; "[unknown]" is not the best HSA run-time 
message, but at least the primary message is shown and there is no crash :-)

Build and tested on x86_64-gnu-linux.

OK for the trunk and GCC 9?

Tobias


2019-09-11  Tobias Burnus  <tobias@codesourcery.com>

         * plugin/plugin-hsa.c (hsa_warn, hsa_fatal, hsa_error): Ensure
         string is initialized.

diff --git a/libgomp/plugin/plugin-hsa.c b/libgomp/plugin/plugin-hsa.c
index 80f23f9beb6..c0837d04e5d 100644
--- a/libgomp/plugin/plugin-hsa.c
+++ b/libgomp/plugin/plugin-hsa.c
@@ -289,7 +289,7 @@ hsa_warn (const char *str, hsa_status_t status)
    if (!debug)
      return;
  
-  const char *hsa_error_msg;
+  const char *hsa_error_msg = "[unknown]";
    hsa_fns.hsa_status_string_fn (status, &hsa_error_msg);
  
    fprintf (stderr, "HSA warning: %s\nRuntime message: %s", str, hsa_error_msg);
@@ -301,7 +301,7 @@ hsa_warn (const char *str, hsa_status_t status)
  static void
  hsa_fatal (const char *str, hsa_status_t status)
  {
-  const char *hsa_error_msg;
+  const char *hsa_error_msg = "[unknown]";
    hsa_fns.hsa_status_string_fn (status, &hsa_error_msg);
    GOMP_PLUGIN_fatal ("HSA fatal error: %s\nRuntime message: %s", str,
  		     hsa_error_msg);
@@ -313,7 +313,7 @@ hsa_fatal (const char *str, hsa_status_t status)
  static bool
  hsa_error (const char *str, hsa_status_t status)
  {
-  const char *hsa_error_msg;
+  const char *hsa_error_msg = "[unknown]";
    hsa_fns.hsa_status_string_fn (status, &hsa_error_msg);
    GOMP_PLUGIN_error ("HSA fatal error: %s\nRuntime message: %s", str,
  		     hsa_error_msg);

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

* Re: [patch, libgomp] Fix segfault with plugin-hsa
  2019-09-11  9:30 [patch, libgomp] Fix segfault with plugin-hsa Tobias Burnus
@ 2019-09-11  9:49 ` Jakub Jelinek
  2019-09-11 12:07   ` Martin Jambor
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2019-09-11  9:49 UTC (permalink / raw)
  To: Tobias Burnus, Martin Jambor; +Cc: gcc-patches

On Wed, Sep 11, 2019 at 11:30:17AM +0200, Tobias Burnus wrote:
> when playing around with offloading, I got an hsa initialization error
> (/dev/... lacked write permission) and the library call returned with an
> error status – but hsa_fns.hsa_status_string_fn didn't set the message to
> the string variable.
> 
> Hence, the string variable was uninitialized and libgomp crashed when
> printing the error message; "[unknown]" is not the best HSA run-time
> message, but at least the primary message is shown and there is no crash :-)

LGTM, but give Martin (CCed) as the author a chance to chime in.

> 2019-09-11  Tobias Burnus  <tobias@codesourcery.com>
> 
>         * plugin/plugin-hsa.c (hsa_warn, hsa_fatal, hsa_error): Ensure
>         string is initialized.
> 
> diff --git a/libgomp/plugin/plugin-hsa.c b/libgomp/plugin/plugin-hsa.c
> index 80f23f9beb6..c0837d04e5d 100644
> --- a/libgomp/plugin/plugin-hsa.c
> +++ b/libgomp/plugin/plugin-hsa.c
> @@ -289,7 +289,7 @@ hsa_warn (const char *str, hsa_status_t status)
>    if (!debug)
>      return;
> -  const char *hsa_error_msg;
> +  const char *hsa_error_msg = "[unknown]";
>    hsa_fns.hsa_status_string_fn (status, &hsa_error_msg);
>    fprintf (stderr, "HSA warning: %s\nRuntime message: %s", str, hsa_error_msg);
> @@ -301,7 +301,7 @@ hsa_warn (const char *str, hsa_status_t status)
>  static void
>  hsa_fatal (const char *str, hsa_status_t status)
>  {
> -  const char *hsa_error_msg;
> +  const char *hsa_error_msg = "[unknown]";
>    hsa_fns.hsa_status_string_fn (status, &hsa_error_msg);
>    GOMP_PLUGIN_fatal ("HSA fatal error: %s\nRuntime message: %s", str,
>  		     hsa_error_msg);
> @@ -313,7 +313,7 @@ hsa_fatal (const char *str, hsa_status_t status)
>  static bool
>  hsa_error (const char *str, hsa_status_t status)
>  {
> -  const char *hsa_error_msg;
> +  const char *hsa_error_msg = "[unknown]";
>    hsa_fns.hsa_status_string_fn (status, &hsa_error_msg);
>    GOMP_PLUGIN_error ("HSA fatal error: %s\nRuntime message: %s", str,
>  		     hsa_error_msg);
> 

	Jakub

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

* Re: [patch, libgomp] Fix segfault with plugin-hsa
  2019-09-11  9:49 ` Jakub Jelinek
@ 2019-09-11 12:07   ` Martin Jambor
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Jambor @ 2019-09-11 12:07 UTC (permalink / raw)
  To: Jakub Jelinek, Tobias Burnus; +Cc: gcc-patches

Hi,

On Wed, Sep 11 2019, Jakub Jelinek wrote:
> On Wed, Sep 11, 2019 at 11:30:17AM +0200, Tobias Burnus wrote:
>> when playing around with offloading, I got an hsa initialization error
>> (/dev/... lacked write permission) and the library call returned with an
>> error status – but hsa_fns.hsa_status_string_fn didn't set the message to
>> the string variable.
>> 
>> Hence, the string variable was uninitialized and libgomp crashed when
>> printing the error message; "[unknown]" is not the best HSA run-time
>> message, but at least the primary message is shown and there is no crash :-)
>
> LGTM, but give Martin (CCed) as the author a chance to chime in.

Looks good to me too.  Thanks.

Martin

>
>> 2019-09-11  Tobias Burnus  <tobias@codesourcery.com>
>> 
>>         * plugin/plugin-hsa.c (hsa_warn, hsa_fatal, hsa_error): Ensure
>>         string is initialized.

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

end of thread, other threads:[~2019-09-11 12:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-11  9:30 [patch, libgomp] Fix segfault with plugin-hsa Tobias Burnus
2019-09-11  9:49 ` Jakub Jelinek
2019-09-11 12:07   ` Martin Jambor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).