Skip to contentSkip to conversation

exec.c: Initialize sa_flags passed to sigaction()

PATCH Applied Peter Maydell 5 participants 5 messages May 15, 2018 – May 16, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exec.c: Initialize sa_flags passed to sigaction()

Coverity points out that in the user-only version of cpu_abort() we call sigaction() with a partially initialized struct sigaction (CID 1005351). Correct the omission.

---
 exec.c | 1 +
 1 file changed, 1 insertion(+)
exec.c +1 -0
index ffa1099547..bd8833fc9d 100644
@@ -1124,6 +1124,7 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
         struct sigaction act;
         sigfillset(&act.sa_mask);
         act.sa_handler = SIG_DFL;
+        act.sa_flags = 0;
         sigaction(SIGABRT, &act, NULL);
     }
 #endif
Signature · 1 line
2.17.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Peter Maydell

Coverity points out that in the user-only version of cpu_abort() we call sigaction() with a partially initialized struct sigaction (CID 1005351). Correct the omission.

Quoted 9 lines
---
 exec.c | 1 +
 1 file changed, 1 insertion(+)
exec.c +0 -0
index ffa1099547..bd8833fc9d 100644

exec.c void cpu_abort(CPUState *cpu, const char *fmt, ...) · line 1130

Quoted 7 lines
exec.c +1 -0
@@ -1124,6 +1124,7 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
         struct sigaction act;
         sigfillset(&act.sa_mask);
         act.sa_handler = SIG_DFL;
+        act.sa_flags = 0;
         sigaction(SIGABRT, &act, NULL);
     }
 #endif

--
Alex Bennée

Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Maydell
Quoted 14 lines · Peter Maydell

Coverity points out that in the user-only version of cpu_abort() we call sigaction() with a partially initialized struct sigaction (CID 1005351). Correct the omission.

---
 exec.c | 1 +
 1 file changed, 1 insertion(+)
exec.c +0 -0
index ffa1099547..bd8833fc9d 100644

exec.c void cpu_abort(CPUState *cpu, const char *fmt, ...) · line 1124

Quoted 1 line
exec.c +0 -0
@@ -1124,6 +1124,7 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
         struct sigaction act;

I'd have used the more generic:

           struct sigaction act = { };
Quoted 7 lines
exec.c +1 -0
         sigfillset(&act.sa_mask);
         act.sa_handler = SIG_DFL;
+        act.sa_flags = 0;
         sigaction(SIGABRT, &act, NULL);
     }
 #endif
#3 lore raw
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Peter Maydell

Coverity points out that in the user-only version of cpu_abort() we call sigaction() with a partially initialized struct sigaction (CID 1005351). Correct the omission.

---
  exec.c | 1 +
  1 file changed, 1 insertion(+)
exec.c +0 -0
index ffa1099547..bd8833fc9d 100644

exec.c void cpu_abort(CPUState *cpu, const char *fmt, ...) · line 1124

Quoted 1 line
exec.c +0 -0
@@ -1124,6 +1124,7 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
          struct sigaction act;

I'd have used the more generic:

Quoted 1 line
            struct sigaction act = { };

That's a gcc/clang extension (although we have used it before, particularly to shut up buggy versions of clang); better is:

struct sigaction act = { 0 };

if that doesn't trigger the clang bug.

Quoted 5 lines
Quoted 2 lines
exec.c +0 -0
          sigfillset(&act.sa_mask);
          act.sa_handler = SIG_DFL;

The sigfillset() has to be done after initialization, but you could also use:

struct sigaction act = {
.sa_handler = SIG_DFL;
};
sigfillset(&act.sa_mask);

as a way to zero-initialize all other fields.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#4 lore raw
In reply to Peter Maydell
Quoted 15 lines · Peter Maydell

Coverity points out that in the user-only version of cpu_abort() we call sigaction() with a partially initialized struct sigaction (CID 1005351). Correct the omission.

---
 exec.c | 1 +
 1 file changed, 1 insertion(+)
exec.c +0 -0
index ffa1099547..bd8833fc9d 100644

exec.c void cpu_abort(CPUState *cpu, const char *fmt, ...) · line 1130

Quoted 7 lines
exec.c +1 -0
@@ -1124,6 +1124,7 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
         struct sigaction act;
         sigfillset(&act.sa_mask);
         act.sa_handler = SIG_DFL;
+        act.sa_flags = 0;
         sigaction(SIGABRT, &act, NULL);
     }
 #endif

Queued, thanks.

Paolo