summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2014-03-01 14:29:42 +0100
committerportix <portix@gmx.net>2014-03-01 14:29:42 +0100
commit190cd57ca807829e5ffe45038eaf97028557cf32 (patch)
tree015693b4a075e221beb433686e975bac61a3ae5d
parentb42f01bdc5cbd16fc4b13c42d67691d453a9cf58 (diff)
downloaddwb-190cd57ca807829e5ffe45038eaf97028557cf32.zip
Use free for buffer allocated by exar_extract
-rw-r--r--dwbem/dwbem.c40
-rw-r--r--exar/exar.c7
-rw-r--r--exar/exar.h1
-rw-r--r--src/dwb.c6
-rw-r--r--src/scripts.c27
5 files changed, 48 insertions, 33 deletions
diff --git a/dwbem/dwbem.c b/dwbem/dwbem.c
index ae360996..4b74c109 100644
--- a/dwbem/dwbem.c
+++ b/dwbem/dwbem.c
@@ -47,8 +47,10 @@
#include <exar.h>
-#define API_BASE "https://api.bitbucket.org/1.0/repositories/portix/dwb_extensions/src/tip/src/?format=yaml"
-#define REPO_BASE "https://bitbucket.org/portix/dwb_extensions"
+#define API_BASE "https://api.bitbucket.org/1.0/repositories/portix/dwbemtest/src/tip/src/?format=yaml"
+#define REPO_BASE "https://bitbucket.org/portix/dwbemtest"
+//#define API_BASE "https://api.bitbucket.org/1.0/repositories/portix/dwb_extensions/src/tip/src/?format=yaml"
+//#define REPO_BASE "https://bitbucket.org/portix/dwb_extensions"
#define REPO_TREE "/raw/tip/src"
#define SKIP(line, c) do{ \
@@ -241,7 +243,7 @@ static char *
get_data(const char *name, const char *data, const char *template, int flags)
{
char *ret = NULL;
- char *content = NULL, *regex = NULL;
+ char *content = NULL, *regex = NULL, *econtent = NULL;
const char *new_data = NULL;
const char *format;
const char *nname = name == NULL ? "" : name;
@@ -258,12 +260,13 @@ get_data(const char *name, const char *data, const char *template, int flags)
else
{
if (exar_check_version(data) == 0) {
- content = (char*)exar_search_extract(data, "main.js", NULL);
+ econtent = (char*)exar_search_extract(data, "main.js", NULL);
+ new_data = econtent;
}
else {
g_file_get_contents(data, &content, NULL, NULL);
+ new_data = content;
}
- new_data = content;
}
if (new_data != NULL)
{
@@ -273,6 +276,7 @@ get_data(const char *name, const char *data, const char *template, int flags)
g_strfreev(matches);
}
g_free(content);
+ exar_free(econtent);
g_free(regex);
return ret;
}
@@ -728,7 +732,7 @@ install_extension(const char *name, int flags)
update_installed(name, meta);
ret = 0;
}
- g_free(content);
+ exar_free(content);
}
else if (g_file_get_contents(buffer, &content, NULL, NULL) )
{
@@ -766,9 +770,7 @@ install_extension(const char *name, int flags)
update_installed(name, meta);
ret = 0;
}
- if (content != NULL) {
- g_free(content);
- }
+ exar_free(content);
}
else
print_error("Saving %s failed", name);
@@ -1133,19 +1135,21 @@ cl_info(const char *name, int flags)
(void) flags;
SoupMessage *msg = NULL;
- char *data = NULL, *path;
+ char *path, *data = NULL;
const char *tmp;
path = g_build_filename(m_system_dir, name, NULL);
- if ((data = get_data(NULL, path, "INFO", F_MATCH_MULTILINE)) != NULL)
+ if ((data = get_data(NULL, path, "INFO", F_MATCH_MULTILINE)) != NULL) {
+ tmp = data;
goto unwind;
- FREE0(data);
+ }
g_free(path);
path = g_build_filename(m_user_dir, name, NULL);
- if ((data = get_data(NULL, path, "INFO", F_MATCH_MULTILINE)) != NULL)
+ if ((data = get_data(NULL, path, "INFO", F_MATCH_MULTILINE)) != NULL) {
+ tmp = data;
goto unwind;
- FREE0(data);
+ }
g_free(path);
path = g_strconcat(REPO_BASE REPO_TREE, "/", name, NULL);
@@ -1156,17 +1160,17 @@ cl_info(const char *name, int flags)
char *mainfile = (char *)exar_search_extract_from_data((unsigned char *)msg->response_body->data, "main.js", NULL);
if (mainfile != NULL) {
data = get_data(NULL, mainfile, "INFO", F_MATCH_MULTILINE | F_MATCH_CONTENT);
- g_free(mainfile);
+ exar_free(mainfile);
}
}
else {
data = get_data(NULL, msg->response_body->data, "INFO", F_MATCH_MULTILINE | F_MATCH_CONTENT);
}
+ tmp = data;
}
unwind:
- if (data != NULL)
+ if (tmp != NULL)
{
- tmp = data;
SKIP_SPACE(tmp);
printf("\033[1m%s\033[0m - %s", name, tmp);
}
@@ -1278,7 +1282,7 @@ exar_xextract(const char *archive, const char *path,
{
fprintf(stderr, "Error extracting %s from %s\n", path, archive);
}
- free(content);
+ exar_free(content);
}
}
void
diff --git a/exar/exar.c b/exar/exar.c
index 725d35dd..b1cfefb3 100644
--- a/exar/exar.c
+++ b/exar/exar.c
@@ -269,7 +269,7 @@ get_file_header_from_data(const unsigned char *data, int *offset, struct exar_he
return EE_ERROR;
}
*offset = SZ_VERSION + SZ_DFLAG + SZ_SIZE;
- while (*tmp != '\0')
+ while (*tmp && *tmp != '\0')
{
head->eh_name[i] = *tmp;
i++;
@@ -280,7 +280,10 @@ get_file_header_from_data(const unsigned char *data, int *offset, struct exar_he
return EE_ERROR;
}
}
- // terminating null byte
+ if (*tmp != '\0') {
+ LOG(1, "The archive seems to be corrupted\n");
+ return EE_ERROR;
+ }
*offset += i+1;
LOG(2, "Found file header (%s, %c, %jd)\n", head->eh_name, head->eh_flag, (intmax_t)head->eh_size);
diff --git a/exar/exar.h b/exar/exar.h
index f141b8ba..805c7f0e 100644
--- a/exar/exar.h
+++ b/exar/exar.h
@@ -46,6 +46,7 @@ enum {
EXAR_VERBOSE_L3 = 1<<2,
};
#define EXAR_VERBOSE_MASK (0x7)
+#define exar_free(x) ((x) = (x) == NULL ? NULL : (free(x), NULL))
/*
* Packs a file or directory
diff --git a/src/dwb.c b/src/dwb.c
index 5a320e40..81d5ddd5 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -3632,9 +3632,11 @@ dwb_get_scripts()
if (exar_check_version(path) == 0)
{
content = (char *) exar_search_extract(path, "main.js", NULL);
- if (content != NULL)
+ if (content != NULL) {
scripts_init_archive(path, content);
- goto loop_end;
+ exar_free(content);
+ }
+ continue;
}
else if ( (f = fopen(path, "r")) != NULL)
{
diff --git a/src/scripts.c b/src/scripts.c
index c1da4f0c..3d2a3377 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -2347,7 +2347,8 @@ global_include(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, c
{
JSValueRef ret = NIL;
gboolean global = false;
- char *path = NULL, *content = NULL;
+ char *path = NULL, *content = NULL, *econtent = NULL;
+ const char *script;
JSValueRef exports[1];
gboolean is_archive = false;
@@ -2362,34 +2363,38 @@ global_include(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, c
if (exar_check_version(path) == 0)
{
- content = (char*) exar_search_extract(path, "main.js", NULL);
- if (content == NULL)
+ econtent = (char*) exar_search_extract(path, "main.js", NULL);
+ if (econtent == NULL)
{
js_make_exception(ctx, exc, EXCEPTION("include: main.js was not found in %s."), path);
goto error_out;
}
exports[0] = get_exports(ctx, path);
is_archive = true;
+ script = econtent;
}
- else if ( (content = util_get_file_content(path, NULL)) == NULL)
+ else if ( (content = util_get_file_content(path, NULL)) != NULL)
{
+ script = content;
+ }
+ else {
js_make_exception(ctx, exc, EXCEPTION("include: reading %s failed."), path);
goto error_out;
}
- const char *tmp = content;
- if (*tmp == '#')
+ if (*script == '#')
{
do {
- tmp++;
- } while(*tmp && *tmp != '\n');
- tmp++;
+ script++;
+ } while(*script && *script != '\n');
+ script++;
}
- ret = do_include(ctx, path, tmp, global, is_archive, is_archive ? 1 : 0, is_archive ? exports : NULL, exc);
+ ret = do_include(ctx, path, script, global, is_archive, is_archive ? 1 : 0, is_archive ? exports : NULL, exc);
error_out:
g_free(content);
+ exar_free(econtent);
g_free(path);
return ret;
}/*}}}*/
@@ -2476,7 +2481,7 @@ global_xinclude(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t
error_out:
g_free(archive);
g_free(path);
- g_free(content);
+ exar_free(content);
return ret;
}