Skip to content
Snippets Groups Projects
Commit fcec18c164be authored by websnarf's avatar websnarf
Browse files

Fix from mike.steinert@gmail.com for uuDecode leak. Add bSGMLEncode().

parent 3f86efd84003
No related branches found
No related tags found
No related merge requests found
...@@ -600,5 +600,7 @@ ...@@ -600,5 +600,7 @@
b = bfromcstralloc (256, ""); b = bfromcstralloc (256, "");
if (NULL == b || 0 > bsread (b, d, INT_MAX)) { if (NULL == b || 0 > bsread (b, d, INT_MAX)) {
bdestroy (b); bdestroy (b);
b = NULL;
}
bsclose (d); bsclose (d);
bsclose (s); bsclose (s);
...@@ -603,7 +605,5 @@ ...@@ -603,7 +605,5 @@
bsclose (d); bsclose (d);
bsclose (s); bsclose (s);
return NULL;
}
return b; return b;
} }
...@@ -838,6 +838,24 @@ ...@@ -838,6 +838,24 @@
return out; return out;
} }
/* int bSGMLEncode (bstring b)
*
* Change the string into a version that is quotable in SGML (HTML, XML).
*/
int bSGMLEncode (bstring b) {
static struct tagbstring fr[4][2] = {
{ bsStatic("&"), bsStatic("&") },
{ bsStatic("\""), bsStatic(""") },
{ bsStatic("<"), bsStatic("&lt;") },
{ bsStatic(">"), bsStatic("&gt;") } };
int i;
for (i = 0; i < 4; i++) {
int ret = bfindreplace (b, &fr[i][0], &fr[i][1], 0);
if (0 > ret) return ret;
}
return 0;
}
/* bstring bStrfTime (const char * fmt, const struct tm * timeptr) /* bstring bStrfTime (const char * fmt, const struct tm * timeptr)
* *
* Takes a format string that is compatible with strftime and a struct tm * Takes a format string that is compatible with strftime and a struct tm
......
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
extern bstring bUuEncode (const_bstring src); extern bstring bUuEncode (const_bstring src);
extern bstring bYEncode (const_bstring src); extern bstring bYEncode (const_bstring src);
extern bstring bYDecode (const_bstring src); extern bstring bYDecode (const_bstring src);
extern int bSGMLEncode (bstring b);
/* Writable stream */ /* Writable stream */
typedef int (* bNwrite) (const void * buf, size_t elsize, size_t nelem, void * parm); typedef int (* bNwrite) (const void * buf, size_t elsize, size_t nelem, void * parm);
......
...@@ -379,6 +379,23 @@ ...@@ -379,6 +379,23 @@
return ret; return ret;
} }
int test14_aux(bstring b, const char* chkVal) {
int ret = 0;
ret += 0 != bSGMLEncode (b);
ret += 1 != biseqcstr (b, chkVal);
return ret;
}
int test14 (void) {
bstring b;
int ret = 0;
printf ("TEST: bSGMLEncode.\n");
ret += test14_aux (b = bfromStatic ("<\"Hello, you, me, & world\">"), "&lt;&quot;Hello, you, me, &amp; world&quot;&gt;");
printf ("\t# failures: %d\n", ret);
return ret;
}
int main () { int main () {
int ret = 0; int ret = 0;
...@@ -398,6 +415,7 @@ ...@@ -398,6 +415,7 @@
ret += test11 (); ret += test11 ();
ret += test12 (); ret += test12 ();
ret += test13 (); ret += test13 ();
ret += test14 ();
printf ("# test failures: %d\n", ret); printf ("# test failures: %d\n", ret);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment