diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2015-05-26 11:29:21 -0300 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2015-05-26 11:29:21 -0300 |
commit | c7aefa2cd7ef9bae68773df9f338da4b44a76d73 (patch) | |
tree | 460cd0d429069705e07af8c3b403ede439e669e2 /dpip | |
parent | 02a3ee925afe16af350979f679df869164dd39c2 (diff) |
Fix view-source dpi to handle null characters correctly
Although not allowed in text contexts, null characters should not
stop/halt/fail dpi protocol, thus the patch.
Test Example. Display a file with these contents:
null padding^@^@
(two trailing null characters)
and view source for it.
Note that dillo will not _display_ the file completely correct,
it will eat a char after each null, but this is not a problem in
dpi nor dpip but in rendering, the cache gets it right.
Adding code to correctly _display_ these anomalous pages is probably
not worth the effort though.
Diffstat (limited to 'dpip')
-rw-r--r-- | dpip/dpip.c | 21 | ||||
-rw-r--r-- | dpip/dpip.h | 1 |
2 files changed, 19 insertions, 3 deletions
diff --git a/dpip/dpip.c b/dpip/dpip.c index f4ce1bf0..2906ba2a 100644 --- a/dpip/dpip.c +++ b/dpip/dpip.c @@ -1,7 +1,7 @@ /* * File: dpip.c * - * Copyright 2005-2007 Jorge Arellano Cid <jcid@dillo.org> + * Copyright 2005-2015 Jorge Arellano Cid <jcid@dillo.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -427,11 +427,13 @@ static void Dpip_dsh_read(Dsh *dsh, int blocking) /* * Return a newlly allocated string with the next dpip token in the socket. - * Return value: token string on success, NULL otherwise + * Return value: token string and length on success, NULL otherwise. + * (useful for handling null characters in the data stream) */ -char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) +char *a_Dpip_dsh_read_token2(Dsh *dsh, int blocking, int *DataSize) { char *p, *ret = NULL; + *DataSize = 0; /* Read all available data without blocking */ Dpip_dsh_read(dsh, 0); @@ -462,6 +464,7 @@ char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) /* return a full tag */ if ((p = strstr(dsh->rdbuf->str, DPIP_TAG_END))) { ret = dStrndup(dsh->rdbuf->str, p - dsh->rdbuf->str + 3); + *DataSize = p - dsh->rdbuf->str + 3; dStr_erase(dsh->rdbuf, 0, p - dsh->rdbuf->str + 3); if (strstr(ret, DPIP_MODE_SWITCH_TAG)) dsh->mode |= DPIP_LAST_TAG; @@ -470,6 +473,7 @@ char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) /* raw mode, return what we have "as is" */ if (dsh->rdbuf->len > 0) { ret = dStrndup(dsh->rdbuf->str, dsh->rdbuf->len); + *DataSize = dsh->rdbuf->len; dStr_truncate(dsh->rdbuf, 0); } } @@ -478,6 +482,17 @@ char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) } /* + * Return a newlly allocated string with the next dpip token in the socket. + * Return value: token string on success, NULL otherwise + */ +char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking) +{ + int token_size; + + return a_Dpip_dsh_read_token2(dsh, blocking, &token_size); +} + +/* * Close this socket for reading and writing. * (flush pending data) */ diff --git a/dpip/dpip.h b/dpip/dpip.h index 1a1846df..a63eb658 100644 --- a/dpip/dpip.h +++ b/dpip/dpip.h @@ -70,6 +70,7 @@ int a_Dpip_dsh_write_str(Dsh *dsh, int flush, const char *str); int a_Dpip_dsh_tryflush(Dsh *dsh); int a_Dpip_dsh_trywrite(Dsh *dsh, const char *Data, int DataSize); char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking); +char *a_Dpip_dsh_read_token2(Dsh *dsh, int blocking, int *DataSize); void a_Dpip_dsh_close(Dsh *dsh); void a_Dpip_dsh_free(Dsh *dsh); |