From 95f467f4be93a3673e4ff304f9e6e5ca408922bf Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 16 Sep 2017 13:30:09 +0200 Subject: [PATCH] Fix potential bug in case of ill-formed serialized container. --- m-array.h | 5 +++-- m-deque.h | 5 +++-- m-dict.h | 5 +++-- m-list.h | 5 +++-- m-rbtree.h | 5 +++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/m-array.h b/m-array.h index 16481099..45346714 100644 --- a/m-array.h +++ b/m-array.h @@ -677,9 +677,10 @@ assert (file != NULL); \ M_C(name,_clean)(array); \ int c = fgetc(file); \ - if (c != '[') return false; \ + if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ - if (c == ']') return true; \ + if (M_UNLIKELY (c == ']')) return true; \ + if (M_UNLIKELY (c == EOF)) return false; \ ungetc(c, file); \ type item; \ M_GET_INIT oplist (item); \ diff --git a/m-deque.h b/m-deque.h index 8fb6c597..abb4ff3e 100644 --- a/m-deque.h +++ b/m-deque.h @@ -687,9 +687,10 @@ assert (file != NULL); \ M_C(name,_clean)(deque); \ int c = fgetc(file); \ - if (c != '[') return false; \ + if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ - if (c == ']') return true; \ + if (M_UNLIKELY (c == ']')) return true; \ + if (M_UNLIKELY (c == EOF)) return false; \ ungetc(c, file); \ type item; \ M_GET_INIT oplist (item); \ diff --git a/m-dict.h b/m-dict.h index bf117b1d..48713366 100644 --- a/m-dict.h +++ b/m-dict.h @@ -504,9 +504,10 @@ DICTI_CONTRACT(name, dict); \ M_C(name, _clean)(dict); \ int c = fgetc(file); \ - if (c != '{') return false; \ + if (M_UNLIKELY (c != '{')) return false; \ c = fgetc(file); \ - if (c == '}') return true; \ + if (M_UNLIKELY (c == '}')) return true; \ + if (M_UNLIKELY (c == EOF)) return true; \ ungetc(c, file); \ key_type key; \ M_IF(isSet)( ,value_type value); \ diff --git a/m-list.h b/m-list.h index 2ec36b06..f71a22d0 100644 --- a/m-list.h +++ b/m-list.h @@ -525,9 +525,10 @@ assert (file != NULL && list != NULL); \ M_C(name,_clean)(list); \ int c = fgetc(file); \ - if (c != '[') return false; \ + if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ - if (c == ']') return true; \ + if (M_UNLIKELY (c == ']')) return true; \ + if (M_UNLIKELY (c == EOF)) return false; \ ungetc(c, file); \ type item; \ M_GET_INIT oplist (item); \ diff --git a/m-rbtree.h b/m-rbtree.h index 4f363b9b..a9b26c5f 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -948,9 +948,10 @@ typedef enum { assert (file != NULL); \ M_C(name,_clean)(rbtree); \ int c = fgetc(file); \ - if (c != '[') return false; \ + if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ - if (c == ']') return true; \ + if (M_UNLIKELY (c == ']')) return true; \ + if (M_UNLIKELY (c == EOF)) return false; \ ungetc(c, file); \ type item; \ M_GET_INIT oplist (item); \