components/proftpd/patches/encode-bug3769.patch
author Tomas Klacko <tomas.klacko@oracle.com>
Wed, 16 May 2012 01:39:44 -0700
changeset 816 5df727abb287
permissions -rw-r--r--
7155867 *proftpd* does not work in multibyte locale other than UTF-8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
816
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     1
--- a/src/encode.c
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     2
+++ b/src/encode.c
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     3
@@ -194,10 +194,12 @@ int encode_init(void) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     4
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     5
 char *pr_decode_str(pool *p, const char *in, size_t inlen, size_t *outlen) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     6
 #ifdef HAVE_ICONV
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     7
-  size_t inbuflen, outbuflen;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     8
+  size_t inbuflen, outbuflen, outbufsz;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
     9
   char *inbuf, outbuf[PR_TUNABLE_PATH_MAX*2], *res = NULL;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    10
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    11
-  if (!p || !in || !outlen) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    12
+  if (p == NULL ||
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    13
+      in == NULL ||
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    14
+      outlen == NULL) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    15
     errno = EINVAL;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    16
     return NULL;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    17
   }
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    18
@@ -229,7 +231,11 @@ char *pr_decode_str(pool *p, const char *in, size_t inlen, size_t *outlen) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    19
     return NULL;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    20
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    21
   *outlen = sizeof(outbuf) - outbuflen;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    22
-  res = pcalloc(p, *outlen);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    23
+
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    24
+  /* We allocate one byte more, for a terminating NUL. */
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    25
+  outbufsz = sizeof(outbuf) - outbuflen + 1;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    26
+  res = pcalloc(p, outbufsz);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    27
+
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    28
   memcpy(res, outbuf, *outlen);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    29
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    30
   return res;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    31
@@ -242,10 +248,12 @@ char *pr_decode_str(pool *p, const char *in, size_t inlen, size_t *outlen) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    32
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    33
 char *pr_encode_str(pool *p, const char *in, size_t inlen, size_t *outlen) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    34
 #ifdef HAVE_ICONV
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    35
-  size_t inbuflen, outbuflen;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    36
+  size_t inbuflen, outbuflen, outbufsz;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    37
   char *inbuf, outbuf[PR_TUNABLE_PATH_MAX*2], *res;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    38
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    39
-  if (!p || !in || !outlen) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    40
+  if (p == NULL ||
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    41
+      in == NULL ||
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    42
+      outlen == NULL) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    43
     errno = EINVAL;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    44
     return NULL;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    45
   }
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    46
@@ -277,7 +285,11 @@ char *pr_encode_str(pool *p, const char *in, size_t inlen, size_t *outlen) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    47
     return NULL;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    48
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    49
   *outlen = sizeof(outbuf) - outbuflen;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    50
-  res = pcalloc(p, *outlen);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    51
+
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    52
+  /* We allocate one byte more, for a terminating NUL. */
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    53
+  outbufsz = sizeof(outbuf) - outbuflen + 1;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    54
+
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    55
+  res = pcalloc(p, outbufsz);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    56
   memcpy(res, outbuf, *outlen);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    57
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    58
   return res;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    59
diff --git a/src/fsio.c b/src/fsio.c
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    60
index 40ef466..8bf5069 100644
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    61
--- a/src/fsio.c
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    62
+++ b/src/fsio.c
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    63
@@ -2058,7 +2058,7 @@ char *pr_fs_decode_path(pool *p, const char *path) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    64
     return (char *) path;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    65
   }
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    66
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    67
-  res = pr_decode_str(p, path, strlen(path) + 1, &outlen);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    68
+  res = pr_decode_str(p, path, strlen(path), &outlen);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    69
   if (!res) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    70
     pr_trace_msg("encode", 1, "error decoding path '%s': %s", path,
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    71
       strerror(errno));
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    72
@@ -2081,7 +2081,7 @@ char *pr_fs_encode_path(pool *p, const char *path) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    73
     return (char *) path;
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    74
   }
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    75
 
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    76
-  res = pr_encode_str(p, path, strlen(path) + 1, &outlen);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    77
+  res = pr_encode_str(p, path, strlen(path), &outlen);
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    78
   if (!res) {
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    79
     pr_trace_msg("encode", 1, "error encoding path '%s': %s", path,
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    80
       strerror(errno));
5df727abb287 7155867 *proftpd* does not work in multibyte locale other than UTF-8
Tomas Klacko <tomas.klacko@oracle.com>
parents:
diff changeset
    81