Commit 5bff4d1a6baed5725e72ceff0ebd790d472a7c99

Authored by Andrii Shvaika
1 parent d190cba2

Fix NPE in Redis Security Store

@@ -46,7 +46,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { @@ -46,7 +46,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
46 lock = redisLock.obtain(toLockKey(endpoint)); 46 lock = redisLock.obtain(toLockKey(endpoint));
47 lock.lock(); 47 lock.lock();
48 byte[] data = connection.get((SEC_EP + endpoint).getBytes()); 48 byte[] data = connection.get((SEC_EP + endpoint).getBytes());
49 - if (data == null) { 49 + if (data == null || data.length == 0) {
50 return null; 50 return null;
51 } else { 51 } else {
52 return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo(); 52 return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
@@ -69,7 +69,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { @@ -69,7 +69,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
69 return null; 69 return null;
70 } else { 70 } else {
71 byte[] data = connection.get((SEC_EP + new String(ep)).getBytes()); 71 byte[] data = connection.get((SEC_EP + new String(ep)).getBytes());
72 - if (data == null) { 72 + if (data == null || data.length == 0) {
73 return null; 73 return null;
74 } else { 74 } else {
75 return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo(); 75 return ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
@@ -122,7 +122,11 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { @@ -122,7 +122,11 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
122 lock = redisLock.obtain(endpoint); 122 lock = redisLock.obtain(endpoint);
123 lock.lock(); 123 lock.lock();
124 byte[] data = connection.get((SEC_EP + endpoint).getBytes()); 124 byte[] data = connection.get((SEC_EP + endpoint).getBytes());
125 - return (TbLwM2MSecurityInfo) serializer.asObject(data); 125 + if (data != null && data.length > 0) {
  126 + return (TbLwM2MSecurityInfo) serializer.asObject(data);
  127 + } else {
  128 + return null;
  129 + }
126 } finally { 130 } finally {
127 if (lock != null) { 131 if (lock != null) {
128 lock.unlock(); 132 lock.unlock();
@@ -137,7 +141,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { @@ -137,7 +141,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore {
137 lock = redisLock.obtain(endpoint); 141 lock = redisLock.obtain(endpoint);
138 lock.lock(); 142 lock.lock();
139 byte[] data = connection.get((SEC_EP + endpoint).getBytes()); 143 byte[] data = connection.get((SEC_EP + endpoint).getBytes());
140 - if (data != null) { 144 + if (data != null && data.length > 0) {
141 SecurityInfo info = ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo(); 145 SecurityInfo info = ((TbLwM2MSecurityInfo) serializer.asObject(data)).getSecurityInfo();
142 if (info != null && info.getIdentity() != null) { 146 if (info != null && info.getIdentity() != null) {
143 connection.hDel(PSKID_SEC.getBytes(), info.getIdentity().getBytes()); 147 connection.hDel(PSKID_SEC.getBytes(), info.getIdentity().getBytes());