]> granicus.if.org Git - postgresql/commitdiff
Add checks for valid multibyte character length in UtfToLocal, LocalToUtf.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Jul 2013 01:55:38 +0000 (21:55 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Jul 2013 01:55:38 +0000 (21:55 -0400)
This is mainly to suppress "uninitialized variable" warnings from very
recent versions of gcc.  But it seems like a good robustness thing anyway,
not to mention that we might someday decide to support 6-byte UTF8.

Per report from Karol Trzcionka.  No back-patch since there's no reason
at the moment to think this is more than cosmetic.

src/backend/utils/mb/conv.c

index ab2e966f1cf791d1b2c3e5295dd1bc4767c7386e..63a2d4a8fb0540b0b813ec20e8ce36d5f1ddb35f 100644 (file)
@@ -382,6 +382,11 @@ UtfToLocal(const unsigned char *utf, unsigned char *iso,
                        iutf |= *utf++ << 8;
                        iutf |= *utf++;
                }
+               else
+               {
+                       elog(ERROR, "unsupported character length %d", l);
+                       iutf = 0;                       /* keep compiler quiet */
+               }
 
                /*
                 * first, try with combined map if possible
@@ -437,6 +442,11 @@ UtfToLocal(const unsigned char *utf, unsigned char *iso,
                                iutf |= *utf++ << 8;
                                iutf |= *utf++;
                        }
+                       else
+                       {
+                               elog(ERROR, "unsupported character length %d", l);
+                               iutf = 0;               /* keep compiler quiet */
+                       }
 
                        cutf[1] = iutf;
                        cp = bsearch(cutf, cmap, size2,
@@ -546,6 +556,11 @@ LocalToUtf(const unsigned char *iso, unsigned char *utf,
                        iiso |= *iso++ << 8;
                        iiso |= *iso++;
                }
+               else
+               {
+                       elog(ERROR, "unsupported character length %d", l);
+                       iiso = 0;                       /* keep compiler quiet */
+               }
 
                p = bsearch(&iiso, map, size1,
                                        sizeof(pg_local_to_utf), compare2);