[binutils-gdb] libctf: handle errors on dynhash insertion better

Jose E.Marchesi jemarch@sourceware.org
Fri Jun 21 12:13:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=24865428034f44d9fffe6b2d9a318e1bd507c63a

commit 24865428034f44d9fffe6b2d9a318e1bd507c63a
Author: Nick Alcock <nick.alcock@oracle.com>
Date:   Wed Jun 19 12:14:16 2019 +0100

    libctf: handle errors on dynhash insertion better
    
    We were missing several cases where dynhash insertion might fail, likely
    due to OOM but possibly for other reasons.  Pass the errors on.
    
    libctf/
    	* ctf-create.c (ctf_dtd_insert): Pass on error returns from
    	ctf_dynhash_insert.
    	(ctf_dvd_insert): Likewise.
    	(ctf_add_generic): Likewise.
    	(ctf_add_variable): Likewise.
    	* ctf-impl.h: Adjust declarations.

Diff:
---
 libctf/ChangeLog    |  9 +++++++++
 libctf/ctf-create.c | 34 ++++++++++++++++++++++++----------
 libctf/ctf-impl.h   |  4 ++--
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 31ce038..886e30b 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,12 @@
+2019-06-19  Nick Alcock <nick.alcock@oracle.com>
+
+	* ctf-create.c (ctf_dtd_insert): Pass on error returns from
+	ctf_dynhash_insert.
+	(ctf_dvd_insert): Likewise.
+	(ctf_add_generic): Likewise.
+	(ctf_add_variable): Likewise.
+	* ctf-impl.h: Adjust declarations.
+
 2019-06-14  Alan Modra  <amodra@gmail.com>
 
 	* configure: Regenerate.
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index 5bcc36e..5b53479 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -526,18 +526,22 @@ ctf_prefixed_name (int kind, const char *name)
   return prefixed;
 }
 
-void
+int
 ctf_dtd_insert (ctf_file_t *fp, ctf_dtdef_t *dtd)
 {
-  ctf_dynhash_insert (fp->ctf_dthash, (void *) dtd->dtd_type, dtd);
-  ctf_list_append (&fp->ctf_dtdefs, dtd);
+  if (ctf_dynhash_insert (fp->ctf_dthash, (void *) dtd->dtd_type, dtd) < 0)
+    return -1;
+
   if (dtd->dtd_name)
     {
       int kind = LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info);
-      ctf_dynhash_insert (fp->ctf_dtbyname, ctf_prefixed_name (kind,
-							       dtd->dtd_name),
-			  dtd);
+      if (ctf_dynhash_insert (fp->ctf_dtbyname,
+			      ctf_prefixed_name (kind, dtd->dtd_name),
+			      dtd) < 0)
+	return -1;
     }
+  ctf_list_append (&fp->ctf_dtdefs, dtd);
+  return 0;
 }
 
 void
@@ -623,11 +627,13 @@ ctf_dynamic_type (const ctf_file_t *fp, ctf_id_t id)
   return NULL;
 }
 
-void
+int
 ctf_dvd_insert (ctf_file_t *fp, ctf_dvdef_t *dvd)
 {
-  ctf_dynhash_insert (fp->ctf_dvhash, dvd->dvd_name, dvd);
+  if (ctf_dynhash_insert (fp->ctf_dvhash, dvd->dvd_name, dvd) < 0)
+    return -1;
   ctf_list_append (&fp->ctf_dvdefs, dvd);
+  return 0;
 }
 
 void
@@ -762,7 +768,11 @@ ctf_add_generic (ctf_file_t *fp, uint32_t flag, const char *name,
   if (s != NULL)
     fp->ctf_dtvstrlen += strlen (s) + 1;
 
-  ctf_dtd_insert (fp, dtd);
+  if (ctf_dtd_insert (fp, dtd) < 0)
+    {
+      ctf_free (dtd);
+      return CTF_ERR;			/* errno is set for us.  */
+    }
   fp->ctf_flags |= LCTF_DIRTY;
 
   *rp = dtd;
@@ -1442,7 +1452,11 @@ ctf_add_variable (ctf_file_t *fp, const char *name, ctf_id_t ref)
   dvd->dvd_type = ref;
   dvd->dvd_snapshots = fp->ctf_snapshots;
 
-  ctf_dvd_insert (fp, dvd);
+  if (ctf_dvd_insert (fp, dvd) < 0)
+    {
+      ctf_free (dvd);
+      return -1;			/* errno is set for us.  */
+    }
 
   fp->ctf_dtvstrlen += strlen (name) + 1;
   fp->ctf_flags |= LCTF_DIRTY;
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index fa9c574..52aef24 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -316,12 +316,12 @@ extern void ctf_list_append (ctf_list_t *, void *);
 extern void ctf_list_prepend (ctf_list_t *, void *);
 extern void ctf_list_delete (ctf_list_t *, void *);
 
-extern void ctf_dtd_insert (ctf_file_t *, ctf_dtdef_t *);
+extern int ctf_dtd_insert (ctf_file_t *, ctf_dtdef_t *);
 extern void ctf_dtd_delete (ctf_file_t *, ctf_dtdef_t *);
 extern ctf_dtdef_t *ctf_dtd_lookup (const ctf_file_t *, ctf_id_t);
 extern ctf_dtdef_t *ctf_dynamic_type (const ctf_file_t *, ctf_id_t);
 
-extern void ctf_dvd_insert (ctf_file_t *, ctf_dvdef_t *);
+extern int ctf_dvd_insert (ctf_file_t *, ctf_dvdef_t *);
 extern void ctf_dvd_delete (ctf_file_t *, ctf_dvdef_t *);
 extern ctf_dvdef_t *ctf_dvd_lookup (const ctf_file_t *, const char *);



More information about the Binutils-cvs mailing list