浏览代码

cookie reader npe fix

jrivard 10 年之前
父节点
当前提交
b2abf96adf
共有 1 个文件被更改,包括 8 次插入5 次删除
  1. 8 5
      pwm/servlet/src/password/pwm/http/PwmHttpRequestWrapper.java

+ 8 - 5
pwm/servlet/src/password/pwm/http/PwmHttpRequestWrapper.java

@@ -325,13 +325,16 @@ public abstract class PwmHttpRequestWrapper {
     public String readCookie(final String cookieName) {
         final int maxChars = Integer.parseInt(configuration.readAppProperty(AppProperty.HTTP_COOKIE_MAX_READ_LENGTH));
         final Cookie[] cookies = this.getHttpServletRequest().getCookies();
-        for (final Cookie cookie : cookies) {
-            if (cookie.getName() != null && cookie.getName().equals(cookieName)) {
-                final String rawCookieValue = cookie.getValue();
-                final String decodedCookieValue = StringUtil.urlDecode(rawCookieValue);
-                return Validator.sanitizeInputValue(configuration, decodedCookieValue, maxChars);
+        if (cookies != null) {
+            for (final Cookie cookie : cookies) {
+                if (cookie.getName() != null && cookie.getName().equals(cookieName)) {
+                    final String rawCookieValue = cookie.getValue();
+                    final String decodedCookieValue = StringUtil.urlDecode(rawCookieValue);
+                    return Validator.sanitizeInputValue(configuration, decodedCookieValue, maxChars);
+                }
             }
         }
+
         return null;
     }