Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/hch/vfs...
[pandora-kernel.git] / security / tomoyo / realpath.c
index 6c601bd..738bbdf 100644 (file)
 #include "../../fs/internal.h"
 
 /**
- * tomoyo_encode: Convert binary string to ascii string.
+ * tomoyo_encode2 - Encode binary string to ascii string.
  *
- * @str: String in binary format.
+ * @str:     String in binary format.
+ * @str_len: Size of @str in byte.
  *
  * Returns pointer to @str in ascii format on success, NULL otherwise.
  *
  * This function uses kzalloc(), so caller must kfree() if this function
  * didn't return NULL.
  */
-char *tomoyo_encode(const char *str)
+char *tomoyo_encode2(const char *str, int str_len)
 {
+       int i;
        int len = 0;
        const char *p = str;
        char *cp;
@@ -33,8 +35,9 @@ char *tomoyo_encode(const char *str)
 
        if (!p)
                return NULL;
-       while (*p) {
-               const unsigned char c = *p++;
+       for (i = 0; i < str_len; i++) {
+               const unsigned char c = p[i];
+
                if (c == '\\')
                        len += 2;
                else if (c > ' ' && c < 127)
@@ -49,8 +52,8 @@ char *tomoyo_encode(const char *str)
                return NULL;
        cp0 = cp;
        p = str;
-       while (*p) {
-               const unsigned char c = *p++;
+       for (i = 0; i < str_len; i++) {
+               const unsigned char c = p[i];
 
                if (c == '\\') {
                        *cp++ = '\\';
@@ -67,6 +70,21 @@ char *tomoyo_encode(const char *str)
        return cp0;
 }
 
+/**
+ * tomoyo_encode - Encode binary string to ascii string.
+ *
+ * @str: String in binary format.
+ *
+ * Returns pointer to @str in ascii format on success, NULL otherwise.
+ *
+ * This function uses kzalloc(), so caller must kfree() if this function
+ * didn't return NULL.
+ */
+char *tomoyo_encode(const char *str)
+{
+       return str ? tomoyo_encode2(str, strlen(str)) : NULL;
+}
+
 /**
  * tomoyo_get_absolute_path - Get the path of a dentry but ignores chroot'ed root.
  *