public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH 04/17] libebl: Use static number for array stack allocation in openbackend.
@ 2015-05-26 19:34 Roland McGrath
  0 siblings, 0 replies; 2+ messages in thread
From: Roland McGrath @ 2015-05-26 19:34 UTC (permalink / raw)
  To: elfutils-devel

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

OK

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

* [PATCH 04/17] libebl: Use static number for array stack allocation in openbackend.
@ 2015-05-23 21:10 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2015-05-23 21:10 UTC (permalink / raw)
  To: elfutils-devel

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

Help the compiler see we stack allocate a small array.  Add assert to check
no machine prefix is ever larger than 16. Current maximum number is 7.
This prevents gcc warning about possible unbounded stack usage with
-Wstack-usage.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libebl/ChangeLog        |  5 +++++
 libebl/eblopenbackend.c | 10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 3655e72..9ca7b47 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,8 @@
+2015-05-17  Mark Wielaard  <mjw@redhat.com>
+
+	* eblopenbackend.c (MAX_PREFIX_LEN): New define (16).
+	(openbackend): Stack allocate symname array using MAX_PREFIX_LEN.
+
 2015-01-27  Mark Wielaard  <mjw@redhat.com>
 
 	* libebl.h: Add comment from README that this is completely
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index 3a22f53..2766e7b 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -1,5 +1,5 @@
 /* Generate ELF backend handle.
-   Copyright (C) 2000-2014 Red Hat, Inc.
+   Copyright (C) 2000-2015 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -135,6 +135,8 @@ static const struct
 };
 #define nmachines (sizeof (machines) / sizeof (machines[0]))
 
+/* No machine prefix should be larger than this.  */
+#define MAX_PREFIX_LEN 16
 
 /* Default callbacks.  Mostly they just return the error value.  */
 static const char *default_object_type_name (int ignore, char *buf,
@@ -343,7 +345,11 @@ openbackend (elf, emulation, machine)
 	    static const char version[] = MODVERSION;
 	    const char *modversion;
 	    ebl_bhinit_t initp;
-	    char symname[machines[cnt].prefix_len + sizeof "_init"];
+
+	    // We use a static number to help the compiler see we don't
+	    // overflow the stack with an arbitrary number.
+	    assert (machines[cnt].prefix_len <= MAX_PREFIX_LEN);
+	    char symname[MAX_PREFIX_LEN + sizeof "_init"];
 
 	    strcpy (mempcpy (symname, machines[cnt].prefix,
 			     machines[cnt].prefix_len), "_init");
-- 
1.8.3.1


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

end of thread, other threads:[~2015-05-26 19:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-26 19:34 [PATCH 04/17] libebl: Use static number for array stack allocation in openbackend Roland McGrath
  -- strict thread matches above, loose matches on Subject: below --
2015-05-23 21:10 Mark Wielaard

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).