File pacemaker-libcrmcommon-check-sscanf-result-parsing-schema-version.patch of Package pacemaker.14737
commit f56e43b8f243858180104dbc8d386192567a092f
Author: Ken Gaillot <kgaillot@redhat.com>
Date: Mon Oct 9 16:17:25 2017 -0500
Low: libcrmcommon: check sscanf() result when parsing schema version
No effect in practice, but makes static analysis happy
Index: pacemaker/lib/common/xml.c
===================================================================
--- pacemaker.orig/lib/common/xml.c
+++ pacemaker/lib/common/xml.c
@@ -292,8 +292,11 @@ static int schema_sort(const struct dire
{
int a_version[2] = {0, 0}, b_version[2] = {0, 0};
- version_from_filename(a[0]->d_name, a_version);
- version_from_filename(b[0]->d_name, b_version);
+ if (!version_from_filename(a[0]->d_name, a_version)
+ || !version_from_filename(b[0]->d_name, b_version)) {
+ // Shouldn't be possible, but makes static analysis happy
+ return 0;
+ }
for (int i = 0; i < 2; ++i) {
if (a_version[i] < b_version[i]) {
@@ -389,13 +392,19 @@ static int __xml_build_schema_list(void)
int version[2] = { 0, 0 };
char *transform = NULL;
- version_from_filename(namelist[lpc]->d_name, version);
+ if (!version_from_filename(namelist[lpc]->d_name, version)) {
+ // Shouldn't be possible, but makes static analysis happy
+ crm_err("Skipping schema '%s': could not parse version",
+ namelist[lpc]->d_name);
+ free(namelist[lpc]);
+ continue;
+ }
if((lpc + 1) < max) {
int next_version[2] = { 0, 0 };
- version_from_filename(namelist[lpc+1]->d_name, next_version);
+ if (version_from_filename(namelist[lpc+1]->d_name, next_version)
+ && (version[0] < next_version[0])) {
- if (version[0] < next_version[0]) {
struct stat s;
char *xslt = NULL;