Merge branch 'akpm' (Andrew's patch-bomb)
[firefly-linux-kernel-4.4.55.git] / security / selinux / hooks.c
index ec43760a8a03e691997697480063812b7f5bbf6e..6c77f63c759198ead061712fb3bad1166c4ace2a 100644 (file)
@@ -2791,11 +2791,16 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
 
                        /* We strip a nul only if it is at the end, otherwise the
                         * context contains a nul and we should audit that */
-                       str = value;
-                       if (str[size - 1] == '\0')
-                               audit_size = size - 1;
-                       else
-                               audit_size = size;
+                       if (value) {
+                               str = value;
+                               if (str[size - 1] == '\0')
+                                       audit_size = size - 1;
+                               else
+                                       audit_size = size;
+                       } else {
+                               str = "";
+                               audit_size = 0;
+                       }
                        ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_SELINUX_ERR);
                        audit_log_format(ab, "op=setxattr invalid_context=");
                        audit_log_n_untrustedstring(ab, value, audit_size);