From 9eb860d45d65a822e7336afce59bb06d68a90c72 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 9 Jul 2019 21:15:35 +0200 Subject: [PATCH] Git: handle excess of cylinders or weightsystems gracefully Currently, the git parser happily trashes memory if a git repository contains too many weightsystems or cylinders. This should only happen in testing, but nevertheless try to handle it gracefully and ignore excess cylinders / weightsystems. Signed-off-by: Berthold Stoeger --- core/load-git.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/load-git.c b/core/load-git.c index 51849501a..ee31e99ac 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -391,6 +391,9 @@ static void parse_dive_cylinder(char *line, struct membuffer *str, void *_dive) struct dive *dive = _dive; cylinder_t *cylinder = dive->cylinder + cylinder_index; + if (cylinder_index >= MAX_CYLINDERS) + return; + cylinder->type.description = get_utf8(str); for (;;) { char c; @@ -423,6 +426,9 @@ static void parse_dive_weightsystem(char *line, struct membuffer *str, void *_di struct dive *dive = _dive; weightsystem_t *ws = dive->weightsystem + weightsystem_index; + if (weightsystem_index >= MAX_WEIGHTSYSTEMS) + return; + weightsystem_index++; ws->description = get_utf8(str); for (;;) {