Fix unbounded recursion CVEs
authorSimon Quigley <tsimonq2@debian.org>
Mon, 22 Mar 2021 21:04:27 +0000 (21:04 +0000)
committerMatthias Klose <doko@ubuntu.com>
Mon, 22 Mar 2021 21:04:27 +0000 (21:04 +0000)
commite98831e21c0aac22d5620be2cf2494feee02038a
tree7a101d2f7f39014996c198585d54bbefb6f516d2
parent2bb2164f997287f65a74736603721e736bf81b38
Fix unbounded recursion CVEs

Origin: https://github.com/jbeder/yaml-cpp/pull/807
Forwarded: yes
Bug: https://github.com/jbeder/yaml-cpp/issues/459
Bug: https://github.com/jbeder/yaml-cpp/issues/655
Bug: https://github.com/jbeder/yaml-cpp/issues/654
Bug: https://github.com/jbeder/yaml-cpp/issues/660

This cherry-picks the (so-far-unmerged) upstream pull request.
The final 5 commits of that PR are not included; they only add tests
to a file not present in the 0.6.2 (or 0.6.3) release.

From d540476e31b080aa1f903ad20ec0426dd3838be7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= <anarcat@debian.org>
Date: Tue, 25 Apr 2017 20:10:20 -0400
Subject: [PATCH 1/9] fix stack overflow in HandleNode() (CVE-2017-5950)

simply set a hardcoded recursion limit to 2000 (inspired by Python's)
to avoid infinitely recursing into arbitrary data structures

assert() the depth. unsure if this is the right approach, but given
that HandleNode() is "void", I am not sure how else to return an
error. the problem with this approach of course is that it will still
crash the caller, unless they have proper exception handling in place.

Closes: #459
Gbp-Pq: Name fix-unbounded-recursion-depth.patch
include/yaml-cpp/depthguard.h [new file with mode: 0644]
src/depthguard.cpp [new file with mode: 0644]
src/singledocparser.cpp
src/singledocparser.h