diff options
| author | Dima Zavin <dima@android.com> | 2011-03-24 11:12:00 -0700 |
|---|---|---|
| committer | Dima Zavin <dima@android.com> | 2011-04-19 15:16:18 -0700 |
| commit | 4fab9ac04e444f8ad057e67006320ca25381948e (patch) | |
| tree | 66e909ccd2adb164bf3820116dfee49eaf5d2196 /libcutils | |
| parent | bdaaec1ba0a7cf832ad7fe475a7c541ed9973e52 (diff) | |
| download | system_core-4fab9ac04e444f8ad057e67006320ca25381948e.tar.gz system_core-4fab9ac04e444f8ad057e67006320ca25381948e.tar.bz2 system_core-4fab9ac04e444f8ad057e67006320ca25381948e.zip | |
libcutils: hashmap: save next pointer in forEach before calling callback
If the callback passed to forEach tries to remove the element it was passed,
there's a use-after-free of the entry pointer in forEach.
Change-Id: Ia364b4775c9c55780b23f683b30cbff511b7f944
Signed-off-by: Dima Zavin <dima@android.com>
Diffstat (limited to 'libcutils')
| -rw-r--r-- | libcutils/hashmap.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/libcutils/hashmap.c b/libcutils/hashmap.c index e29bc246..65539ea3 100644 --- a/libcutils/hashmap.c +++ b/libcutils/hashmap.c @@ -310,10 +310,11 @@ void hashmapForEach(Hashmap* map, for (i = 0; i < map->bucketCount; i++) { Entry* entry = map->buckets[i]; while (entry != NULL) { + Entry *next = entry->next; if (!callback(entry->key, entry->value, context)) { return; } - entry = entry->next; + entry = next; } } } |
