Handle certain unlikely format violations

This commit is contained in:
Stephen Gallagher 2018-02-15 20:37:35 -05:00
parent b68eb69e41
commit d0df9e74ca
No known key found for this signature in database
GPG Key ID: 7A25556236BAA3A3
3 changed files with 118 additions and 1 deletions

View File

@ -0,0 +1,54 @@
From e44cb185d1e6d18960c648b8233e4a71e458444f Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Thu, 15 Feb 2018 20:30:12 -0500
Subject: [PATCH] Be stricter about simpleset_from_sequence
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
---
modulemd/modulemd-yaml-parser.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/modulemd/modulemd-yaml-parser.c b/modulemd/modulemd-yaml-parser.c
index a1d2a3ed7ee0f89f4e0950710c79747743778d13..16daaddff1e1f82ba6761c39ba47819e5e2a281b 100644
--- a/modulemd/modulemd-yaml-parser.c
+++ b/modulemd/modulemd-yaml-parser.c
@@ -2257,10 +2257,11 @@ static gboolean
_simpleset_from_sequence (yaml_parser_t *parser,
ModulemdSimpleSet **_set,
GError **error)
{
yaml_event_t event;
+ gboolean started = FALSE;
gboolean done = FALSE;
ModulemdSimpleSet *set = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -2276,18 +2277,24 @@ _simpleset_from_sequence (yaml_parser_t *parser,
switch (event.type)
{
case YAML_SEQUENCE_START_EVENT:
/* Sequence has begun */
+ started = TRUE;
break;
case YAML_SEQUENCE_END_EVENT:
/* Sequence has concluded. Return */
done = TRUE;
break;
case YAML_SCALAR_EVENT:
+ if (!started)
+ {
+ MMD_YAML_ERROR_RETURN (
+ error, "Received scalar where sequence expected");
+ }
modulemd_simpleset_add (set, (const gchar *)event.data.scalar.value);
break;
default:
/* We received a YAML event we shouldn't expect at this level */
--
2.14.3

View File

@ -0,0 +1,54 @@
From ef2e8b4914feea9b717f71dd381bf1ff09b493ea Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Thu, 15 Feb 2018 20:35:56 -0500
Subject: [PATCH 2/2] Be stricter about hashtable_from_mapping
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
---
modulemd/modulemd-yaml-parser.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/modulemd/modulemd-yaml-parser.c b/modulemd/modulemd-yaml-parser.c
index 064135fc45b15df608b4bc636c64ca736bd789ef..ebdb63abb9b970834a8e8f8859345d9adc152d9a 100644
--- a/modulemd/modulemd-yaml-parser.c
+++ b/modulemd/modulemd-yaml-parser.c
@@ -2320,10 +2320,11 @@ static gboolean
_hashtable_from_mapping (yaml_parser_t *parser,
GHashTable **_htable,
GError **error)
{
yaml_event_t event;
+ gboolean started = FALSE;
gboolean done = FALSE;
GHashTable *htable = NULL;
gchar *name = NULL;
gchar *value = NULL;
@@ -2339,18 +2340,24 @@ _hashtable_from_mapping (yaml_parser_t *parser,
switch (event.type)
{
case YAML_MAPPING_START_EVENT:
/* The dictionary has begun */
+ started = TRUE;
break;
case YAML_MAPPING_END_EVENT:
/* We've processed the whole dictionary */
done = TRUE;
break;
case YAML_SCALAR_EVENT:
+ if (!started)
+ {
+ MMD_YAML_ERROR_RETURN (
+ error, "Received scalar where mapping expected");
+ }
name = g_strdup ((const gchar *)event.data.scalar.value);
YAML_PARSER_PARSE_WITH_ERROR_RETURN (
parser, &event, error, "Parser error");
if (event.type != YAML_SCALAR_EVENT)
{
--
2.14.3

View File

@ -5,7 +5,7 @@
Name: libmodulemd
Version: %{majorminorversion}%{?patchversion:.%{patchversion}}
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Module metadata manipulation library
License: MIT
@ -20,6 +20,12 @@ BuildRequires: pkgconfig(yaml-0.1)
BuildRequires: pkgconfig(gtk-doc)
BuildRequires: pkgconfig(popt)
# Patches
# Upstream patches for proper sequence and mapping validation
Patch0001: 0001-Be-stricter-about-simpleset_from_sequence.patch
Patch0002: 0002-Be-stricter-about-hashtable_from_mapping.patch
%description
C Library for manipulating module metadata files.
See https://pagure.io/modulemd for more details.
@ -66,6 +72,9 @@ export LC_CTYPE=C.utf8
%{_datadir}/gtk-doc/html/modulemd/
%changelog
* Thu Feb 15 2018 Stephen Gallagher <sgallagh@redhat.com> - 1.0.1-2
- Handle certain unlikely format violations
* Thu Feb 15 2018 Stephen Gallagher <sgallagh@redhat.com> - 1.0.1-1
- Support modulemd v2
- Add tool to do quick validation of modulemd