URL: https://github.com/freeipa/freeipa/pull/363
Author: dkupka
 Title: #363: ipaclient: schema cache: Handle malformed server info data 
gracefully
Action: opened

PR body:
"""
As a part of CLI schema cache some data about each previously contacted server
are stored in simple JSON file. The file may get corrupted and became
undecodable for various reasons (parallel access, file system error,
tampering). Since the data are not necessary we should just warn an continue.

https://fedorahosted.org/freeipa/ticket/6578
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/363/head:pr363
git checkout pr363
From a2839d52229b2d5b1e3ea1325e08a7320428924c Mon Sep 17 00:00:00 2001
From: David Kupka <dku...@redhat.com>
Date: Tue, 3 Jan 2017 08:57:21 +0100
Subject: [PATCH] ipaclient: schema cache: Handle malformed server info data
 gracefully

As a part of CLI schema cache some data about each previously contacted server
are stored in simple JSON file. The file may get corrupted and became
undecodable for various reasons (parallel access, file system error,
tampering). Since the data are not necessary we should just warn an continue.

https://fedorahosted.org/freeipa/ticket/6578
---
 ipaclient/remote_plugins/__init__.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/ipaclient/remote_plugins/__init__.py b/ipaclient/remote_plugins/__init__.py
index 9cf501f..2363a78 100644
--- a/ipaclient/remote_plugins/__init__.py
+++ b/ipaclient/remote_plugins/__init__.py
@@ -40,9 +40,14 @@ def __init__(self, api):
     def _read(self):
         try:
             with open(self._path, 'r') as sc:
-                self._dict = json.load(sc)
-        except EnvironmentError as e:
-            if e.errno != errno.ENOENT:
+                self._dict = json.loads(sc)
+        except (EnvironmentError, ValueError) as e:
+            if isinstance(e, EnvironmentError) and e.errno == errno.ENOENT:
+                # ignore non-existent file, this happens when the cache was
+                # erased or the server is contacted for the first time
+                pass
+            else:
+                # warn that the file is unreadable, probably corrupted
                 logger.warning('Failed to read server info: {}'.format(e))
 
     def _write(self):
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to