summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWan-Teh Chang <wtc@google.com>2013-04-30 16:06:47 -0700
committerWan-Teh Chang <wtc@google.com>2013-04-30 16:06:47 -0700
commitd46efd7144d06cf861b378a0f9b58c2cab86ce92 (patch)
tree01b5852ea9a537fe793b64522840225c8f85bbc4
parent840b1e8113a98d7b39fb25447627b617c558aba8 (diff)
downloadnss-hg-d46efd7144d06cf861b378a0f9b58c2cab86ce92.tar.gz
Bug 844513: Add AddressSanitizer annotations to port_ArenaZeroAfterMark.NSS_3_15_BETA3
Reset an arena mark to NULL after releasing the mark. r=choller.
-rw-r--r--lib/util/secasn1d.c1
-rw-r--r--lib/util/secport.c20
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/util/secasn1d.c b/lib/util/secasn1d.c
index 11c5c5bfd..81518830a 100644
--- a/lib/util/secasn1d.c
+++ b/lib/util/secasn1d.c
@@ -2772,6 +2772,7 @@ SEC_ASN1DecoderUpdate (SEC_ASN1DecoderContext *cx,
if (cx->their_pool != NULL) {
PORT_Assert (cx->their_mark != NULL);
PORT_ArenaRelease (cx->their_pool, cx->their_mark);
+ cx->their_mark = NULL;
}
#endif
return SECFailure;
diff --git a/lib/util/secport.c b/lib/util/secport.c
index 9476c4888..dc44d25ae 100644
--- a/lib/util/secport.c
+++ b/lib/util/secport.c
@@ -394,18 +394,35 @@ PORT_ArenaMark(PLArenaPool *arena)
return result;
}
+/*
+ * This function accesses the internals of PLArena, which is why it needs
+ * to use the NSPR internal macro PL_MAKE_MEM_UNDEFINED before the memset
+ * calls.
+ *
+ * We should move this function to NSPR as PL_ClearArenaAfterMark or add
+ * a PL_ARENA_CLEAR_AND_RELEASE macro.
+ *
+ * TODO: remove the #ifdef PL_MAKE_MEM_UNDEFINED tests when NSPR 4.10+ is
+ * widely available.
+ */
static void
port_ArenaZeroAfterMark(PLArenaPool *arena, void *mark)
{
PLArena *a = arena->current;
if (a->base <= (PRUword)mark && (PRUword)mark <= a->avail) {
/* fast path: mark falls in the current arena */
+#ifdef PL_MAKE_MEM_UNDEFINED
+ PL_MAKE_MEM_UNDEFINED(mark, a->avail - (PRUword)mark);
+#endif
memset(mark, 0, a->avail - (PRUword)mark);
} else {
/* slow path: need to find the arena that mark falls in */
for (a = arena->first.next; a; a = a->next) {
PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
if (a->base <= (PRUword)mark && (PRUword)mark <= a->avail) {
+#ifdef PL_MAKE_MEM_UNDEFINED
+ PL_MAKE_MEM_UNDEFINED(mark, a->avail - (PRUword)mark);
+#endif
memset(mark, 0, a->avail - (PRUword)mark);
a = a->next;
break;
@@ -413,6 +430,9 @@ port_ArenaZeroAfterMark(PLArenaPool *arena, void *mark)
}
for (; a; a = a->next) {
PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
+#ifdef PL_MAKE_MEM_UNDEFINED
+ PL_MAKE_MEM_UNDEFINED((void *)a->base, a->avail - a->base);
+#endif
memset((void *)a->base, 0, a->avail - a->base);
}
}