summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-11-10 15:05:56 +0000
committerVincent Sanders <vince@kyllikki.org>2014-11-10 15:09:57 +0000
commitdf8c6c3ad758fbcd88fbbe7fb53221a32ae3abe2 (patch)
tree35bbd4c6b8cd628ee8da82a2207f4aeb520e204e /desktop
parent72f4c4f8b8bae950bbd0d38379e2be458bb91273 (diff)
downloadnetsurf-df8c6c3ad758fbcd88fbbe7fb53221a32ae3abe2.tar.gz
netsurf-df8c6c3ad758fbcd88fbbe7fb53221a32ae3abe2.tar.bz2
Avoid calling calloc with 0 length data.
CERT MEM04-C suggests that zero length allocations behaviour might be surprising so it should be avoided. This adds a check to ensure a zero length allocation will be avoided. Additionally it returns errors to the caller rather than warning directly (in some error paths)
Diffstat (limited to 'desktop')
-rw-r--r--desktop/frames.c40
-rw-r--r--desktop/frames.h9
2 files changed, 33 insertions, 16 deletions
diff --git a/desktop/frames.c b/desktop/frames.c
index 3e5556f5c..934217761 100644
--- a/desktop/frames.c
+++ b/desktop/frames.c
@@ -180,14 +180,8 @@ void browser_window_handle_scrollbars(struct browser_window *bw)
}
-/**
- * Create and open a iframes for a browser window.
- *
- * \param bw The browser window to create iframes for
- * \param iframe The iframes to create
- */
-
-void browser_window_create_iframes(struct browser_window *bw,
+/* exported function documented in desktop/frames.h */
+nserror browser_window_create_iframes(struct browser_window *bw,
struct content_html_iframe *iframe)
{
struct browser_window *window;
@@ -195,12 +189,22 @@ void browser_window_create_iframes(struct browser_window *bw,
struct rect rect;
int iframes = 0;
int index;
+ nserror ret = NSERROR_OK;
- for (cur = iframe; cur; cur = cur->next)
+ if (iframe == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /* Count iframe list and allocate enough space within the
+ * browser window.
+ */
+ for (cur = iframe; cur; cur = cur->next) {
iframes++;
+ }
bw->iframes = calloc(iframes, sizeof(*bw));
- if (!bw->iframes)
- return;
+ if (!bw->iframes) {
+ return NSERROR_NOMEM;
+ }
bw->iframe_count = iframes;
index = 0;
@@ -220,10 +224,14 @@ void browser_window_create_iframes(struct browser_window *bw,
window->margin_width = cur->margin_width;
window->margin_height = cur->margin_height;
window->scale = bw->scale;
- if (cur->name) {
+ if (cur->name != NULL) {
window->name = strdup(cur->name);
- if (!window->name)
- warn_user("NoMemory", 0);
+ if (window->name == NULL) {
+ free(bw->iframes) ;
+ bw->iframes = 0;
+ bw->iframe_count = 0;
+ return NSERROR_NOMEM;
+ }
}
/* linking */
@@ -248,7 +256,7 @@ void browser_window_create_iframes(struct browser_window *bw,
window = &(bw->iframes[index++]);
if (cur->url) {
/* fetch iframe's content */
- browser_window_navigate(window,
+ ret = browser_window_navigate(window,
cur->url,
hlcache_handle_get_url(bw->current_content),
BW_NAVIGATE_UNVERIFIABLE,
@@ -257,6 +265,8 @@ void browser_window_create_iframes(struct browser_window *bw,
bw->current_content);
}
}
+
+ return ret;
}
diff --git a/desktop/frames.h b/desktop/frames.h
index 15efb7d67..bca7f2e68 100644
--- a/desktop/frames.h
+++ b/desktop/frames.h
@@ -25,7 +25,14 @@
struct scrollbar_msg_data;
-void browser_window_create_iframes(struct browser_window *bw,
+/**
+ * Create and open iframes for a browser window.
+ *
+ * \param bw The browser window to create iframes for.
+ * \param iframe The iframes to create from.
+ * \param NSERROR_OK or error code on faliure.
+ */
+nserror browser_window_create_iframes(struct browser_window *bw,
struct content_html_iframe *iframe);
void browser_window_recalculate_iframes(struct browser_window *bw);
void browser_window_create_frameset(struct browser_window *bw,