summaryrefslogtreecommitdiff
path: root/src/proxy
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2014-05-02 15:13:29 +0000
committerXavier Roche <xroche@users.noreply.github.com>2014-05-02 15:13:29 +0000
commit5544f503bf0fcfd050b4e338e8ec7b22e2f53b9a (patch)
tree2d65f1fd285c450cbb1c676697ad13b5a47a835c /src/proxy
parentb3fa8537c411e6e2d53044b1d5d20c361d2ad17d (diff)
Big cleanup in functions writing to a char buffer without proper size boundary.
Diffstat (limited to 'src/proxy')
-rwxr-xr-xsrc/proxy/proxystrings.h42
-rw-r--r--src/proxy/store.c4
2 files changed, 16 insertions, 30 deletions
diff --git a/src/proxy/proxystrings.h b/src/proxy/proxystrings.h
index 8dc371a..dc70286 100755
--- a/src/proxy/proxystrings.h
+++ b/src/proxy/proxystrings.h
@@ -85,35 +85,21 @@ HTS_UNUSED static void escapexml(const char *s, String * tempo) {
}
}
-HTS_UNUSED static char *concat(char *catbuff, const char *a, const char *b) {
- if (a != NULL && a[0] != '\0') {
- strcpy(catbuff, a);
- } else {
- catbuff[0] = '\0';
- }
- if (b != NULL && b[0] != '\0') {
- strcat(catbuff, b);
- }
- return catbuff;
-}
-
-HTS_UNUSED static char *__fconv(char *a) {
-#ifdef WIN32
- int i;
-
- for(i = 0; a[i] != 0; i++)
- if (a[i] == '/') // Unix-to-DOS style
- a[i] = '\\';
+HTS_UNUSED static char* file_convert(char *dest, size_t size, const char *src) {
+ size_t i;
+ for(i = 0 ; src[i] != '\0' && i + 1 < size ; i++) {
+#ifdef _WIN32
+ if (src[i] == '/') {
+ dest[i] = '\\';
+ } else {
#endif
- return a;
-}
-
-HTS_UNUSED static char *fconcat(char *catbuff, const char *a, const char *b) {
- return __fconv(concat(catbuff, a, b));
-}
-
-HTS_UNUSED static char *fconv(char *catbuff, const char *a) {
- return __fconv(concat(catbuff, a, ""));
+ dest[i] = src[i];
+#ifdef _WIN32
+ }
+#endif
+ }
+ dest[i] = '\0';
+ return dest;
}
#endif
diff --git a/src/proxy/store.c b/src/proxy/store.c
index 9475412..1702bc8 100644
--- a/src/proxy/store.c
+++ b/src/proxy/store.c
@@ -1157,7 +1157,7 @@ static PT_Element PT_ReadCache__New_u(PT_Index index_, const char *url,
/* Read in memory from cache */
if (flags & FETCH_BODY) {
if (strnotempty(previous_save)) {
- FILE *fp = fopen(fconv(catbuff, previous_save), "rb");
+ FILE *fp = fopen(file_convert(catbuff, sizeof(catbuff), previous_save), "rb");
if (fp != NULL) {
r->adr = (char *) malloc(r->size + 4);
@@ -1179,7 +1179,7 @@ static PT_Element PT_ReadCache__New_u(PT_Index index_, const char *url,
} else {
r->statuscode = STATUSCODE_INVALID;
sprintf(r->msg, "Read error (can't open '%s') from cache",
- fconv(catbuff, previous_save));
+ file_convert(catbuff, sizeof(catbuff), previous_save));
}
} else {
r->statuscode = STATUSCODE_INVALID;