summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2016-07-24 13:59:30 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2016-07-24 14:03:16 +0100
commitfa2e3b778465cd496aedde8e187038835a765c4f (patch)
tree106aaf119a4b3925769adb49479274f3c886a148 /frontends
parentcf753f20cc2a8506c831a5cedd933e3e78417261 (diff)
downloadnetsurf-fa2e3b778465cd496aedde8e187038835a765c4f.tar.gz
netsurf-fa2e3b778465cd496aedde8e187038835a765c4f.tar.bz2
URL unescape: return the new length to the caller.
The avoids situations were we threw away the length, only for the caller to have to strlen the returned string. Note, there seems to be a case of the amiga front end writing beyond end of allocation. Added a TODO for now.
Diffstat (limited to 'frontends')
-rwxr-xr-xfrontends/amiga/misc.c10
-rw-r--r--frontends/atari/file.c4
-rw-r--r--frontends/beos/gui.cpp2
-rw-r--r--frontends/riscos/download.c1
-rw-r--r--frontends/riscos/gui.c6
-rw-r--r--frontends/windows/file.c1
6 files changed, 16 insertions, 8 deletions
diff --git a/frontends/amiga/misc.c b/frontends/amiga/misc.c
index 238865120..f15eb48d9 100755
--- a/frontends/amiga/misc.c
+++ b/frontends/amiga/misc.c
@@ -189,6 +189,7 @@ int32 amiga_warn_user_multi(const char *body, const char *opt1, const char *opt2
static nserror amiga_nsurl_to_path(struct nsurl *url, char **path_out)
{
lwc_string *urlpath;
+ size_t path_len;
char *path;
bool match;
lwc_string *scheme;
@@ -217,7 +218,7 @@ static nserror amiga_nsurl_to_path(struct nsurl *url, char **path_out)
return NSERROR_BAD_PARAMETER;
}
- res = url_unescape(lwc_string_data(urlpath) + 1, 0, &path);
+ res = url_unescape(lwc_string_data(urlpath) + 1, 0, &path_len, &path);
lwc_string_unref(urlpath);
if (res != NSERROR_OK) {
return res;
@@ -233,9 +234,10 @@ static nserror amiga_nsurl_to_path(struct nsurl *url, char **path_out)
}
else
{
- int len = strlen(path);
- path[len] = ':';
- path[len + 1] = '\0';
+ path[path_len] = ':';
+ /* TODO: Looks like we are writing past the end of
+ * path's allocation here. */
+ path[path_len + 1] = '\0';
}
}
diff --git a/frontends/atari/file.c b/frontends/atari/file.c
index 7bc11dabc..3816e476d 100644
--- a/frontends/atari/file.c
+++ b/frontends/atari/file.c
@@ -112,6 +112,7 @@ static nserror atari_basename(const char *path, char **str, size_t *size)
static nserror atari_nsurl_to_path(struct nsurl *url, char **path_out)
{
lwc_string *urlpath;
+ size_t path_len;
char *path;
bool match;
lwc_string *scheme;
@@ -140,6 +141,7 @@ static nserror atari_nsurl_to_path(struct nsurl *url, char **path_out)
res = url_unescape(lwc_string_data(urlpath),
lwc_string_length(urlpath),
+ &path_len,
&path);
lwc_string_unref(urlpath);
if (res != NSERROR_OK) {
@@ -153,7 +155,7 @@ static nserror atari_nsurl_to_path(struct nsurl *url, char **path_out)
* strlen is *not* copying too much data as we are
* moving the null too!
*/
- memmove(path, path + 1, strlen(path));
+ memmove(path, path + 1, path_len);
}
/* if the path does not have a drive letter we return the
* complete path.
diff --git a/frontends/beos/gui.cpp b/frontends/beos/gui.cpp
index 53387ad07..8c6614d17 100644
--- a/frontends/beos/gui.cpp
+++ b/frontends/beos/gui.cpp
@@ -797,7 +797,7 @@ static char *url_to_path(const char *url)
char *url_path;
char *path = NULL;
- if (url_unescape(url, 0, &url_path) == NSERROR_OK) {
+ if (url_unescape(url, 0, NULL, &url_path) == NSERROR_OK) {
/* return the absolute path including leading / */
path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1));
free(url_path);
diff --git a/frontends/riscos/download.c b/frontends/riscos/download.c
index 1a0249e20..561409ed1 100644
--- a/frontends/riscos/download.c
+++ b/frontends/riscos/download.c
@@ -241,6 +241,7 @@ static nserror download_ro_filetype(download_context *ctx, bits *ftype_out)
char *raw_path;
if (url_unescape(lwc_string_data(path),
lwc_string_length(path),
+ NULL,
&raw_path) == NSERROR_OK) {
ftype = ro_filetype_from_unix_path(raw_path);
free(raw_path);
diff --git a/frontends/riscos/gui.c b/frontends/riscos/gui.c
index f55392f99..72eeb6282 100644
--- a/frontends/riscos/gui.c
+++ b/frontends/riscos/gui.c
@@ -1485,6 +1485,7 @@ static nserror ro_path_to_nsurl(const char *path, struct nsurl **url_out)
static nserror ro_nsurl_to_path(struct nsurl *url, char **path_out)
{
lwc_string *urlpath;
+ size_t unpath_len;
char *unpath;
char *path;
bool match;
@@ -1515,6 +1516,7 @@ static nserror ro_nsurl_to_path(struct nsurl *url, char **path_out)
res = url_unescape(lwc_string_data(urlpath),
lwc_string_length(urlpath),
+ &unpath_len,
&unpath);
lwc_string_unref(urlpath);
if (res != NSERROR_OK) {
@@ -1522,14 +1524,14 @@ static nserror ro_nsurl_to_path(struct nsurl *url, char **path_out)
}
/* RISC OS path should not be more than 100 characters longer */
- path = malloc(strlen(unpath) + 100);
+ path = malloc(unpath_len + 100);
if (path == NULL) {
free(unpath);
return NSERROR_NOMEM;
}
r = __riscosify(unpath, 0, __RISCOSIFY_NO_SUFFIX,
- path, strlen(unpath) + 100, 0);
+ path, unpath_len + 100, 0);
free(unpath);
if (r == NULL) {
free(path);
diff --git a/frontends/windows/file.c b/frontends/windows/file.c
index 7583790e9..90e6ef458 100644
--- a/frontends/windows/file.c
+++ b/frontends/windows/file.c
@@ -143,6 +143,7 @@ static nserror windows_nsurl_to_path(struct nsurl *url, char **path_out)
res = url_unescape(lwc_string_data(urlpath),
lwc_string_length(urlpath),
+ NULL,
&path);
lwc_string_unref(urlpath);
if (res != NSERROR_OK) {