Browse code

pdf: chomp whitespace off read values

Kevin Lin authored on 2016/04/15 00:16:43
Showing 1 changed files
... ...
@@ -1805,6 +1805,7 @@ static char *pdf_readval(const char *q, int len, const char *key)
1805 1805
 {
1806 1806
     const char *end;
1807 1807
     char *s;
1808
+    int origlen = len;
1808 1809
 
1809 1810
     q = pdf_getdict(q, &len, key);
1810 1811
     if (!q || len <= 0)
... ...
@@ -1827,6 +1828,12 @@ static char *pdf_readval(const char *q, int len, const char *key)
1827 1827
         len--;
1828 1828
     }
1829 1829
 
1830
+    /* end-of-buffer whitespace trimming */
1831
+    while (len < origlen && isspace(*(end-1))) {
1832
+        end--;
1833
+        len++;
1834
+    }
1835
+
1830 1836
     s = cli_malloc(end - q + 1);
1831 1837
     if (!s)
1832 1838
         return NULL;