idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
14,700 | include(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
gchar *pe = NULL,
*path = NULL,
*line;
int i=0;
if(!argv_idx(argv, 0))
return;
pe = parseenv(argv_idx(argv, 0));
if((path = find_existing_file(pe))) {
GArray* lines = read_file_by_line(path);
while ((line = g_array_index(lines, gchar*, i))) {
parse_cmd_line (line, NULL);
i++;
g_free (line);
}
g_array_free (lines, TRUE);
send_event(FILE_INCLUDED, path, NULL);
g_free(path);
}
g_free(pe);
}
| Exec Code | 0 | include(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
gchar *pe = NULL,
*path = NULL,
*line;
int i=0;
if(!argv_idx(argv, 0))
return;
pe = parseenv(argv_idx(argv, 0));
if((path = find_existing_file(pe))) {
GArray* lines = read_file_by_line(path);
while ((line = g_array_index(lines, gchar*, i))) {
parse_cmd_line (line, NULL);
i++;
g_free (line);
}
g_array_free (lines, TRUE);
send_event(FILE_INCLUDED, path, NULL);
g_free(path);
}
g_free(pe);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,701 | init_connect_socket() {
int sockfd, replay = 0;
struct sockaddr_un local;
GIOChannel *chan;
gchar **name = NULL;
if(!uzbl.comm.connect_chan)
uzbl.comm.connect_chan = g_ptr_array_new();
name = uzbl.state.connect_socket_names;
while(name && *name) {
sockfd = socket (AF_UNIX, SOCK_STREAM, 0);
local.sun_family = AF_UNIX;
strcpy (local.sun_path, *name);
if(!connect(sockfd, (struct sockaddr *) &local, sizeof(local))) {
if ((chan = g_io_channel_unix_new(sockfd))) {
g_io_channel_set_encoding(chan, NULL, NULL);
g_io_add_watch(chan, G_IO_IN|G_IO_HUP,
(GIOFunc) control_client_socket, chan);
g_ptr_array_add(uzbl.comm.connect_chan, (gpointer)chan);
replay++;
}
}
else
g_warning("Error connecting to socket: %s\n", *name);
name++;
}
/* replay buffered events */
if(replay)
send_event_socket(NULL);
}
| Exec Code | 0 | init_connect_socket() {
int sockfd, replay = 0;
struct sockaddr_un local;
GIOChannel *chan;
gchar **name = NULL;
if(!uzbl.comm.connect_chan)
uzbl.comm.connect_chan = g_ptr_array_new();
name = uzbl.state.connect_socket_names;
while(name && *name) {
sockfd = socket (AF_UNIX, SOCK_STREAM, 0);
local.sun_family = AF_UNIX;
strcpy (local.sun_path, *name);
if(!connect(sockfd, (struct sockaddr *) &local, sizeof(local))) {
if ((chan = g_io_channel_unix_new(sockfd))) {
g_io_channel_set_encoding(chan, NULL, NULL);
g_io_add_watch(chan, G_IO_IN|G_IO_HUP,
(GIOFunc) control_client_socket, chan);
g_ptr_array_add(uzbl.comm.connect_chan, (gpointer)chan);
replay++;
}
}
else
g_warning("Error connecting to socket: %s\n", *name);
name++;
}
/* replay buffered events */
if(replay)
send_event_socket(NULL);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,702 | init_fifo(gchar *dir) { /* return dir or, on error, free dir and return NULL */
if (uzbl.comm.fifo_path) { /* get rid of the old fifo if one exists */
if (unlink(uzbl.comm.fifo_path) == -1)
g_warning ("Fifo: Can't unlink old fifo at %s\n", uzbl.comm.fifo_path);
g_free(uzbl.comm.fifo_path);
uzbl.comm.fifo_path = NULL;
}
GIOChannel *chan = NULL;
GError *error = NULL;
gchar *path = build_stream_name(FIFO, dir);
if (!file_exists(path)) {
if (mkfifo (path, 0666) == 0) {
chan = g_io_channel_new_file(path, "r+", &error);
if (chan) {
if (g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_fifo, NULL)) {
if (uzbl.state.verbose)
printf ("init_fifo: created successfully as %s\n", path);
send_event(FIFO_SET, path, NULL);
uzbl.comm.fifo_path = path;
return dir;
} else g_warning ("init_fifo: could not add watch on %s\n", path);
} else g_warning ("init_fifo: can't open: %s\n", error->message);
} else g_warning ("init_fifo: can't create %s: %s\n", path, strerror(errno));
} else g_warning ("init_fifo: can't create %s: file exists\n", path);
/* if we got this far, there was an error; cleanup */
if (error) g_error_free (error);
g_free(dir);
g_free(path);
return NULL;
}
| Exec Code | 0 | init_fifo(gchar *dir) { /* return dir or, on error, free dir and return NULL */
if (uzbl.comm.fifo_path) { /* get rid of the old fifo if one exists */
if (unlink(uzbl.comm.fifo_path) == -1)
g_warning ("Fifo: Can't unlink old fifo at %s\n", uzbl.comm.fifo_path);
g_free(uzbl.comm.fifo_path);
uzbl.comm.fifo_path = NULL;
}
GIOChannel *chan = NULL;
GError *error = NULL;
gchar *path = build_stream_name(FIFO, dir);
if (!file_exists(path)) {
if (mkfifo (path, 0666) == 0) {
chan = g_io_channel_new_file(path, "r+", &error);
if (chan) {
if (g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_fifo, NULL)) {
if (uzbl.state.verbose)
printf ("init_fifo: created successfully as %s\n", path);
send_event(FIFO_SET, path, NULL);
uzbl.comm.fifo_path = path;
return dir;
} else g_warning ("init_fifo: could not add watch on %s\n", path);
} else g_warning ("init_fifo: can't open: %s\n", error->message);
} else g_warning ("init_fifo: can't create %s: %s\n", path, strerror(errno));
} else g_warning ("init_fifo: can't create %s: file exists\n", path);
/* if we got this far, there was an error; cleanup */
if (error) g_error_free (error);
g_free(dir);
g_free(path);
return NULL;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,703 | init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL */
if (uzbl.comm.socket_path) { /* remove an existing socket should one exist */
if (unlink(uzbl.comm.socket_path) == -1)
g_warning ("init_socket: couldn't unlink socket at %s\n", uzbl.comm.socket_path);
g_free(uzbl.comm.socket_path);
uzbl.comm.socket_path = NULL;
}
if (*dir == ' ') {
g_free(dir);
return NULL;
}
GIOChannel *chan = NULL;
int sock, len;
struct sockaddr_un local;
gchar *path = build_stream_name(SOCKET, dir);
sock = socket (AF_UNIX, SOCK_STREAM, 0);
local.sun_family = AF_UNIX;
strcpy (local.sun_path, path);
unlink (local.sun_path);
len = strlen (local.sun_path) + sizeof (local.sun_family);
if (bind (sock, (struct sockaddr *) &local, len) != -1) {
if (uzbl.state.verbose)
printf ("init_socket: opened in %s\n", path);
listen (sock, 5);
if( (chan = g_io_channel_unix_new(sock)) ) {
g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_socket, chan);
uzbl.comm.socket_path = path;
send_event(SOCKET_SET, path, NULL);
return dir;
}
} else g_warning ("init_socket: could not open in %s: %s\n", path, strerror(errno));
/* if we got this far, there was an error; cleanup */
g_free(path);
g_free(dir);
return NULL;
}
| Exec Code | 0 | init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL */
if (uzbl.comm.socket_path) { /* remove an existing socket should one exist */
if (unlink(uzbl.comm.socket_path) == -1)
g_warning ("init_socket: couldn't unlink socket at %s\n", uzbl.comm.socket_path);
g_free(uzbl.comm.socket_path);
uzbl.comm.socket_path = NULL;
}
if (*dir == ' ') {
g_free(dir);
return NULL;
}
GIOChannel *chan = NULL;
int sock, len;
struct sockaddr_un local;
gchar *path = build_stream_name(SOCKET, dir);
sock = socket (AF_UNIX, SOCK_STREAM, 0);
local.sun_family = AF_UNIX;
strcpy (local.sun_path, path);
unlink (local.sun_path);
len = strlen (local.sun_path) + sizeof (local.sun_family);
if (bind (sock, (struct sockaddr *) &local, len) != -1) {
if (uzbl.state.verbose)
printf ("init_socket: opened in %s\n", path);
listen (sock, 5);
if( (chan = g_io_channel_unix_new(sock)) ) {
g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_socket, chan);
uzbl.comm.socket_path = path;
send_event(SOCKET_SET, path, NULL);
return dir;
}
} else g_warning ("init_socket: could not open in %s: %s\n", path, strerror(errno));
/* if we got this far, there was an error; cleanup */
g_free(path);
g_free(dir);
return NULL;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,704 | initialize(int argc, char *argv[]) {
int i;
for(i=0; i<argc; ++i) {
if(!strcmp(argv[i], "-s") || !strcmp(argv[i], "--socket")) {
uzbl.state.plug_mode = TRUE;
break;
}
}
if (!g_thread_supported ())
g_thread_init (NULL);
gtk_init (&argc, &argv);
uzbl.state.executable_path = g_strdup(argv[0]);
uzbl.state.selected_url = NULL;
uzbl.state.searchtx = NULL;
GOptionContext* context = g_option_context_new ("[ uri ] - load a uri by default");
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free(context);
if (uzbl.behave.print_version) {
printf("Commit: %s\n", COMMIT);
exit(EXIT_SUCCESS);
}
uzbl.net.soup_session = webkit_get_default_session();
uzbl.state.keycmd = g_strdup("");
for(i=0; sigs[i]; i++) {
if(setup_signal(sigs[i], catch_signal) == SIG_ERR)
fprintf(stderr, "uzbl: error hooking %d: %s\n", sigs[i], strerror(errno));
}
event_buffer_timeout(10);
uzbl.info.webkit_major = WEBKIT_MAJOR_VERSION;
uzbl.info.webkit_minor = WEBKIT_MINOR_VERSION;
uzbl.info.webkit_micro = WEBKIT_MICRO_VERSION;
uzbl.info.arch = ARCH;
uzbl.info.commit = COMMIT;
commands_hash ();
create_var_to_name_hash();
create_mainbar();
create_browser();
}
| Exec Code | 0 | initialize(int argc, char *argv[]) {
int i;
for(i=0; i<argc; ++i) {
if(!strcmp(argv[i], "-s") || !strcmp(argv[i], "--socket")) {
uzbl.state.plug_mode = TRUE;
break;
}
}
if (!g_thread_supported ())
g_thread_init (NULL);
gtk_init (&argc, &argv);
uzbl.state.executable_path = g_strdup(argv[0]);
uzbl.state.selected_url = NULL;
uzbl.state.searchtx = NULL;
GOptionContext* context = g_option_context_new ("[ uri ] - load a uri by default");
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free(context);
if (uzbl.behave.print_version) {
printf("Commit: %s\n", COMMIT);
exit(EXIT_SUCCESS);
}
uzbl.net.soup_session = webkit_get_default_session();
uzbl.state.keycmd = g_strdup("");
for(i=0; sigs[i]; i++) {
if(setup_signal(sigs[i], catch_signal) == SIG_ERR)
fprintf(stderr, "uzbl: error hooking %d: %s\n", sigs[i], strerror(errno));
}
event_buffer_timeout(10);
uzbl.info.webkit_major = WEBKIT_MAJOR_VERSION;
uzbl.info.webkit_minor = WEBKIT_MINOR_VERSION;
uzbl.info.webkit_micro = WEBKIT_MICRO_VERSION;
uzbl.info.arch = ARCH;
uzbl.info.commit = COMMIT;
commands_hash ();
create_var_to_name_hash();
create_mainbar();
create_browser();
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,705 | itos(int val) {
char tmp[20];
snprintf(tmp, sizeof(tmp), "%i", val);
return g_strdup(tmp);
}
| Exec Code | 0 | itos(int val) {
char tmp[20];
snprintf(tmp, sizeof(tmp), "%i", val);
return g_strdup(tmp);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,706 | js_init() {
/* This function creates the class and its definition, only once */
if (!uzbl.js.initialized) {
/* it would be pretty cool to make this dynamic */
uzbl.js.classdef = kJSClassDefinitionEmpty;
uzbl.js.classdef.staticFunctions = js_static_functions;
uzbl.js.classref = JSClassCreate(&uzbl.js.classdef);
}
}
| Exec Code | 0 | js_init() {
/* This function creates the class and its definition, only once */
if (!uzbl.js.initialized) {
/* it would be pretty cool to make this dynamic */
uzbl.js.classdef = kJSClassDefinitionEmpty;
uzbl.js.classdef.staticFunctions = js_static_functions;
uzbl.js.classref = JSClassCreate(&uzbl.js.classdef);
}
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,707 | js_run_command (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argumentCount, const JSValueRef arguments[],
JSValueRef* exception) {
(void) function;
(void) thisObject;
(void) exception;
JSStringRef js_result_string;
GString *result = g_string_new("");
if (argumentCount >= 1) {
JSStringRef arg = JSValueToStringCopy(ctx, arguments[0], NULL);
size_t arg_size = JSStringGetMaximumUTF8CStringSize(arg);
char ctl_line[arg_size];
JSStringGetUTF8CString(arg, ctl_line, arg_size);
parse_cmd_line(ctl_line, result);
JSStringRelease(arg);
}
js_result_string = JSStringCreateWithUTF8CString(result->str);
g_string_free(result, TRUE);
return JSValueMakeString(ctx, js_result_string);
}
| Exec Code | 0 | js_run_command (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argumentCount, const JSValueRef arguments[],
JSValueRef* exception) {
(void) function;
(void) thisObject;
(void) exception;
JSStringRef js_result_string;
GString *result = g_string_new("");
if (argumentCount >= 1) {
JSStringRef arg = JSValueToStringCopy(ctx, arguments[0], NULL);
size_t arg_size = JSStringGetMaximumUTF8CStringSize(arg);
char ctl_line[arg_size];
JSStringGetUTF8CString(arg, ctl_line, arg_size);
parse_cmd_line(ctl_line, result);
JSStringRelease(arg);
}
js_result_string = JSStringCreateWithUTF8CString(result->str);
g_string_free(result, TRUE);
return JSValueMakeString(ctx, js_result_string);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,708 | load_uri (WebKitWebView *web_view, GArray *argv, GString *result) {
(void) web_view; (void) result;
load_uri_imp (argv_idx (argv, 0));
}
| Exec Code | 0 | load_uri (WebKitWebView *web_view, GArray *argv, GString *result) {
(void) web_view; (void) result;
load_uri_imp (argv_idx (argv, 0));
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,709 | load_uri_imp(gchar *uri) {
GString* newuri;
if (g_strstr_len (uri, 11, "javascript:") != NULL) {
eval_js(uzbl.gui.web_view, uri, NULL);
return;
}
newuri = g_string_new (uri);
if (!soup_uri_new(uri)) {
GString* fullpath = g_string_new ("");
if (g_path_is_absolute (newuri->str))
g_string_assign (fullpath, newuri->str);
else {
gchar* wd;
wd = g_get_current_dir ();
g_string_assign (fullpath, g_build_filename (wd, newuri->str, NULL));
free(wd);
}
struct stat stat_result;
if (! g_stat(fullpath->str, &stat_result)) {
g_string_prepend (fullpath, "file://");
g_string_assign (newuri, fullpath->str);
}
else
g_string_prepend (newuri, "http://");
g_string_free (fullpath, TRUE);
}
/* if we do handle cookies, ask our handler for them */
webkit_web_view_load_uri (uzbl.gui.web_view, newuri->str);
g_string_free (newuri, TRUE);
}
| Exec Code | 0 | load_uri_imp(gchar *uri) {
GString* newuri;
if (g_strstr_len (uri, 11, "javascript:") != NULL) {
eval_js(uzbl.gui.web_view, uri, NULL);
return;
}
newuri = g_string_new (uri);
if (!soup_uri_new(uri)) {
GString* fullpath = g_string_new ("");
if (g_path_is_absolute (newuri->str))
g_string_assign (fullpath, newuri->str);
else {
gchar* wd;
wd = g_get_current_dir ();
g_string_assign (fullpath, g_build_filename (wd, newuri->str, NULL));
free(wd);
}
struct stat stat_result;
if (! g_stat(fullpath->str, &stat_result)) {
g_string_prepend (fullpath, "file://");
g_string_assign (newuri, fullpath->str);
}
else
g_string_prepend (newuri, "http://");
g_string_free (fullpath, TRUE);
}
/* if we do handle cookies, ask our handler for them */
webkit_web_view_load_uri (uzbl.gui.web_view, newuri->str);
g_string_free (newuri, TRUE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,710 | main (int argc, char* argv[]) {
initialize(argc, argv);
uzbl.gui.scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (uzbl.gui.scrolled_win),
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
gtk_container_add (GTK_CONTAINER (uzbl.gui.scrolled_win),
GTK_WIDGET (uzbl.gui.web_view));
uzbl.gui.vbox = gtk_vbox_new (FALSE, 0);
/* initial packing */
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.scrolled_win, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.mainbar, FALSE, TRUE, 0);
if (uzbl.state.plug_mode) {
uzbl.gui.plug = create_plug ();
gtk_container_add (GTK_CONTAINER (uzbl.gui.plug), uzbl.gui.vbox);
gtk_widget_show_all (GTK_WIDGET (uzbl.gui.plug));
/* in xembed mode the window has no unique id and thus
* socket/fifo names aren't unique either.
* we use a custom randomizer to create a random id
*/
struct timeval tv;
gettimeofday(&tv, NULL);
srand((unsigned int)tv.tv_sec*tv.tv_usec);
uzbl.xwin = rand();
} else {
uzbl.gui.main_window = create_window ();
gtk_container_add (GTK_CONTAINER (uzbl.gui.main_window), uzbl.gui.vbox);
gtk_widget_show_all (uzbl.gui.main_window);
uzbl.xwin = GDK_WINDOW_XID (GTK_WIDGET (uzbl.gui.main_window)->window);
}
uzbl.gui.scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL);
uzbl.gui.bar_v = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_v);
uzbl.gui.scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL);
uzbl.gui.bar_h = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_h);
gtk_widget_set_scroll_adjustments ((GtkWidget*) uzbl.gui.web_view, uzbl.gui.bar_h, uzbl.gui.bar_v);
if(!uzbl.state.instance_name)
uzbl.state.instance_name = itos((int)uzbl.xwin);
GString *tmp = g_string_new("");
g_string_printf(tmp, "%d", getpid());
uzbl.info.pid_str = g_string_free(tmp, FALSE);
send_event(INSTANCE_START, uzbl.info.pid_str, NULL);
if(uzbl.state.plug_mode) {
char *t = itos(gtk_plug_get_id(uzbl.gui.plug));
send_event(PLUG_CREATED, t, NULL);
g_free(t);
}
/* generate an event with a list of built in commands */
builtins();
gtk_widget_grab_focus (GTK_WIDGET (uzbl.gui.web_view));
if (uzbl.state.verbose) {
printf("Uzbl start location: %s\n", argv[0]);
if (uzbl.state.socket_id)
printf("plug_id %i\n", gtk_plug_get_id(uzbl.gui.plug));
else
printf("window_id %i\n",(int) uzbl.xwin);
printf("pid %i\n", getpid ());
printf("name: %s\n", uzbl.state.instance_name);
printf("commit: %s\n", uzbl.info.commit);
}
/* Check uzbl is in window mode before getting/setting geometry */
if (uzbl.gui.main_window) {
if(uzbl.gui.geometry)
cmd_set_geometry();
else
retrieve_geometry();
}
gchar *uri_override = (uzbl.state.uri ? g_strdup(uzbl.state.uri) : NULL);
if (argc > 1 && !uzbl.state.uri)
uri_override = g_strdup(argv[1]);
gboolean verbose_override = uzbl.state.verbose;
settings_init ();
if (!uzbl.behave.show_status)
gtk_widget_hide(uzbl.gui.mainbar);
else
update_title();
/* WebInspector */
set_up_inspector();
if (verbose_override > uzbl.state.verbose)
uzbl.state.verbose = verbose_override;
if (uri_override) {
set_var_value("uri", uri_override);
g_free(uri_override);
}
gtk_main ();
clean_up();
return EXIT_SUCCESS;
}
| Exec Code | 0 | main (int argc, char* argv[]) {
initialize(argc, argv);
uzbl.gui.scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (uzbl.gui.scrolled_win),
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
gtk_container_add (GTK_CONTAINER (uzbl.gui.scrolled_win),
GTK_WIDGET (uzbl.gui.web_view));
uzbl.gui.vbox = gtk_vbox_new (FALSE, 0);
/* initial packing */
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.scrolled_win, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.mainbar, FALSE, TRUE, 0);
if (uzbl.state.plug_mode) {
uzbl.gui.plug = create_plug ();
gtk_container_add (GTK_CONTAINER (uzbl.gui.plug), uzbl.gui.vbox);
gtk_widget_show_all (GTK_WIDGET (uzbl.gui.plug));
/* in xembed mode the window has no unique id and thus
* socket/fifo names aren't unique either.
* we use a custom randomizer to create a random id
*/
struct timeval tv;
gettimeofday(&tv, NULL);
srand((unsigned int)tv.tv_sec*tv.tv_usec);
uzbl.xwin = rand();
} else {
uzbl.gui.main_window = create_window ();
gtk_container_add (GTK_CONTAINER (uzbl.gui.main_window), uzbl.gui.vbox);
gtk_widget_show_all (uzbl.gui.main_window);
uzbl.xwin = GDK_WINDOW_XID (GTK_WIDGET (uzbl.gui.main_window)->window);
}
uzbl.gui.scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL);
uzbl.gui.bar_v = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_v);
uzbl.gui.scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL);
uzbl.gui.bar_h = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_h);
gtk_widget_set_scroll_adjustments ((GtkWidget*) uzbl.gui.web_view, uzbl.gui.bar_h, uzbl.gui.bar_v);
if(!uzbl.state.instance_name)
uzbl.state.instance_name = itos((int)uzbl.xwin);
GString *tmp = g_string_new("");
g_string_printf(tmp, "%d", getpid());
uzbl.info.pid_str = g_string_free(tmp, FALSE);
send_event(INSTANCE_START, uzbl.info.pid_str, NULL);
if(uzbl.state.plug_mode) {
char *t = itos(gtk_plug_get_id(uzbl.gui.plug));
send_event(PLUG_CREATED, t, NULL);
g_free(t);
}
/* generate an event with a list of built in commands */
builtins();
gtk_widget_grab_focus (GTK_WIDGET (uzbl.gui.web_view));
if (uzbl.state.verbose) {
printf("Uzbl start location: %s\n", argv[0]);
if (uzbl.state.socket_id)
printf("plug_id %i\n", gtk_plug_get_id(uzbl.gui.plug));
else
printf("window_id %i\n",(int) uzbl.xwin);
printf("pid %i\n", getpid ());
printf("name: %s\n", uzbl.state.instance_name);
printf("commit: %s\n", uzbl.info.commit);
}
/* Check uzbl is in window mode before getting/setting geometry */
if (uzbl.gui.main_window) {
if(uzbl.gui.geometry)
cmd_set_geometry();
else
retrieve_geometry();
}
gchar *uri_override = (uzbl.state.uri ? g_strdup(uzbl.state.uri) : NULL);
if (argc > 1 && !uzbl.state.uri)
uri_override = g_strdup(argv[1]);
gboolean verbose_override = uzbl.state.verbose;
settings_init ();
if (!uzbl.behave.show_status)
gtk_widget_hide(uzbl.gui.mainbar);
else
update_title();
/* WebInspector */
set_up_inspector();
if (verbose_override > uzbl.state.verbose)
uzbl.state.verbose = verbose_override;
if (uri_override) {
set_var_value("uri", uri_override);
g_free(uri_override);
}
gtk_main ();
clean_up();
return EXIT_SUCCESS;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,711 | menu_add(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT);
}
| Exec Code | 0 | menu_add(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,712 | menu_add_edit(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE);
}
| Exec Code | 0 | menu_add_edit(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,713 | menu_add_image(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE);
}
| Exec Code | 0 | menu_add_image(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,714 | menu_add_separator(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_separator_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT);
}
| Exec Code | 0 | menu_add_separator(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_separator_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,715 | menu_add_separator_edit(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_separator_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE);
}
| Exec Code | 0 | menu_add_separator_edit(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_separator_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,716 | menu_add_separator_image(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_separator_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE);
}
| Exec Code | 0 | menu_add_separator_image(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
add_separator_to_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,717 | menu_remove_edit(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
remove_from_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE);
}
| Exec Code | 0 | menu_remove_edit(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
remove_from_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,718 | menu_remove_image(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
remove_from_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE);
}
| Exec Code | 0 | menu_remove_image(WebKitWebView *page, GArray *argv, GString *result) {
(void) page;
(void) result;
remove_from_menu(argv, WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,719 | move_statusbar() {
if (!uzbl.gui.scrolled_win &&
!uzbl.gui.mainbar)
return;
g_object_ref(uzbl.gui.scrolled_win);
g_object_ref(uzbl.gui.mainbar);
gtk_container_remove(GTK_CONTAINER(uzbl.gui.vbox), uzbl.gui.scrolled_win);
gtk_container_remove(GTK_CONTAINER(uzbl.gui.vbox), uzbl.gui.mainbar);
if(uzbl.behave.status_top) {
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.mainbar, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.scrolled_win, TRUE, TRUE, 0);
}
else {
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.scrolled_win, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.mainbar, FALSE, TRUE, 0);
}
g_object_unref(uzbl.gui.scrolled_win);
g_object_unref(uzbl.gui.mainbar);
gtk_widget_grab_focus (GTK_WIDGET (uzbl.gui.web_view));
return;
}
| Exec Code | 0 | move_statusbar() {
if (!uzbl.gui.scrolled_win &&
!uzbl.gui.mainbar)
return;
g_object_ref(uzbl.gui.scrolled_win);
g_object_ref(uzbl.gui.mainbar);
gtk_container_remove(GTK_CONTAINER(uzbl.gui.vbox), uzbl.gui.scrolled_win);
gtk_container_remove(GTK_CONTAINER(uzbl.gui.vbox), uzbl.gui.mainbar);
if(uzbl.behave.status_top) {
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.mainbar, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.scrolled_win, TRUE, TRUE, 0);
}
else {
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.scrolled_win, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (uzbl.gui.vbox), uzbl.gui.mainbar, FALSE, TRUE, 0);
}
g_object_unref(uzbl.gui.scrolled_win);
g_object_unref(uzbl.gui.mainbar);
gtk_widget_grab_focus (GTK_WIDGET (uzbl.gui.web_view));
return;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,720 | new_window_load_uri (const gchar * uri) {
if (uzbl.behave.new_window) {
GString *s = g_string_new ("");
g_string_printf(s, "'%s'", uri);
run_handler(uzbl.behave.new_window, s->str);
send_event(NEW_WINDOW, s->str, NULL);
return;
}
GString* to_execute = g_string_new ("");
g_string_append_printf (to_execute, "%s --uri '%s'", uzbl.state.executable_path, uri);
int i;
for (i = 0; entries[i].long_name != NULL; i++) {
if ((entries[i].arg == G_OPTION_ARG_STRING) &&
!strcmp(entries[i].long_name,"uri") &&
!strcmp(entries[i].long_name,"name")) {
gchar** str = (gchar**)entries[i].arg_data;
if (*str!=NULL)
g_string_append_printf (to_execute, " --%s '%s'", entries[i].long_name, *str);
}
else if(entries[i].arg == G_OPTION_ARG_STRING_ARRAY) {
int j;
gchar **str = *((gchar ***)entries[i].arg_data);
for(j=0; str[j]; j++)
g_string_append_printf(to_execute, " --%s '%s'", entries[i].long_name, str[j]);
}
}
if (uzbl.state.verbose)
printf("\n%s\n", to_execute->str);
g_spawn_command_line_async (to_execute->str, NULL);
/* TODO: should we just report the uri as event detail? */
send_event(NEW_WINDOW, to_execute->str, NULL);
g_string_free (to_execute, TRUE);
}
| Exec Code | 0 | new_window_load_uri (const gchar * uri) {
if (uzbl.behave.new_window) {
GString *s = g_string_new ("");
g_string_printf(s, "'%s'", uri);
run_handler(uzbl.behave.new_window, s->str);
send_event(NEW_WINDOW, s->str, NULL);
return;
}
GString* to_execute = g_string_new ("");
g_string_append_printf (to_execute, "%s --uri '%s'", uzbl.state.executable_path, uri);
int i;
for (i = 0; entries[i].long_name != NULL; i++) {
if ((entries[i].arg == G_OPTION_ARG_STRING) &&
!strcmp(entries[i].long_name,"uri") &&
!strcmp(entries[i].long_name,"name")) {
gchar** str = (gchar**)entries[i].arg_data;
if (*str!=NULL)
g_string_append_printf (to_execute, " --%s '%s'", entries[i].long_name, *str);
}
else if(entries[i].arg == G_OPTION_ARG_STRING_ARRAY) {
int j;
gchar **str = *((gchar ***)entries[i].arg_data);
for(j=0; str[j]; j++)
g_string_append_printf(to_execute, " --%s '%s'", entries[i].long_name, str[j]);
}
}
if (uzbl.state.verbose)
printf("\n%s\n", to_execute->str);
g_spawn_command_line_async (to_execute->str, NULL);
/* TODO: should we just report the uri as event detail? */
send_event(NEW_WINDOW, to_execute->str, NULL);
g_string_free (to_execute, TRUE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,721 | parse_cmd_line(const char *ctl_line, GString *result) {
size_t len=0;
gchar *ctlstrip = NULL;
gchar *exp_line = NULL;
gchar *work_string = NULL;
work_string = g_strdup(ctl_line);
/* strip trailing newline */
len = strlen(ctl_line);
if (work_string[len - 1] == '\n')
ctlstrip = g_strndup(work_string, len - 1);
else
ctlstrip = g_strdup(work_string);
g_free(work_string);
if( strcmp(g_strchug(ctlstrip), "") &&
strcmp(exp_line = expand(ctlstrip, 0), "")
) {
/* ignore comments */
if((exp_line[0] == '#'))
;
/* parse a command */
else {
gchar **tokens = NULL;
tokens = g_strsplit(exp_line, " ", 2);
parse_command(tokens[0], tokens[1], result);
g_strfreev(tokens);
}
g_free(exp_line);
}
g_free(ctlstrip);
}
| Exec Code | 0 | parse_cmd_line(const char *ctl_line, GString *result) {
size_t len=0;
gchar *ctlstrip = NULL;
gchar *exp_line = NULL;
gchar *work_string = NULL;
work_string = g_strdup(ctl_line);
/* strip trailing newline */
len = strlen(ctl_line);
if (work_string[len - 1] == '\n')
ctlstrip = g_strndup(work_string, len - 1);
else
ctlstrip = g_strdup(work_string);
g_free(work_string);
if( strcmp(g_strchug(ctlstrip), "") &&
strcmp(exp_line = expand(ctlstrip, 0), "")
) {
/* ignore comments */
if((exp_line[0] == '#'))
;
/* parse a command */
else {
gchar **tokens = NULL;
tokens = g_strsplit(exp_line, " ", 2);
parse_command(tokens[0], tokens[1], result);
g_strfreev(tokens);
}
g_free(exp_line);
}
g_free(ctlstrip);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,722 | parse_command(const char *cmd, const char *param, GString *result) {
CommandInfo *c;
GString *tmp = g_string_new("");
if ((c = g_hash_table_lookup(uzbl.behave.commands, cmd))) {
guint i;
gchar **par = split_quoted(param, TRUE);
GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*));
if (c->no_split) { /* don't split */
sharg_append(a, param);
} else if (par) {
for (i = 0; i < g_strv_length(par); i++)
sharg_append(a, par[i]);
}
if (result == NULL) {
GString *result_print = g_string_new("");
c->function(uzbl.gui.web_view, a, result_print);
if (result_print->len)
printf("%*s\n", (int)result_print->len, result_print->str);
g_string_free(result_print, TRUE);
} else {
c->function(uzbl.gui.web_view, a, result);
}
g_strfreev (par);
g_array_free (a, TRUE);
if(strcmp("set", cmd) &&
strcmp("event", cmd) &&
strcmp("request", cmd)) {
g_string_printf(tmp, "%s %s", cmd, param?param:"");
send_event(COMMAND_EXECUTED, tmp->str, NULL);
g_string_free(tmp, TRUE);
}
}
else {
gchar *tmp = g_strdup_printf("%s %s", cmd, param?param:"");
send_event(COMMAND_ERROR, tmp, NULL);
g_free(tmp);
}
}
| Exec Code | 0 | parse_command(const char *cmd, const char *param, GString *result) {
CommandInfo *c;
GString *tmp = g_string_new("");
if ((c = g_hash_table_lookup(uzbl.behave.commands, cmd))) {
guint i;
gchar **par = split_quoted(param, TRUE);
GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*));
if (c->no_split) { /* don't split */
sharg_append(a, param);
} else if (par) {
for (i = 0; i < g_strv_length(par); i++)
sharg_append(a, par[i]);
}
if (result == NULL) {
GString *result_print = g_string_new("");
c->function(uzbl.gui.web_view, a, result_print);
if (result_print->len)
printf("%*s\n", (int)result_print->len, result_print->str);
g_string_free(result_print, TRUE);
} else {
c->function(uzbl.gui.web_view, a, result);
}
g_strfreev (par);
g_array_free (a, TRUE);
if(strcmp("set", cmd) &&
strcmp("event", cmd) &&
strcmp("request", cmd)) {
g_string_printf(tmp, "%s %s", cmd, param?param:"");
send_event(COMMAND_EXECUTED, tmp->str, NULL);
g_string_free(tmp, TRUE);
}
}
else {
gchar *tmp = g_strdup_printf("%s %s", cmd, param?param:"");
send_event(COMMAND_ERROR, tmp, NULL);
g_free(tmp);
}
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,723 | read_file_by_line (const gchar *path) {
GIOChannel *chan = NULL;
gchar *readbuf = NULL;
gsize len;
GArray *lines = g_array_new(TRUE, FALSE, sizeof(gchar*));
int i = 0;
chan = g_io_channel_new_file(path, "r", NULL);
if (chan) {
while (g_io_channel_read_line(chan, &readbuf, &len, NULL, NULL) == G_IO_STATUS_NORMAL) {
const gchar* val = g_strdup (readbuf);
g_array_append_val (lines, val);
g_free (readbuf);
i ++;
}
g_io_channel_unref (chan);
} else {
gchar *tmp = g_strdup_printf("File %s can not be read.", path);
send_event(COMMAND_ERROR, tmp, NULL);
g_free(tmp);
}
return lines;
}
| Exec Code | 0 | read_file_by_line (const gchar *path) {
GIOChannel *chan = NULL;
gchar *readbuf = NULL;
gsize len;
GArray *lines = g_array_new(TRUE, FALSE, sizeof(gchar*));
int i = 0;
chan = g_io_channel_new_file(path, "r", NULL);
if (chan) {
while (g_io_channel_read_line(chan, &readbuf, &len, NULL, NULL) == G_IO_STATUS_NORMAL) {
const gchar* val = g_strdup (readbuf);
g_array_append_val (lines, val);
g_free (readbuf);
i ++;
}
g_io_channel_unref (chan);
} else {
gchar *tmp = g_strdup_printf("File %s can not be read.", path);
send_event(COMMAND_ERROR, tmp, NULL);
g_free(tmp);
}
return lines;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,724 | remove_socket_from_array(GIOChannel *chan) {
gboolean ret = 0;
/* TODO: Do wee need to manually free the IO channel or is this
* happening implicitly on unref?
*/
ret = g_ptr_array_remove_fast(uzbl.comm.connect_chan, chan);
if(!ret)
ret = g_ptr_array_remove_fast(uzbl.comm.client_chan, chan);
return ret;
}
| Exec Code | 0 | remove_socket_from_array(GIOChannel *chan) {
gboolean ret = 0;
/* TODO: Do wee need to manually free the IO channel or is this
* happening implicitly on unref?
*/
ret = g_ptr_array_remove_fast(uzbl.comm.connect_chan, chan);
if(!ret)
ret = g_ptr_array_remove_fast(uzbl.comm.client_chan, chan);
return ret;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,725 | run_external_js (WebKitWebView * web_view, GArray *argv, GString *result) {
(void) result;
gchar *path = NULL;
if (argv_idx(argv, 0) &&
((path = find_existing_file(argv_idx(argv, 0)))) ) {
GArray* lines = read_file_by_line (path);
gchar* js = NULL;
int i = 0;
gchar* line;
while ((line = g_array_index(lines, gchar*, i))) {
if (js == NULL) {
js = g_strdup (line);
} else {
gchar* newjs = g_strconcat (js, line, NULL);
js = newjs;
}
i ++;
g_free (line);
}
if (uzbl.state.verbose)
printf ("External JavaScript file %s loaded\n", argv_idx(argv, 0));
gchar* newjs = str_replace("%s", argv_idx (argv, 1)?argv_idx (argv, 1):"", js);
g_free (js);
js = newjs;
eval_js (web_view, js, result);
g_free (js);
g_array_free (lines, TRUE);
g_free(path);
}
}
| Exec Code | 0 | run_external_js (WebKitWebView * web_view, GArray *argv, GString *result) {
(void) result;
gchar *path = NULL;
if (argv_idx(argv, 0) &&
((path = find_existing_file(argv_idx(argv, 0)))) ) {
GArray* lines = read_file_by_line (path);
gchar* js = NULL;
int i = 0;
gchar* line;
while ((line = g_array_index(lines, gchar*, i))) {
if (js == NULL) {
js = g_strdup (line);
} else {
gchar* newjs = g_strconcat (js, line, NULL);
js = newjs;
}
i ++;
g_free (line);
}
if (uzbl.state.verbose)
printf ("External JavaScript file %s loaded\n", argv_idx(argv, 0));
gchar* newjs = str_replace("%s", argv_idx (argv, 1)?argv_idx (argv, 1):"", js);
g_free (js);
js = newjs;
eval_js (web_view, js, result);
g_free (js);
g_array_free (lines, TRUE);
g_free(path);
}
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,726 | run_handler (const gchar *act, const gchar *args) {
/* Consider this code a temporary hack to make the handlers usable.
In practice, all this splicing, injection, and reconstruction is
inefficient, annoying and hard to manage. Potential pitfalls arise
when the handler specific args 1) are not quoted (the handler
callbacks should take care of this) 2) are quoted but interfere
with the users' own quotation. A more ideal solution is
to refactor parse_command so that it doesn't just take a string
and execute it; rather than that, we should have a function which
returns the argument vector parsed from the string. This vector
could be modified (e.g. insert additional args into it) before
passing it to the next function that actually executes it. Though
it still isn't perfect for chain actions.. will reconsider & re-
factor when I have the time. -duc */
if (!act) return;
char **parts = g_strsplit(act, " ", 2);
if (!parts || !parts[0]) return;
if (g_strcmp0(parts[0], "chain") == 0) {
GString *newargs = g_string_new("");
gchar **chainparts = split_quoted(parts[1], FALSE);
/* for every argument in the chain, inject the handler args
and make sure the new parts are wrapped in quotes */
gchar **cp = chainparts;
gchar quot = '\'';
gchar *quotless = NULL;
gchar **spliced_quotless = NULL; // sigh -_-;
gchar **inpart = NULL;
while (*cp) {
if ((**cp == '\'') || (**cp == '\"')) { /* strip old quotes */
quot = **cp;
quotless = g_strndup(&(*cp)[1], strlen(*cp) - 2);
} else quotless = g_strdup(*cp);
spliced_quotless = g_strsplit(quotless, " ", 2);
inpart = inject_handler_args(spliced_quotless[0], spliced_quotless[1], args);
g_strfreev(spliced_quotless);
g_string_append_printf(newargs, " %c%s %s%c", quot, inpart[0], inpart[1], quot);
g_free(quotless);
g_strfreev(inpart);
cp++;
}
parse_command(parts[0], &(newargs->str[1]), NULL);
g_string_free(newargs, TRUE);
g_strfreev(chainparts);
} else {
gchar **inparts;
gchar *inparts_[2];
if (parts[1]) {
/* expand the user-specified arguments */
gchar* expanded = expand(parts[1], 0);
inparts = inject_handler_args(parts[0], expanded, args);
g_free(expanded);
} else {
inparts_[0] = parts[0];
inparts_[1] = g_strdup(args);
inparts = inparts_;
}
parse_command(inparts[0], inparts[1], NULL);
if (inparts != inparts_) {
g_free(inparts[0]);
g_free(inparts[1]);
} else
g_free(inparts[1]);
}
g_strfreev(parts);
}
| Exec Code | 0 | run_handler (const gchar *act, const gchar *args) {
/* Consider this code a temporary hack to make the handlers usable.
In practice, all this splicing, injection, and reconstruction is
inefficient, annoying and hard to manage. Potential pitfalls arise
when the handler specific args 1) are not quoted (the handler
callbacks should take care of this) 2) are quoted but interfere
with the users' own quotation. A more ideal solution is
to refactor parse_command so that it doesn't just take a string
and execute it; rather than that, we should have a function which
returns the argument vector parsed from the string. This vector
could be modified (e.g. insert additional args into it) before
passing it to the next function that actually executes it. Though
it still isn't perfect for chain actions.. will reconsider & re-
factor when I have the time. -duc */
if (!act) return;
char **parts = g_strsplit(act, " ", 2);
if (!parts || !parts[0]) return;
if (g_strcmp0(parts[0], "chain") == 0) {
GString *newargs = g_string_new("");
gchar **chainparts = split_quoted(parts[1], FALSE);
/* for every argument in the chain, inject the handler args
and make sure the new parts are wrapped in quotes */
gchar **cp = chainparts;
gchar quot = '\'';
gchar *quotless = NULL;
gchar **spliced_quotless = NULL; // sigh -_-;
gchar **inpart = NULL;
while (*cp) {
if ((**cp == '\'') || (**cp == '\"')) { /* strip old quotes */
quot = **cp;
quotless = g_strndup(&(*cp)[1], strlen(*cp) - 2);
} else quotless = g_strdup(*cp);
spliced_quotless = g_strsplit(quotless, " ", 2);
inpart = inject_handler_args(spliced_quotless[0], spliced_quotless[1], args);
g_strfreev(spliced_quotless);
g_string_append_printf(newargs, " %c%s %s%c", quot, inpart[0], inpart[1], quot);
g_free(quotless);
g_strfreev(inpart);
cp++;
}
parse_command(parts[0], &(newargs->str[1]), NULL);
g_string_free(newargs, TRUE);
g_strfreev(chainparts);
} else {
gchar **inparts;
gchar *inparts_[2];
if (parts[1]) {
/* expand the user-specified arguments */
gchar* expanded = expand(parts[1], 0);
inparts = inject_handler_args(parts[0], expanded, args);
g_free(expanded);
} else {
inparts_[0] = parts[0];
inparts_[1] = g_strdup(args);
inparts = inparts_;
}
parse_command(inparts[0], inparts[1], NULL);
if (inparts != inparts_) {
g_free(inparts[0]);
g_free(inparts[1]);
} else
g_free(inparts[1]);
}
g_strfreev(parts);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,727 | run_js (WebKitWebView * web_view, GArray *argv, GString *result) {
if (argv_idx(argv, 0))
eval_js(web_view, argv_idx(argv, 0), result);
}
| Exec Code | 0 | run_js (WebKitWebView * web_view, GArray *argv, GString *result) {
if (argv_idx(argv, 0))
eval_js(web_view, argv_idx(argv, 0), result);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,728 | save_cookies (SoupMessage *msg, gpointer user_data){
(void) user_data;
GSList *ck;
char *cookie;
for (ck = soup_cookies_from_response(msg); ck; ck = ck->next){
cookie = soup_cookie_to_set_cookie_header(ck->data);
SoupURI * soup_uri = soup_message_get_uri(msg);
GString *s = g_string_new ("");
g_string_printf(s, "PUT '%s' '%s' '%s' '%s'", soup_uri->scheme, soup_uri->host, soup_uri->path, cookie);
run_handler(uzbl.behave.cookie_handler, s->str);
g_free (cookie);
g_string_free(s, TRUE);
}
g_slist_free(ck);
}
| Exec Code | 0 | save_cookies (SoupMessage *msg, gpointer user_data){
(void) user_data;
GSList *ck;
char *cookie;
for (ck = soup_cookies_from_response(msg); ck; ck = ck->next){
cookie = soup_cookie_to_set_cookie_header(ck->data);
SoupURI * soup_uri = soup_message_get_uri(msg);
GString *s = g_string_new ("");
g_string_printf(s, "PUT '%s' '%s' '%s' '%s'", soup_uri->scheme, soup_uri->host, soup_uri->path, cookie);
run_handler(uzbl.behave.cookie_handler, s->str);
g_free (cookie);
g_string_free(s, TRUE);
}
g_slist_free(ck);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,729 | search_clear(WebKitWebView *page, GArray *argv, GString *result) {
(void) argv;
(void) result;
webkit_web_view_unmark_text_matches (page);
if(uzbl.state.searchtx) {
g_free(uzbl.state.searchtx);
uzbl.state.searchtx = NULL;
}
}
| Exec Code | 0 | search_clear(WebKitWebView *page, GArray *argv, GString *result) {
(void) argv;
(void) result;
webkit_web_view_unmark_text_matches (page);
if(uzbl.state.searchtx) {
g_free(uzbl.state.searchtx);
uzbl.state.searchtx = NULL;
}
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,730 | search_reverse_text (WebKitWebView *page, GArray *argv, GString *result) {
(void) result;
search_text(page, argv, FALSE);
}
| Exec Code | 0 | search_reverse_text (WebKitWebView *page, GArray *argv, GString *result) {
(void) result;
search_text(page, argv, FALSE);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,731 | search_text (WebKitWebView *page, GArray *argv, const gboolean forward) {
if (argv_idx(argv, 0) && (*argv_idx(argv, 0) != '\0')) {
if (g_strcmp0 (uzbl.state.searchtx, argv_idx(argv, 0)) != 0) {
webkit_web_view_unmark_text_matches (page);
webkit_web_view_mark_text_matches (page, argv_idx(argv, 0), FALSE, 0);
uzbl.state.searchtx = g_strdup(argv_idx(argv, 0));
}
}
if (uzbl.state.searchtx) {
if (uzbl.state.verbose)
printf ("Searching: %s\n", uzbl.state.searchtx);
webkit_web_view_set_highlight_text_matches (page, TRUE);
webkit_web_view_search_text (page, uzbl.state.searchtx, FALSE, forward, TRUE);
}
}
| Exec Code | 0 | search_text (WebKitWebView *page, GArray *argv, const gboolean forward) {
if (argv_idx(argv, 0) && (*argv_idx(argv, 0) != '\0')) {
if (g_strcmp0 (uzbl.state.searchtx, argv_idx(argv, 0)) != 0) {
webkit_web_view_unmark_text_matches (page);
webkit_web_view_mark_text_matches (page, argv_idx(argv, 0), FALSE, 0);
uzbl.state.searchtx = g_strdup(argv_idx(argv, 0));
}
}
if (uzbl.state.searchtx) {
if (uzbl.state.verbose)
printf ("Searching: %s\n", uzbl.state.searchtx);
webkit_web_view_set_highlight_text_matches (page, TRUE);
webkit_web_view_search_text (page, uzbl.state.searchtx, FALSE, forward, TRUE);
}
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,732 | set_var(WebKitWebView *page, GArray *argv, GString *result) {
(void) page; (void) result;
if(!argv_idx(argv, 0))
return;
gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2);
if (split[0] != NULL) {
gchar *value = parseenv(split[1] ? g_strchug(split[1]) : " ");
set_var_value(g_strstrip(split[0]), value);
g_free(value);
}
g_strfreev(split);
}
| Exec Code | 0 | set_var(WebKitWebView *page, GArray *argv, GString *result) {
(void) page; (void) result;
if(!argv_idx(argv, 0))
return;
gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2);
if (split[0] != NULL) {
gchar *value = parseenv(split[1] ? g_strchug(split[1]) : " ");
set_var_value(g_strstrip(split[0]), value);
g_free(value);
}
g_strfreev(split);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,733 | set_var_value(const gchar *name, gchar *val) {
uzbl_cmdprop *c = NULL;
char *endp = NULL;
char *buf = NULL;
char *invalid_chars = "^°!\"§$%&/()=?'`'+~*'#-.:,;@<>| \\{}[]¹²³¼½";
GString *msg;
if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) {
if(!c->writeable) return FALSE;
msg = g_string_new(name);
/* check for the variable type */
if (c->type == TYPE_STR) {
buf = g_strdup(val);
g_free(*c->ptr.s);
*c->ptr.s = buf;
g_string_append_printf(msg, " str %s", buf);
} else if(c->type == TYPE_INT) {
*c->ptr.i = (int)strtoul(val, &endp, 10);
g_string_append_printf(msg, " int %d", *c->ptr.i);
} else if (c->type == TYPE_FLOAT) {
*c->ptr.f = strtod(val, &endp);
g_string_append_printf(msg, " float %f", *c->ptr.f);
}
send_event(VARIABLE_SET, msg->str, NULL);
g_string_free(msg,TRUE);
/* invoke a command specific function */
if(c->func) c->func();
} else {
/* check wether name violates our naming scheme */
if(strpbrk(name, invalid_chars)) {
if (uzbl.state.verbose)
printf("Invalid variable name\n");
return FALSE;
}
/* custom vars */
c = g_malloc(sizeof(uzbl_cmdprop));
c->type = TYPE_STR;
c->dump = 0;
c->func = NULL;
c->writeable = 1;
buf = g_strdup(val);
c->ptr.s = g_malloc(sizeof(char *));
*c->ptr.s = buf;
g_hash_table_insert(uzbl.comm.proto_var,
g_strdup(name), (gpointer) c);
msg = g_string_new(name);
g_string_append_printf(msg, " str %s", buf);
send_event(VARIABLE_SET, msg->str, NULL);
g_string_free(msg,TRUE);
}
update_title();
return TRUE;
}
| Exec Code | 0 | set_var_value(const gchar *name, gchar *val) {
uzbl_cmdprop *c = NULL;
char *endp = NULL;
char *buf = NULL;
char *invalid_chars = "^°!\"§$%&/()=?'`'+~*'#-.:,;@<>| \\{}[]¹²³¼½";
GString *msg;
if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) {
if(!c->writeable) return FALSE;
msg = g_string_new(name);
/* check for the variable type */
if (c->type == TYPE_STR) {
buf = g_strdup(val);
g_free(*c->ptr.s);
*c->ptr.s = buf;
g_string_append_printf(msg, " str %s", buf);
} else if(c->type == TYPE_INT) {
*c->ptr.i = (int)strtoul(val, &endp, 10);
g_string_append_printf(msg, " int %d", *c->ptr.i);
} else if (c->type == TYPE_FLOAT) {
*c->ptr.f = strtod(val, &endp);
g_string_append_printf(msg, " float %f", *c->ptr.f);
}
send_event(VARIABLE_SET, msg->str, NULL);
g_string_free(msg,TRUE);
/* invoke a command specific function */
if(c->func) c->func();
} else {
/* check wether name violates our naming scheme */
if(strpbrk(name, invalid_chars)) {
if (uzbl.state.verbose)
printf("Invalid variable name\n");
return FALSE;
}
/* custom vars */
c = g_malloc(sizeof(uzbl_cmdprop));
c->type = TYPE_STR;
c->dump = 0;
c->func = NULL;
c->writeable = 1;
buf = g_strdup(val);
c->ptr.s = g_malloc(sizeof(char *));
*c->ptr.s = buf;
g_hash_table_insert(uzbl.comm.proto_var,
g_strdup(name), (gpointer) c);
msg = g_string_new(name);
g_string_append_printf(msg, " str %s", buf);
send_event(VARIABLE_SET, msg->str, NULL);
g_string_free(msg,TRUE);
}
update_title();
return TRUE;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,734 | setup_signal(int signr, sigfunc *shandler) {
struct sigaction nh, oh;
nh.sa_handler = shandler;
sigemptyset(&nh.sa_mask);
nh.sa_flags = 0;
if(sigaction(signr, &nh, &oh) < 0)
return SIG_ERR;
return NULL;
}
| Exec Code | 0 | setup_signal(int signr, sigfunc *shandler) {
struct sigaction nh, oh;
nh.sa_handler = shandler;
sigemptyset(&nh.sa_mask);
nh.sa_flags = 0;
if(sigaction(signr, &nh, &oh) < 0)
return SIG_ERR;
return NULL;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,735 | sharg_append(GArray *a, const gchar *str) {
const gchar *s = (str ? str : "");
g_array_append_val(a, s);
}
| Exec Code | 0 | sharg_append(GArray *a, const gchar *str) {
const gchar *s = (str ? str : "");
g_array_append_val(a, s);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,736 | spawn(WebKitWebView *web_view, GArray *argv, GString *result) {
(void)web_view; (void)result;
gchar *path = NULL;
if (argv_idx(argv, 0) &&
((path = find_existing_file(argv_idx(argv, 0)))) ) {
run_command(path, 0,
((const gchar **) (argv->data + sizeof(gchar*))),
FALSE, NULL);
g_free(path);
}
}
| Exec Code | 0 | spawn(WebKitWebView *web_view, GArray *argv, GString *result) {
(void)web_view; (void)result;
gchar *path = NULL;
if (argv_idx(argv, 0) &&
((path = find_existing_file(argv_idx(argv, 0)))) ) {
run_command(path, 0,
((const gchar **) (argv->data + sizeof(gchar*))),
FALSE, NULL);
g_free(path);
}
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,737 | spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result) {
(void)web_view; (void)result;
if (!uzbl.behave.shell_cmd) {
g_printerr ("spawn_sh: shell_cmd is not set!\n");
return;
}
guint i;
gchar *spacer = g_strdup("");
g_array_insert_val(argv, 1, spacer);
gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE);
for (i = 1; i < g_strv_length(cmd); i++)
g_array_prepend_val(argv, cmd[i]);
if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, FALSE, NULL);
g_free (spacer);
g_strfreev (cmd);
}
| Exec Code | 0 | spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result) {
(void)web_view; (void)result;
if (!uzbl.behave.shell_cmd) {
g_printerr ("spawn_sh: shell_cmd is not set!\n");
return;
}
guint i;
gchar *spacer = g_strdup("");
g_array_insert_val(argv, 1, spacer);
gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE);
for (i = 1; i < g_strv_length(cmd); i++)
g_array_prepend_val(argv, cmd[i]);
if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, FALSE, NULL);
g_free (spacer);
g_strfreev (cmd);
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,738 | spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) {
(void)web_view; (void)result;
gchar *path = NULL;
if (argv_idx(argv, 0) &&
((path = find_existing_file(argv_idx(argv, 0)))) ) {
run_command(path, 0,
((const gchar **) (argv->data + sizeof(gchar*))),
TRUE, &uzbl.comm.sync_stdout);
g_free(path);
}
}
| Exec Code | 0 | spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) {
(void)web_view; (void)result;
gchar *path = NULL;
if (argv_idx(argv, 0) &&
((path = find_existing_file(argv_idx(argv, 0)))) ) {
run_command(path, 0,
((const gchar **) (argv->data + sizeof(gchar*))),
TRUE, &uzbl.comm.sync_stdout);
g_free(path);
}
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,739 | str_replace (const char* search, const char* replace, const char* string) {
gchar **buf;
char *ret;
if(!string)
return NULL;
buf = g_strsplit (string, search, -1);
ret = g_strjoinv (replace, buf);
g_strfreev(buf);
return ret;
}
| Exec Code | 0 | str_replace (const char* search, const char* replace, const char* string) {
gchar **buf;
char *ret;
if(!string)
return NULL;
buf = g_strsplit (string, search, -1);
ret = g_strjoinv (replace, buf);
g_strfreev(buf);
return ret;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,740 | strfree(gchar *str) {
g_free(str);
return NULL;
}
| Exec Code | 0 | strfree(gchar *str) {
g_free(str);
return NULL;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,741 | talk_to_socket(WebKitWebView *web_view, GArray *argv, GString *result) {
(void)web_view; (void)result;
int fd, len;
struct sockaddr_un sa;
char* sockpath;
ssize_t ret;
struct pollfd pfd;
struct iovec* iov;
guint i;
if(uzbl.comm.sync_stdout) uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout);
/* This function could be optimised by storing a hash table of socket paths
and associated connected file descriptors rather than closing and
re-opening for every call. Also we could launch a script if socket connect
fails. */
/* First element argv[0] is path to socket. Following elements are tokens to
write to the socket. We write them as a single packet with each token
separated by an ASCII nul (\0). */
if(argv->len < 2) {
g_printerr("talk_to_socket called with only %d args (need at least two).\n",
(int)argv->len);
return;
}
/* copy socket path, null terminate result */
sockpath = g_array_index(argv, char*, 0);
g_strlcpy(sa.sun_path, sockpath, sizeof(sa.sun_path));
sa.sun_family = AF_UNIX;
/* create socket file descriptor and connect it to path */
fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
if(fd == -1) {
g_printerr("talk_to_socket: creating socket failed (%s)\n", strerror(errno));
return;
}
if(connect(fd, (struct sockaddr*)&sa, sizeof(sa))) {
g_printerr("talk_to_socket: connect failed (%s)\n", strerror(errno));
close(fd);
return;
}
/* build request vector */
iov = g_malloc(sizeof(struct iovec) * (argv->len - 1));
if(!iov) {
g_printerr("talk_to_socket: unable to allocated memory for token vector\n");
close(fd);
return;
}
for(i = 1; i < argv->len; ++i) {
iov[i - 1].iov_base = g_array_index(argv, char*, i);
iov[i - 1].iov_len = strlen(iov[i - 1].iov_base) + 1; /* string plus \0 */
}
/* write request */
ret = writev(fd, iov, argv->len - 1);
g_free(iov);
if(ret == -1) {
g_printerr("talk_to_socket: write failed (%s)\n", strerror(errno));
close(fd);
return;
}
/* wait for a response, with a 500ms timeout */
pfd.fd = fd;
pfd.events = POLLIN;
while(1) {
ret = poll(&pfd, 1, 500);
if(ret == 1) break;
if(ret == 0) errno = ETIMEDOUT;
if(errno == EINTR) continue;
g_printerr("talk_to_socket: poll failed while waiting for input (%s)\n",
strerror(errno));
close(fd);
return;
}
/* get length of response */
if(ioctl(fd, FIONREAD, &len) == -1) {
g_printerr("talk_to_socket: cannot find daemon response length, "
"ioctl failed (%s)\n", strerror(errno));
close(fd);
return;
}
/* if there is a response, read it */
if(len) {
uzbl.comm.sync_stdout = g_malloc(len + 1);
if(!uzbl.comm.sync_stdout) {
g_printerr("talk_to_socket: failed to allocate %d bytes\n", len);
close(fd);
return;
}
uzbl.comm.sync_stdout[len] = 0; /* ensure result is null terminated */
ret = read(fd, uzbl.comm.sync_stdout, len);
if(ret == -1) {
g_printerr("talk_to_socket: failed to read from socket (%s)\n",
strerror(errno));
close(fd);
return;
}
}
/* clean up */
close(fd);
return;
}
| Exec Code | 0 | talk_to_socket(WebKitWebView *web_view, GArray *argv, GString *result) {
(void)web_view; (void)result;
int fd, len;
struct sockaddr_un sa;
char* sockpath;
ssize_t ret;
struct pollfd pfd;
struct iovec* iov;
guint i;
if(uzbl.comm.sync_stdout) uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout);
/* This function could be optimised by storing a hash table of socket paths
and associated connected file descriptors rather than closing and
re-opening for every call. Also we could launch a script if socket connect
fails. */
/* First element argv[0] is path to socket. Following elements are tokens to
write to the socket. We write them as a single packet with each token
separated by an ASCII nul (\0). */
if(argv->len < 2) {
g_printerr("talk_to_socket called with only %d args (need at least two).\n",
(int)argv->len);
return;
}
/* copy socket path, null terminate result */
sockpath = g_array_index(argv, char*, 0);
g_strlcpy(sa.sun_path, sockpath, sizeof(sa.sun_path));
sa.sun_family = AF_UNIX;
/* create socket file descriptor and connect it to path */
fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
if(fd == -1) {
g_printerr("talk_to_socket: creating socket failed (%s)\n", strerror(errno));
return;
}
if(connect(fd, (struct sockaddr*)&sa, sizeof(sa))) {
g_printerr("talk_to_socket: connect failed (%s)\n", strerror(errno));
close(fd);
return;
}
/* build request vector */
iov = g_malloc(sizeof(struct iovec) * (argv->len - 1));
if(!iov) {
g_printerr("talk_to_socket: unable to allocated memory for token vector\n");
close(fd);
return;
}
for(i = 1; i < argv->len; ++i) {
iov[i - 1].iov_base = g_array_index(argv, char*, i);
iov[i - 1].iov_len = strlen(iov[i - 1].iov_base) + 1; /* string plus \0 */
}
/* write request */
ret = writev(fd, iov, argv->len - 1);
g_free(iov);
if(ret == -1) {
g_printerr("talk_to_socket: write failed (%s)\n", strerror(errno));
close(fd);
return;
}
/* wait for a response, with a 500ms timeout */
pfd.fd = fd;
pfd.events = POLLIN;
while(1) {
ret = poll(&pfd, 1, 500);
if(ret == 1) break;
if(ret == 0) errno = ETIMEDOUT;
if(errno == EINTR) continue;
g_printerr("talk_to_socket: poll failed while waiting for input (%s)\n",
strerror(errno));
close(fd);
return;
}
/* get length of response */
if(ioctl(fd, FIONREAD, &len) == -1) {
g_printerr("talk_to_socket: cannot find daemon response length, "
"ioctl failed (%s)\n", strerror(errno));
close(fd);
return;
}
/* if there is a response, read it */
if(len) {
uzbl.comm.sync_stdout = g_malloc(len + 1);
if(!uzbl.comm.sync_stdout) {
g_printerr("talk_to_socket: failed to allocate %d bytes\n", len);
close(fd);
return;
}
uzbl.comm.sync_stdout[len] = 0; /* ensure result is null terminated */
ret = read(fd, uzbl.comm.sync_stdout, len);
if(ret == -1) {
g_printerr("talk_to_socket: failed to read from socket (%s)\n",
strerror(errno));
close(fd);
return;
}
}
/* clean up */
close(fd);
return;
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,742 | update_title (void) {
Behaviour *b = &uzbl.behave;
gchar *parsed;
if (b->show_status) {
if (b->title_format_short) {
parsed = expand(b->title_format_short, 0);
if (uzbl.gui.main_window)
gtk_window_set_title (GTK_WINDOW(uzbl.gui.main_window), parsed);
g_free(parsed);
}
if (b->status_format) {
parsed = expand(b->status_format, 0);
gtk_label_set_markup(GTK_LABEL(uzbl.gui.mainbar_label), parsed);
g_free(parsed);
}
if (b->status_background) {
GdkColor color;
gdk_color_parse (b->status_background, &color);
if (uzbl.gui.main_window)
gtk_widget_modify_bg (uzbl.gui.main_window, GTK_STATE_NORMAL, &color);
else if (uzbl.gui.plug)
gtk_widget_modify_bg (GTK_WIDGET(uzbl.gui.plug), GTK_STATE_NORMAL, &color);
}
} else {
if (b->title_format_long) {
parsed = expand(b->title_format_long, 0);
if (uzbl.gui.main_window)
gtk_window_set_title (GTK_WINDOW(uzbl.gui.main_window), parsed);
g_free(parsed);
}
}
}
| Exec Code | 0 | update_title (void) {
Behaviour *b = &uzbl.behave;
gchar *parsed;
if (b->show_status) {
if (b->title_format_short) {
parsed = expand(b->title_format_short, 0);
if (uzbl.gui.main_window)
gtk_window_set_title (GTK_WINDOW(uzbl.gui.main_window), parsed);
g_free(parsed);
}
if (b->status_format) {
parsed = expand(b->status_format, 0);
gtk_label_set_markup(GTK_LABEL(uzbl.gui.mainbar_label), parsed);
g_free(parsed);
}
if (b->status_background) {
GdkColor color;
gdk_color_parse (b->status_background, &color);
if (uzbl.gui.main_window)
gtk_widget_modify_bg (uzbl.gui.main_window, GTK_STATE_NORMAL, &color);
else if (uzbl.gui.plug)
gtk_widget_modify_bg (GTK_WIDGET(uzbl.gui.plug), GTK_STATE_NORMAL, &color);
}
} else {
if (b->title_format_long) {
parsed = expand(b->title_format_long, 0);
if (uzbl.gui.main_window)
gtk_window_set_title (GTK_WINDOW(uzbl.gui.main_window), parsed);
g_free(parsed);
}
}
}
| @@ -1046,7 +1046,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
WebKitWebFrame *frame;
JSGlobalContextRef context;
JSObjectRef globalobject;
- JSStringRef var_name;
JSStringRef js_script;
JSValueRef js_result;
@@ -1059,12 +1058,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
context = webkit_web_frame_get_global_context(frame);
globalobject = JSContextGetGlobalObject(context);
- /* uzbl javascript namespace */
- var_name = JSStringCreateWithUTF8CString("Uzbl");
- JSObjectSetProperty(context, globalobject, var_name,
- JSObjectMake(context, uzbl.js.classref, NULL),
- kJSClassAttributeNone, NULL);
-
/* evaluate the script and get return value*/
js_script = JSStringCreateWithUTF8CString(script);
js_result = JSEvaluateScript(context, js_script, globalobject, NULL, 0, NULL);
@@ -1082,9 +1075,6 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result) {
}
/* cleanup */
- JSObjectDeleteProperty(context, globalobject, var_name, NULL);
-
- JSStringRelease(var_name);
JSStringRelease(js_script);
}
| CWE-264 | null | null |
14,743 | static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
{
int ret;
int nblocks;
APEContext *ape = s->priv_data;
uint32_t extra_size = 8;
if (s->pb->eof_reached)
return AVERROR(EIO);
if (ape->currentframe > ape->totalframes)
return AVERROR(EIO);
avio_seek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET);
/* Calculate how many blocks there are in this frame */
if (ape->currentframe == (ape->totalframes - 1))
nblocks = ape->finalframeblocks;
else
nblocks = ape->blocksperframe;
if (av_new_packet(pkt, ape->frames[ape->currentframe].size + extra_size) < 0)
return AVERROR(ENOMEM);
AV_WL32(pkt->data , nblocks);
AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip);
ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size);
pkt->pts = ape->frames[ape->currentframe].pts;
pkt->stream_index = 0;
/* note: we need to modify the packet size here to handle the last
packet */
pkt->size = ret + extra_size;
ape->currentframe++;
return 0;
}
| DoS | 0 | static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
{
int ret;
int nblocks;
APEContext *ape = s->priv_data;
uint32_t extra_size = 8;
if (s->pb->eof_reached)
return AVERROR(EIO);
if (ape->currentframe > ape->totalframes)
return AVERROR(EIO);
avio_seek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET);
/* Calculate how many blocks there are in this frame */
if (ape->currentframe == (ape->totalframes - 1))
nblocks = ape->finalframeblocks;
else
nblocks = ape->blocksperframe;
if (av_new_packet(pkt, ape->frames[ape->currentframe].size + extra_size) < 0)
return AVERROR(ENOMEM);
AV_WL32(pkt->data , nblocks);
AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip);
ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size);
pkt->pts = ape->frames[ape->currentframe].pts;
pkt->stream_index = 0;
/* note: we need to modify the packet size here to handle the last
packet */
pkt->size = ret + extra_size;
ape->currentframe++;
return 0;
}
| @@ -242,6 +242,10 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
avio_seek(pb, ape->wavheaderlength, SEEK_CUR);
}
+ if(!ape->totalframes){
+ av_log(s, AV_LOG_ERROR, "No frames in the file!\n");
+ return AVERROR(EINVAL);
+ }
if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){
av_log(s, AV_LOG_ERROR, "Too many frames: %d\n", ape->totalframes);
return -1; | CWE-399 | null | null |
14,744 | static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
{
AVStream *st = s->streams[stream_index];
APEContext *ape = s->priv_data;
int index = av_index_search_timestamp(st, timestamp, flags);
if (index < 0)
return -1;
ape->currentframe = index;
return 0;
}
| DoS | 0 | static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
{
AVStream *st = s->streams[stream_index];
APEContext *ape = s->priv_data;
int index = av_index_search_timestamp(st, timestamp, flags);
if (index < 0)
return -1;
ape->currentframe = index;
return 0;
}
| @@ -242,6 +242,10 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
avio_seek(pb, ape->wavheaderlength, SEEK_CUR);
}
+ if(!ape->totalframes){
+ av_log(s, AV_LOG_ERROR, "No frames in the file!\n");
+ return AVERROR(EINVAL);
+ }
if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){
av_log(s, AV_LOG_ERROR, "Too many frames: %d\n", ape->totalframes);
return -1; | CWE-399 | null | null |
14,745 | static void antiidle(void)
{
if (noopidle == (time_t) -1) {
noopidle = time(NULL);
} else {
if ((time(NULL) - noopidle) > (time_t) idletime_noop) {
die(421, LOG_INFO, MSG_TIMEOUT_NOOP, (unsigned long) idletime_noop);
}
}
}
| null | 0 | static void antiidle(void)
{
if (noopidle == (time_t) -1) {
noopidle = time(NULL);
} else {
if ((time(NULL) - noopidle) > (time_t) idletime_noop) {
die(421, LOG_INFO, MSG_TIMEOUT_NOOP, (unsigned long) idletime_noop);
}
}
}
| @@ -57,14 +57,20 @@ static void randomdelay(void)
* -Frank.
*/
+static size_t scanned;
+static size_t readnbd;
+
+static void flush_cmd(void)
+{
+ scanned = readnbd = (size_t) 0U;
+}
+
int sfgets(void)
{
struct pollfd pfd;
int pollret;
ssize_t readnb;
signed char seen_r = 0;
- static size_t scanned;
- static size_t readnbd;
if (scanned > (size_t) 0U) { /* support pipelining */
readnbd -= scanned;
@@ -362,6 +368,7 @@ void parser(void)
addreply_noformat(234, "AUTH TLS OK.");
doreply();
if (tls_cnx == NULL) {
+ flush_cmd();
(void) tls_init_new_session();
}
goto wayout; | CWE-399 | null | null |
14,746 | static char *revealextraspc(char * const s_)
{
unsigned char *s = (unsigned char *) s_;
unsigned char *sn;
if (s == NULL) {
return s_;
}
simplify(s_);
while (*s != 0U && isspace(*s)) {
*s++ = '_';
}
if (*s == 0U) {
return s_;
}
sn = s;
do {
sn++;
} while (*sn != 0U);
do {
sn--;
if (!isspace(*sn)) {
break;
}
*sn = '_';
} while (sn != s);
return s_;
}
| null | 0 | static char *revealextraspc(char * const s_)
{
unsigned char *s = (unsigned char *) s_;
unsigned char *sn;
if (s == NULL) {
return s_;
}
simplify(s_);
while (*s != 0U && isspace(*s)) {
*s++ = '_';
}
if (*s == 0U) {
return s_;
}
sn = s;
do {
sn++;
} while (*sn != 0U);
do {
sn--;
if (!isspace(*sn)) {
break;
}
*sn = '_';
} while (sn != s);
return s_;
}
| @@ -57,14 +57,20 @@ static void randomdelay(void)
* -Frank.
*/
+static size_t scanned;
+static size_t readnbd;
+
+static void flush_cmd(void)
+{
+ scanned = readnbd = (size_t) 0U;
+}
+
int sfgets(void)
{
struct pollfd pfd;
int pollret;
ssize_t readnb;
signed char seen_r = 0;
- static size_t scanned;
- static size_t readnbd;
if (scanned > (size_t) 0U) { /* support pipelining */
readnbd -= scanned;
@@ -362,6 +368,7 @@ void parser(void)
addreply_noformat(234, "AUTH TLS OK.");
doreply();
if (tls_cnx == NULL) {
+ flush_cmd();
(void) tls_init_new_session();
}
goto wayout; | CWE-399 | null | null |
14,747 | int authorized_client(CLIENT *opts) {
const char *ERRMSG="Invalid entry '%s' in authfile '%s', so, refusing all connections.";
FILE *f ;
char line[LINELEN];
char *tmp;
struct in_addr addr;
struct in_addr client;
struct in_addr cltemp;
int len;
if ((f=fopen(opts->server->authname,"r"))==NULL) {
msg4(LOG_INFO,"Can't open authorization file %s (%s).",
opts->server->authname,strerror(errno)) ;
return 1 ;
}
inet_aton(opts->clientname, &client);
while (fgets(line,LINELEN,f)!=NULL) {
if((tmp=index(line, '/'))) {
if(strlen(line)<=tmp-line) {
msg4(LOG_CRIT, ERRMSG, line, opts->server->authname);
return 0;
}
*(tmp++)=0;
if(!inet_aton(line,&addr)) {
msg4(LOG_CRIT, ERRMSG, line, opts->server->authname);
return 0;
}
len=strtol(tmp, NULL, 0);
addr.s_addr>>=32-len;
addr.s_addr<<=32-len;
memcpy(&cltemp,&client,sizeof(client));
cltemp.s_addr>>=32-len;
cltemp.s_addr<<=32-len;
if(addr.s_addr == cltemp.s_addr) {
return 1;
}
}
if (strncmp(line,opts->clientname,strlen(opts->clientname))==0) {
fclose(f);
return 1;
}
}
fclose(f);
return 0;
}
| Exec Code Overflow | 0 | int authorized_client(CLIENT *opts) {
const char *ERRMSG="Invalid entry '%s' in authfile '%s', so, refusing all connections.";
FILE *f ;
char line[LINELEN];
char *tmp;
struct in_addr addr;
struct in_addr client;
struct in_addr cltemp;
int len;
if ((f=fopen(opts->server->authname,"r"))==NULL) {
msg4(LOG_INFO,"Can't open authorization file %s (%s).",
opts->server->authname,strerror(errno)) ;
return 1 ;
}
inet_aton(opts->clientname, &client);
while (fgets(line,LINELEN,f)!=NULL) {
if((tmp=index(line, '/'))) {
if(strlen(line)<=tmp-line) {
msg4(LOG_CRIT, ERRMSG, line, opts->server->authname);
return 0;
}
*(tmp++)=0;
if(!inet_aton(line,&addr)) {
msg4(LOG_CRIT, ERRMSG, line, opts->server->authname);
return 0;
}
len=strtol(tmp, NULL, 0);
addr.s_addr>>=32-len;
addr.s_addr<<=32-len;
memcpy(&cltemp,&client,sizeof(client));
cltemp.s_addr>>=32-len;
cltemp.s_addr<<=32-len;
if(addr.s_addr == cltemp.s_addr) {
return 1;
}
}
if (strncmp(line,opts->clientname,strlen(opts->clientname))==0) {
fclose(f);
return 1;
}
}
fclose(f);
return 0;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,748 | int copyonwrite_prepare(CLIENT* client) {
off_t i;
if ((client->difffilename = malloc(1024))==NULL)
err("Failed to allocate string for diff file name");
snprintf(client->difffilename, 1024, "%s-%s-%d.diff",client->exportname,client->clientname,
(int)getpid()) ;
client->difffilename[1023]='\0';
msg3(LOG_INFO,"About to create map and diff file %s",client->difffilename) ;
client->difffile=open(client->difffilename,O_RDWR | O_CREAT | O_TRUNC,0600) ;
if (client->difffile<0) err("Could not create diff file (%m)") ;
if ((client->difmap=calloc(client->exportsize/DIFFPAGESIZE,sizeof(u32)))==NULL)
err("Could not allocate memory") ;
for (i=0;i<client->exportsize/DIFFPAGESIZE;i++) client->difmap[i]=(u32)-1 ;
return 0;
}
| Exec Code Overflow | 0 | int copyonwrite_prepare(CLIENT* client) {
off_t i;
if ((client->difffilename = malloc(1024))==NULL)
err("Failed to allocate string for diff file name");
snprintf(client->difffilename, 1024, "%s-%s-%d.diff",client->exportname,client->clientname,
(int)getpid()) ;
client->difffilename[1023]='\0';
msg3(LOG_INFO,"About to create map and diff file %s",client->difffilename) ;
client->difffile=open(client->difffilename,O_RDWR | O_CREAT | O_TRUNC,0600) ;
if (client->difffile<0) err("Could not create diff file (%m)") ;
if ((client->difmap=calloc(client->exportsize/DIFFPAGESIZE,sizeof(u32)))==NULL)
err("Could not allocate memory") ;
for (i=0;i<client->exportsize/DIFFPAGESIZE;i++) client->difmap[i]=(u32)-1 ;
return 0;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,749 | void daemonize(SERVER* serve) {
FILE*pidf;
if(serve && !(serve->port)) {
return;
}
if(daemon(0,0)<0) {
err("daemon");
}
if(!*pidftemplate) {
if(serve) {
strncpy(pidftemplate, "/var/run/nbd-server.%d.pid", 255);
} else {
strncpy(pidftemplate, "/var/run/nbd-server.pid", 255);
}
}
snprintf(pidfname, 255, pidftemplate, serve ? serve->port : 0);
pidf=fopen(pidfname, "w");
if(pidf) {
fprintf(pidf,"%d\n", (int)getpid());
fclose(pidf);
} else {
perror("fopen");
fprintf(stderr, "Not fatal; continuing");
}
}
| Exec Code Overflow | 0 | void daemonize(SERVER* serve) {
FILE*pidf;
if(serve && !(serve->port)) {
return;
}
if(daemon(0,0)<0) {
err("daemon");
}
if(!*pidftemplate) {
if(serve) {
strncpy(pidftemplate, "/var/run/nbd-server.%d.pid", 255);
} else {
strncpy(pidftemplate, "/var/run/nbd-server.pid", 255);
}
}
snprintf(pidfname, 255, pidftemplate, serve ? serve->port : 0);
pidf=fopen(pidfname, "w");
if(pidf) {
fprintf(pidf,"%d\n", (int)getpid());
fclose(pidf);
} else {
perror("fopen");
fprintf(stderr, "Not fatal; continuing");
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,750 | void destroy_pid_t(gpointer data) {
g_free(data);
}
| Exec Code Overflow | 0 | void destroy_pid_t(gpointer data) {
g_free(data);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,751 | int do_run(gchar* command, gchar* file) {
gchar* cmd;
int retval=0;
if(command && *command) {
cmd = g_strdup_printf(command, file);
retval=system(cmd);
g_free(cmd);
}
return retval;
}
| Exec Code Overflow | 0 | int do_run(gchar* command, gchar* file) {
gchar* cmd;
int retval=0;
if(command && *command) {
cmd = g_strdup_printf(command, file);
retval=system(cmd);
g_free(cmd);
}
return retval;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,752 | void dosockopts(int socket) {
#ifndef sun
int yes=1;
#else
char yes='1';
#endif /* sun */
int sock_flags;
/* lose the pesky "Address already in use" error message */
if (setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
err("setsockopt SO_REUSEADDR");
}
if (setsockopt(socket,SOL_SOCKET,SO_KEEPALIVE,&yes,sizeof(int)) == -1) {
err("setsockopt SO_KEEPALIVE");
}
/* make the listening socket non-blocking */
if ((sock_flags = fcntl(socket, F_GETFL, 0)) == -1) {
err("fcntl F_GETFL");
}
if (fcntl(socket, F_SETFL, sock_flags | O_NONBLOCK) == -1) {
err("fcntl F_SETFL O_NONBLOCK");
}
}
| Exec Code Overflow | 0 | void dosockopts(int socket) {
#ifndef sun
int yes=1;
#else
char yes='1';
#endif /* sun */
int sock_flags;
/* lose the pesky "Address already in use" error message */
if (setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
err("setsockopt SO_REUSEADDR");
}
if (setsockopt(socket,SOL_SOCKET,SO_KEEPALIVE,&yes,sizeof(int)) == -1) {
err("setsockopt SO_KEEPALIVE");
}
/* make the listening socket non-blocking */
if ((sock_flags = fcntl(socket, F_GETFL, 0)) == -1) {
err("fcntl F_GETFL");
}
if (fcntl(socket, F_SETFL, sock_flags | O_NONBLOCK) == -1) {
err("fcntl F_SETFL O_NONBLOCK");
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,753 | void dousers(void) {
struct passwd *pw;
struct group *gr;
gchar* str;
if(rungroup) {
gr=getgrnam(rungroup);
if(!gr) {
str = g_strdup_printf("Invalid group name: %s", rungroup);
err(str);
}
if(setgid(gr->gr_gid)<0) {
err("Could not set GID: %m");
}
}
if(runuser) {
pw=getpwnam(runuser);
if(!pw) {
str = g_strdup_printf("Invalid user name: %s", runuser);
err(str);
}
if(setuid(pw->pw_uid)<0) {
err("Could not set UID: %m");
}
}
}
| Exec Code Overflow | 0 | void dousers(void) {
struct passwd *pw;
struct group *gr;
gchar* str;
if(rungroup) {
gr=getgrnam(rungroup);
if(!gr) {
str = g_strdup_printf("Invalid group name: %s", rungroup);
err(str);
}
if(setgid(gr->gr_gid)<0) {
err("Could not set GID: %m");
}
}
if(runuser) {
pw=getpwnam(runuser);
if(!pw) {
str = g_strdup_printf("Invalid user name: %s", runuser);
err(str);
}
if(setuid(pw->pw_uid)<0) {
err("Could not set UID: %m");
}
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,754 | SERVER* dup_serve(SERVER *s) {
SERVER *serve = NULL;
serve=g_new0(SERVER, 1);
if(serve == NULL)
return NULL;
if(s->exportname)
serve->exportname = g_strdup(s->exportname);
serve->expected_size = s->expected_size;
if(s->listenaddr)
serve->listenaddr = g_strdup(s->listenaddr);
serve->port = s->port;
if(s->authname)
serve->authname = strdup(s->authname);
serve->flags = s->flags;
serve->socket = serve->socket;
serve->socket_family = serve->socket_family;
serve->cidrlen = s->cidrlen;
if(s->prerun)
serve->prerun = g_strdup(s->prerun);
if(s->postrun)
serve->postrun = g_strdup(s->postrun);
if(s->servename)
serve->servename = g_strdup(s->servename);
serve->max_connections = s->max_connections;
return serve;
}
| Exec Code Overflow | 0 | SERVER* dup_serve(SERVER *s) {
SERVER *serve = NULL;
serve=g_new0(SERVER, 1);
if(serve == NULL)
return NULL;
if(s->exportname)
serve->exportname = g_strdup(s->exportname);
serve->expected_size = s->expected_size;
if(s->listenaddr)
serve->listenaddr = g_strdup(s->listenaddr);
serve->port = s->port;
if(s->authname)
serve->authname = strdup(s->authname);
serve->flags = s->flags;
serve->socket = serve->socket;
serve->socket_family = serve->socket_family;
serve->cidrlen = s->cidrlen;
if(s->prerun)
serve->prerun = g_strdup(s->prerun);
if(s->postrun)
serve->postrun = g_strdup(s->postrun);
if(s->servename)
serve->servename = g_strdup(s->servename);
serve->max_connections = s->max_connections;
return serve;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,755 | int expread(off_t a, char *buf, size_t len, CLIENT *client) {
off_t rdlen, offset;
off_t mapcnt, mapl, maph, pagestart;
if (!(client->server->flags & F_COPYONWRITE))
return(rawexpread_fully(a, buf, len, client));
DEBUG3("Asked to read %d bytes at %llu.\n", len, (unsigned long long)a);
mapl=a/DIFFPAGESIZE; maph=(a+len-1)/DIFFPAGESIZE;
for (mapcnt=mapl;mapcnt<=maph;mapcnt++) {
pagestart=mapcnt*DIFFPAGESIZE;
offset=a-pagestart;
rdlen=(0<DIFFPAGESIZE-offset && len<(size_t)(DIFFPAGESIZE-offset)) ?
len : (size_t)DIFFPAGESIZE-offset;
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
DEBUG3("Page %llu is at %lu\n", (unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt]));
myseek(client->difffile, client->difmap[mapcnt]*DIFFPAGESIZE+offset);
if (read(client->difffile, buf, rdlen) != rdlen) return -1;
} else { /* the block is not there */
DEBUG2("Page %llu is not here, we read the original one\n",
(unsigned long long)mapcnt);
if(rawexpread_fully(a, buf, rdlen, client)) return -1;
}
len-=rdlen; a+=rdlen; buf+=rdlen;
}
return 0;
}
| Exec Code Overflow | 0 | int expread(off_t a, char *buf, size_t len, CLIENT *client) {
off_t rdlen, offset;
off_t mapcnt, mapl, maph, pagestart;
if (!(client->server->flags & F_COPYONWRITE))
return(rawexpread_fully(a, buf, len, client));
DEBUG3("Asked to read %d bytes at %llu.\n", len, (unsigned long long)a);
mapl=a/DIFFPAGESIZE; maph=(a+len-1)/DIFFPAGESIZE;
for (mapcnt=mapl;mapcnt<=maph;mapcnt++) {
pagestart=mapcnt*DIFFPAGESIZE;
offset=a-pagestart;
rdlen=(0<DIFFPAGESIZE-offset && len<(size_t)(DIFFPAGESIZE-offset)) ?
len : (size_t)DIFFPAGESIZE-offset;
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
DEBUG3("Page %llu is at %lu\n", (unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt]));
myseek(client->difffile, client->difmap[mapcnt]*DIFFPAGESIZE+offset);
if (read(client->difffile, buf, rdlen) != rdlen) return -1;
} else { /* the block is not there */
DEBUG2("Page %llu is not here, we read the original one\n",
(unsigned long long)mapcnt);
if(rawexpread_fully(a, buf, rdlen, client)) return -1;
}
len-=rdlen; a+=rdlen; buf+=rdlen;
}
return 0;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,756 | int expwrite(off_t a, char *buf, size_t len, CLIENT *client) {
char pagebuf[DIFFPAGESIZE];
off_t mapcnt,mapl,maph;
off_t wrlen,rdlen;
off_t pagestart;
off_t offset;
if (!(client->server->flags & F_COPYONWRITE))
return(rawexpwrite_fully(a, buf, len, client));
DEBUG3("Asked to write %d bytes at %llu.\n", len, (unsigned long long)a);
mapl=a/DIFFPAGESIZE ; maph=(a+len-1)/DIFFPAGESIZE ;
for (mapcnt=mapl;mapcnt<=maph;mapcnt++) {
pagestart=mapcnt*DIFFPAGESIZE ;
offset=a-pagestart ;
wrlen=(0<DIFFPAGESIZE-offset && len<(size_t)(DIFFPAGESIZE-offset)) ?
len : (size_t)DIFFPAGESIZE-offset;
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
DEBUG3("Page %llu is at %lu\n", (unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt])) ;
myseek(client->difffile,
client->difmap[mapcnt]*DIFFPAGESIZE+offset);
if (write(client->difffile, buf, wrlen) != wrlen) return -1 ;
} else { /* the block is not there */
myseek(client->difffile,client->difffilelen*DIFFPAGESIZE) ;
client->difmap[mapcnt]=(client->server->flags&F_SPARSE)?mapcnt:client->difffilelen++;
DEBUG3("Page %llu is not here, we put it at %lu\n",
(unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt]));
rdlen=DIFFPAGESIZE ;
if (rawexpread_fully(pagestart, pagebuf, rdlen, client))
return -1;
memcpy(pagebuf+offset,buf,wrlen) ;
if (write(client->difffile, pagebuf, DIFFPAGESIZE) !=
DIFFPAGESIZE)
return -1;
}
len-=wrlen ; a+=wrlen ; buf+=wrlen ;
}
return 0;
}
| Exec Code Overflow | 0 | int expwrite(off_t a, char *buf, size_t len, CLIENT *client) {
char pagebuf[DIFFPAGESIZE];
off_t mapcnt,mapl,maph;
off_t wrlen,rdlen;
off_t pagestart;
off_t offset;
if (!(client->server->flags & F_COPYONWRITE))
return(rawexpwrite_fully(a, buf, len, client));
DEBUG3("Asked to write %d bytes at %llu.\n", len, (unsigned long long)a);
mapl=a/DIFFPAGESIZE ; maph=(a+len-1)/DIFFPAGESIZE ;
for (mapcnt=mapl;mapcnt<=maph;mapcnt++) {
pagestart=mapcnt*DIFFPAGESIZE ;
offset=a-pagestart ;
wrlen=(0<DIFFPAGESIZE-offset && len<(size_t)(DIFFPAGESIZE-offset)) ?
len : (size_t)DIFFPAGESIZE-offset;
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
DEBUG3("Page %llu is at %lu\n", (unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt])) ;
myseek(client->difffile,
client->difmap[mapcnt]*DIFFPAGESIZE+offset);
if (write(client->difffile, buf, wrlen) != wrlen) return -1 ;
} else { /* the block is not there */
myseek(client->difffile,client->difffilelen*DIFFPAGESIZE) ;
client->difmap[mapcnt]=(client->server->flags&F_SPARSE)?mapcnt:client->difffilelen++;
DEBUG3("Page %llu is not here, we put it at %lu\n",
(unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt]));
rdlen=DIFFPAGESIZE ;
if (rawexpread_fully(pagestart, pagebuf, rdlen, client))
return -1;
memcpy(pagebuf+offset,buf,wrlen) ;
if (write(client->difffile, pagebuf, DIFFPAGESIZE) !=
DIFFPAGESIZE)
return -1;
}
len-=wrlen ; a+=wrlen ; buf+=wrlen ;
}
return 0;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,757 | int get_filepos(GArray* export, off_t a, int* fhandle, off_t* foffset, size_t* maxbytes ) {
/* Negative offset not allowed */
if(a < 0)
return -1;
/* Binary search for last file with starting offset <= a */
FILE_INFO fi;
int start = 0;
int end = export->len - 1;
while( start <= end ) {
int mid = (start + end) / 2;
fi = g_array_index(export, FILE_INFO, mid);
if( fi.startoff < a ) {
start = mid + 1;
} else if( fi.startoff > a ) {
end = mid - 1;
} else {
start = end = mid;
break;
}
}
/* end should never go negative, since first startoff is 0 and a >= 0 */
g_assert(end >= 0);
fi = g_array_index(export, FILE_INFO, end);
*fhandle = fi.fhandle;
*foffset = a - fi.startoff;
*maxbytes = 0;
if( end+1 < export->len ) {
FILE_INFO fi_next = g_array_index(export, FILE_INFO, end+1);
*maxbytes = fi_next.startoff - a;
}
return 0;
}
| Exec Code Overflow | 0 | int get_filepos(GArray* export, off_t a, int* fhandle, off_t* foffset, size_t* maxbytes ) {
/* Negative offset not allowed */
if(a < 0)
return -1;
/* Binary search for last file with starting offset <= a */
FILE_INFO fi;
int start = 0;
int end = export->len - 1;
while( start <= end ) {
int mid = (start + end) / 2;
fi = g_array_index(export, FILE_INFO, mid);
if( fi.startoff < a ) {
start = mid + 1;
} else if( fi.startoff > a ) {
end = mid - 1;
} else {
start = end = mid;
break;
}
}
/* end should never go negative, since first startoff is 0 and a >= 0 */
g_assert(end >= 0);
fi = g_array_index(export, FILE_INFO, end);
*fhandle = fi.fhandle;
*foffset = a - fi.startoff;
*maxbytes = 0;
if( end+1 < export->len ) {
FILE_INFO fi_next = g_array_index(export, FILE_INFO, end+1);
*maxbytes = fi_next.startoff - a;
}
return 0;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,758 | void killchild(gpointer key, gpointer value, gpointer user_data) {
pid_t *pid=value;
int *parent=user_data;
kill(*pid, SIGTERM);
*parent=1;
}
| Exec Code Overflow | 0 | void killchild(gpointer key, gpointer value, gpointer user_data) {
pid_t *pid=value;
int *parent=user_data;
kill(*pid, SIGTERM);
*parent=1;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,759 | void myseek(int handle,off_t a) {
if (lseek(handle, a, SEEK_SET) < 0) {
err("Can not seek locally!\n");
}
}
| Exec Code Overflow | 0 | void myseek(int handle,off_t a) {
if (lseek(handle, a, SEEK_SET) < 0) {
err("Can not seek locally!\n");
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,760 | void open_modern(void) {
struct addrinfo hints;
struct addrinfo* ai = NULL;
struct sock_flags;
int e;
memset(&hints, '\0', sizeof(hints));
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_UNSPEC;
hints.ai_protocol = IPPROTO_TCP;
e = getaddrinfo(modern_listen, NBD_DEFAULT_PORT, &hints, &ai);
if(e != 0) {
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
exit(EXIT_FAILURE);
}
if((modernsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol))<0) {
err("socket: %m");
}
dosockopts(modernsock);
if(bind(modernsock, ai->ai_addr, ai->ai_addrlen)) {
err("bind: %m");
}
if(listen(modernsock, 10) <0) {
err("listen: %m");
}
freeaddrinfo(ai);
}
| Exec Code Overflow | 0 | void open_modern(void) {
struct addrinfo hints;
struct addrinfo* ai = NULL;
struct sock_flags;
int e;
memset(&hints, '\0', sizeof(hints));
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_UNSPEC;
hints.ai_protocol = IPPROTO_TCP;
e = getaddrinfo(modern_listen, NBD_DEFAULT_PORT, &hints, &ai);
if(e != 0) {
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
exit(EXIT_FAILURE);
}
if((modernsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol))<0) {
err("socket: %m");
}
dosockopts(modernsock);
if(bind(modernsock, ai->ai_addr, ai->ai_addrlen)) {
err("bind: %m");
}
if(listen(modernsock, 10) <0) {
err("listen: %m");
}
freeaddrinfo(ai);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,761 | GArray* parse_cfile(gchar* f, GError** e) {
const char* DEFAULT_ERROR = "Could not parse %s in group %s: %s";
const char* MISSING_REQUIRED_ERROR = "Could not find required value %s in group %s: %s";
SERVER s;
gchar *virtstyle=NULL;
PARAM lp[] = {
{ "exportname", TRUE, PARAM_STRING, NULL, 0 },
{ "port", TRUE, PARAM_INT, NULL, 0 },
{ "authfile", FALSE, PARAM_STRING, NULL, 0 },
{ "filesize", FALSE, PARAM_INT, NULL, 0 },
{ "virtstyle", FALSE, PARAM_STRING, NULL, 0 },
{ "prerun", FALSE, PARAM_STRING, NULL, 0 },
{ "postrun", FALSE, PARAM_STRING, NULL, 0 },
{ "readonly", FALSE, PARAM_BOOL, NULL, F_READONLY },
{ "multifile", FALSE, PARAM_BOOL, NULL, F_MULTIFILE },
{ "copyonwrite", FALSE, PARAM_BOOL, NULL, F_COPYONWRITE },
{ "sparse_cow", FALSE, PARAM_BOOL, NULL, F_SPARSE },
{ "sdp", FALSE, PARAM_BOOL, NULL, F_SDP },
{ "sync", FALSE, PARAM_BOOL, NULL, F_SYNC },
{ "listenaddr", FALSE, PARAM_STRING, NULL, 0 },
{ "maxconnections", FALSE, PARAM_INT, NULL, 0 },
};
const int lp_size=sizeof(lp)/sizeof(PARAM);
PARAM gp[] = {
{ "user", FALSE, PARAM_STRING, &runuser, 0 },
{ "group", FALSE, PARAM_STRING, &rungroup, 0 },
{ "oldstyle", FALSE, PARAM_BOOL, &do_oldstyle, 1 },
{ "listenaddr", FALSE, PARAM_STRING, &modern_listen, 0 },
};
PARAM* p=gp;
int p_size=sizeof(gp)/sizeof(PARAM);
GKeyFile *cfile;
GError *err = NULL;
const char *err_msg=NULL;
GQuark errdomain;
GArray *retval=NULL;
gchar **groups;
gboolean value;
gchar* startgroup;
gint i;
gint j;
errdomain = g_quark_from_string("parse_cfile");
cfile = g_key_file_new();
retval = g_array_new(FALSE, TRUE, sizeof(SERVER));
if(!g_key_file_load_from_file(cfile, f, G_KEY_FILE_KEEP_COMMENTS |
G_KEY_FILE_KEEP_TRANSLATIONS, &err)) {
g_set_error(e, errdomain, CFILE_NOTFOUND, "Could not open config file %s.", f);
g_key_file_free(cfile);
return retval;
}
startgroup = g_key_file_get_start_group(cfile);
if(!startgroup || strcmp(startgroup, "generic")) {
g_set_error(e, errdomain, CFILE_MISSING_GENERIC, "Config file does not contain the [generic] group!");
g_key_file_free(cfile);
return NULL;
}
groups = g_key_file_get_groups(cfile, NULL);
for(i=0;groups[i];i++) {
memset(&s, '\0', sizeof(SERVER));
lp[0].target=&(s.exportname);
lp[1].target=&(s.port);
lp[2].target=&(s.authname);
lp[3].target=&(s.expected_size);
lp[4].target=&(virtstyle);
lp[5].target=&(s.prerun);
lp[6].target=&(s.postrun);
lp[7].target=lp[8].target=lp[9].target=
lp[10].target=lp[11].target=
lp[12].target=&(s.flags);
lp[13].target=&(s.listenaddr);
lp[14].target=&(s.max_connections);
/* After the [generic] group, start parsing exports */
if(i==1) {
p=lp;
p_size=lp_size;
}
for(j=0;j<p_size;j++) {
g_assert(p[j].target != NULL);
g_assert(p[j].ptype==PARAM_INT||p[j].ptype==PARAM_STRING||p[j].ptype==PARAM_BOOL);
switch(p[j].ptype) {
case PARAM_INT:
*((gint*)p[j].target) =
g_key_file_get_integer(cfile,
groups[i],
p[j].paramname,
&err);
break;
case PARAM_STRING:
*((gchar**)p[j].target) =
g_key_file_get_string(cfile,
groups[i],
p[j].paramname,
&err);
break;
case PARAM_BOOL:
value = g_key_file_get_boolean(cfile,
groups[i],
p[j].paramname, &err);
if(!err) {
if(value) {
*((gint*)p[j].target) |= p[j].flagval;
} else {
*((gint*)p[j].target) &= ~(p[j].flagval);
}
}
break;
}
if(!strcmp(p[j].paramname, "port") && !strcmp(p[j].target, NBD_DEFAULT_PORT)) {
g_set_error(e, errdomain, CFILE_INCORRECT_PORT, "Config file specifies default port for oldstyle export");
g_key_file_free(cfile);
return NULL;
}
if(err) {
if(err->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND) {
if(!p[j].required) {
/* Ignore not-found error for optional values */
g_clear_error(&err);
continue;
} else {
err_msg = MISSING_REQUIRED_ERROR;
}
} else {
err_msg = DEFAULT_ERROR;
}
g_set_error(e, errdomain, CFILE_VALUE_INVALID, err_msg, p[j].paramname, groups[i], err->message);
g_array_free(retval, TRUE);
g_error_free(err);
g_key_file_free(cfile);
return NULL;
}
}
if(virtstyle) {
if(!strncmp(virtstyle, "none", 4)) {
s.virtstyle=VIRT_NONE;
} else if(!strncmp(virtstyle, "ipliteral", 9)) {
s.virtstyle=VIRT_IPLIT;
} else if(!strncmp(virtstyle, "iphash", 6)) {
s.virtstyle=VIRT_IPHASH;
} else if(!strncmp(virtstyle, "cidrhash", 8)) {
s.virtstyle=VIRT_CIDR;
if(strlen(virtstyle)<10) {
g_set_error(e, errdomain, CFILE_VALUE_INVALID, "Invalid value %s for parameter virtstyle in group %s: missing length", virtstyle, groups[i]);
g_array_free(retval, TRUE);
g_key_file_free(cfile);
return NULL;
}
s.cidrlen=strtol(virtstyle+8, NULL, 0);
} else {
g_set_error(e, errdomain, CFILE_VALUE_INVALID, "Invalid value %s for parameter virtstyle in group %s", virtstyle, groups[i]);
g_array_free(retval, TRUE);
g_key_file_free(cfile);
return NULL;
}
if(s.port && !do_oldstyle) {
g_warning("A port was specified, but oldstyle exports were not requested. This may not do what you expect.");
g_warning("Please read 'man 5 nbd-server' and search for oldstyle for more info");
}
} else {
s.virtstyle=VIRT_IPLIT;
}
/* Don't need to free this, it's not our string */
virtstyle=NULL;
/* Don't append values for the [generic] group */
if(i>0) {
s.socket_family = AF_UNSPEC;
s.servename = groups[i];
append_serve(&s, retval);
} else {
if(!do_oldstyle) {
lp[1].required = 0;
}
}
#ifndef WITH_SDP
if(s.flags & F_SDP) {
g_set_error(e, errdomain, CFILE_VALUE_UNSUPPORTED, "This nbd-server was built without support for SDP, yet group %s uses it", groups[i]);
g_array_free(retval, TRUE);
g_key_file_free(cfile);
return NULL;
}
#endif
}
if(i==1) {
g_set_error(e, errdomain, CFILE_NO_EXPORTS, "The config file does not specify any exports");
}
g_key_file_free(cfile);
return retval;
}
| Exec Code Overflow | 0 | GArray* parse_cfile(gchar* f, GError** e) {
const char* DEFAULT_ERROR = "Could not parse %s in group %s: %s";
const char* MISSING_REQUIRED_ERROR = "Could not find required value %s in group %s: %s";
SERVER s;
gchar *virtstyle=NULL;
PARAM lp[] = {
{ "exportname", TRUE, PARAM_STRING, NULL, 0 },
{ "port", TRUE, PARAM_INT, NULL, 0 },
{ "authfile", FALSE, PARAM_STRING, NULL, 0 },
{ "filesize", FALSE, PARAM_INT, NULL, 0 },
{ "virtstyle", FALSE, PARAM_STRING, NULL, 0 },
{ "prerun", FALSE, PARAM_STRING, NULL, 0 },
{ "postrun", FALSE, PARAM_STRING, NULL, 0 },
{ "readonly", FALSE, PARAM_BOOL, NULL, F_READONLY },
{ "multifile", FALSE, PARAM_BOOL, NULL, F_MULTIFILE },
{ "copyonwrite", FALSE, PARAM_BOOL, NULL, F_COPYONWRITE },
{ "sparse_cow", FALSE, PARAM_BOOL, NULL, F_SPARSE },
{ "sdp", FALSE, PARAM_BOOL, NULL, F_SDP },
{ "sync", FALSE, PARAM_BOOL, NULL, F_SYNC },
{ "listenaddr", FALSE, PARAM_STRING, NULL, 0 },
{ "maxconnections", FALSE, PARAM_INT, NULL, 0 },
};
const int lp_size=sizeof(lp)/sizeof(PARAM);
PARAM gp[] = {
{ "user", FALSE, PARAM_STRING, &runuser, 0 },
{ "group", FALSE, PARAM_STRING, &rungroup, 0 },
{ "oldstyle", FALSE, PARAM_BOOL, &do_oldstyle, 1 },
{ "listenaddr", FALSE, PARAM_STRING, &modern_listen, 0 },
};
PARAM* p=gp;
int p_size=sizeof(gp)/sizeof(PARAM);
GKeyFile *cfile;
GError *err = NULL;
const char *err_msg=NULL;
GQuark errdomain;
GArray *retval=NULL;
gchar **groups;
gboolean value;
gchar* startgroup;
gint i;
gint j;
errdomain = g_quark_from_string("parse_cfile");
cfile = g_key_file_new();
retval = g_array_new(FALSE, TRUE, sizeof(SERVER));
if(!g_key_file_load_from_file(cfile, f, G_KEY_FILE_KEEP_COMMENTS |
G_KEY_FILE_KEEP_TRANSLATIONS, &err)) {
g_set_error(e, errdomain, CFILE_NOTFOUND, "Could not open config file %s.", f);
g_key_file_free(cfile);
return retval;
}
startgroup = g_key_file_get_start_group(cfile);
if(!startgroup || strcmp(startgroup, "generic")) {
g_set_error(e, errdomain, CFILE_MISSING_GENERIC, "Config file does not contain the [generic] group!");
g_key_file_free(cfile);
return NULL;
}
groups = g_key_file_get_groups(cfile, NULL);
for(i=0;groups[i];i++) {
memset(&s, '\0', sizeof(SERVER));
lp[0].target=&(s.exportname);
lp[1].target=&(s.port);
lp[2].target=&(s.authname);
lp[3].target=&(s.expected_size);
lp[4].target=&(virtstyle);
lp[5].target=&(s.prerun);
lp[6].target=&(s.postrun);
lp[7].target=lp[8].target=lp[9].target=
lp[10].target=lp[11].target=
lp[12].target=&(s.flags);
lp[13].target=&(s.listenaddr);
lp[14].target=&(s.max_connections);
/* After the [generic] group, start parsing exports */
if(i==1) {
p=lp;
p_size=lp_size;
}
for(j=0;j<p_size;j++) {
g_assert(p[j].target != NULL);
g_assert(p[j].ptype==PARAM_INT||p[j].ptype==PARAM_STRING||p[j].ptype==PARAM_BOOL);
switch(p[j].ptype) {
case PARAM_INT:
*((gint*)p[j].target) =
g_key_file_get_integer(cfile,
groups[i],
p[j].paramname,
&err);
break;
case PARAM_STRING:
*((gchar**)p[j].target) =
g_key_file_get_string(cfile,
groups[i],
p[j].paramname,
&err);
break;
case PARAM_BOOL:
value = g_key_file_get_boolean(cfile,
groups[i],
p[j].paramname, &err);
if(!err) {
if(value) {
*((gint*)p[j].target) |= p[j].flagval;
} else {
*((gint*)p[j].target) &= ~(p[j].flagval);
}
}
break;
}
if(!strcmp(p[j].paramname, "port") && !strcmp(p[j].target, NBD_DEFAULT_PORT)) {
g_set_error(e, errdomain, CFILE_INCORRECT_PORT, "Config file specifies default port for oldstyle export");
g_key_file_free(cfile);
return NULL;
}
if(err) {
if(err->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND) {
if(!p[j].required) {
/* Ignore not-found error for optional values */
g_clear_error(&err);
continue;
} else {
err_msg = MISSING_REQUIRED_ERROR;
}
} else {
err_msg = DEFAULT_ERROR;
}
g_set_error(e, errdomain, CFILE_VALUE_INVALID, err_msg, p[j].paramname, groups[i], err->message);
g_array_free(retval, TRUE);
g_error_free(err);
g_key_file_free(cfile);
return NULL;
}
}
if(virtstyle) {
if(!strncmp(virtstyle, "none", 4)) {
s.virtstyle=VIRT_NONE;
} else if(!strncmp(virtstyle, "ipliteral", 9)) {
s.virtstyle=VIRT_IPLIT;
} else if(!strncmp(virtstyle, "iphash", 6)) {
s.virtstyle=VIRT_IPHASH;
} else if(!strncmp(virtstyle, "cidrhash", 8)) {
s.virtstyle=VIRT_CIDR;
if(strlen(virtstyle)<10) {
g_set_error(e, errdomain, CFILE_VALUE_INVALID, "Invalid value %s for parameter virtstyle in group %s: missing length", virtstyle, groups[i]);
g_array_free(retval, TRUE);
g_key_file_free(cfile);
return NULL;
}
s.cidrlen=strtol(virtstyle+8, NULL, 0);
} else {
g_set_error(e, errdomain, CFILE_VALUE_INVALID, "Invalid value %s for parameter virtstyle in group %s", virtstyle, groups[i]);
g_array_free(retval, TRUE);
g_key_file_free(cfile);
return NULL;
}
if(s.port && !do_oldstyle) {
g_warning("A port was specified, but oldstyle exports were not requested. This may not do what you expect.");
g_warning("Please read 'man 5 nbd-server' and search for oldstyle for more info");
}
} else {
s.virtstyle=VIRT_IPLIT;
}
/* Don't need to free this, it's not our string */
virtstyle=NULL;
/* Don't append values for the [generic] group */
if(i>0) {
s.socket_family = AF_UNSPEC;
s.servename = groups[i];
append_serve(&s, retval);
} else {
if(!do_oldstyle) {
lp[1].required = 0;
}
}
#ifndef WITH_SDP
if(s.flags & F_SDP) {
g_set_error(e, errdomain, CFILE_VALUE_UNSUPPORTED, "This nbd-server was built without support for SDP, yet group %s uses it", groups[i]);
g_array_free(retval, TRUE);
g_key_file_free(cfile);
return NULL;
}
#endif
}
if(i==1) {
g_set_error(e, errdomain, CFILE_NO_EXPORTS, "The config file does not specify any exports");
}
g_key_file_free(cfile);
return retval;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,762 | ssize_t rawexpread(off_t a, char *buf, size_t len, CLIENT *client) {
int fhandle;
off_t foffset;
size_t maxbytes;
if(get_filepos(client->export, a, &fhandle, &foffset, &maxbytes))
return -1;
if(maxbytes && len > maxbytes)
len = maxbytes;
DEBUG4("(READ from fd %d offset %llu len %u), ", fhandle, foffset, len);
myseek(fhandle, foffset);
return read(fhandle, buf, len);
}
| Exec Code Overflow | 0 | ssize_t rawexpread(off_t a, char *buf, size_t len, CLIENT *client) {
int fhandle;
off_t foffset;
size_t maxbytes;
if(get_filepos(client->export, a, &fhandle, &foffset, &maxbytes))
return -1;
if(maxbytes && len > maxbytes)
len = maxbytes;
DEBUG4("(READ from fd %d offset %llu len %u), ", fhandle, foffset, len);
myseek(fhandle, foffset);
return read(fhandle, buf, len);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,763 | int rawexpread_fully(off_t a, char *buf, size_t len, CLIENT *client) {
ssize_t ret=0;
while(len > 0 && (ret=rawexpread(a, buf, len, client)) > 0 ) {
a += ret;
buf += ret;
len -= ret;
}
return (ret < 0 || len != 0);
}
| Exec Code Overflow | 0 | int rawexpread_fully(off_t a, char *buf, size_t len, CLIENT *client) {
ssize_t ret=0;
while(len > 0 && (ret=rawexpread(a, buf, len, client)) > 0 ) {
a += ret;
buf += ret;
len -= ret;
}
return (ret < 0 || len != 0);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,764 | ssize_t rawexpwrite(off_t a, char *buf, size_t len, CLIENT *client) {
int fhandle;
off_t foffset;
size_t maxbytes;
ssize_t retval;
if(get_filepos(client->export, a, &fhandle, &foffset, &maxbytes))
return -1;
if(maxbytes && len > maxbytes)
len = maxbytes;
DEBUG4("(WRITE to fd %d offset %llu len %u), ", fhandle, foffset, len);
myseek(fhandle, foffset);
retval = write(fhandle, buf, len);
if(client->server->flags & F_SYNC) {
fsync(fhandle);
}
return retval;
}
| Exec Code Overflow | 0 | ssize_t rawexpwrite(off_t a, char *buf, size_t len, CLIENT *client) {
int fhandle;
off_t foffset;
size_t maxbytes;
ssize_t retval;
if(get_filepos(client->export, a, &fhandle, &foffset, &maxbytes))
return -1;
if(maxbytes && len > maxbytes)
len = maxbytes;
DEBUG4("(WRITE to fd %d offset %llu len %u), ", fhandle, foffset, len);
myseek(fhandle, foffset);
retval = write(fhandle, buf, len);
if(client->server->flags & F_SYNC) {
fsync(fhandle);
}
return retval;
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,765 | int rawexpwrite_fully(off_t a, char *buf, size_t len, CLIENT *client) {
ssize_t ret=0;
while(len > 0 && (ret=rawexpwrite(a, buf, len, client)) > 0 ) {
a += ret;
buf += ret;
len -= ret;
}
return (ret < 0 || len != 0);
}
| Exec Code Overflow | 0 | int rawexpwrite_fully(off_t a, char *buf, size_t len, CLIENT *client) {
ssize_t ret=0;
while(len > 0 && (ret=rawexpwrite(a, buf, len, client)) > 0 ) {
a += ret;
buf += ret;
len -= ret;
}
return (ret < 0 || len != 0);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,766 | inline void readit(int f, void *buf, size_t len) {
ssize_t res;
while (len > 0) {
DEBUG("*");
if ((res = read(f, buf, len)) <= 0) {
if(errno != EAGAIN) {
err("Read failed: %m");
}
} else {
len -= res;
buf += res;
}
}
}
| Exec Code Overflow | 0 | inline void readit(int f, void *buf, size_t len) {
ssize_t res;
while (len > 0) {
DEBUG("*");
if ((res = read(f, buf, len)) <= 0) {
if(errno != EAGAIN) {
err("Read failed: %m");
}
} else {
len -= res;
buf += res;
}
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,767 | void remove_server(gpointer s) {
SERVER *server;
server=(SERVER*)s;
g_free(server->exportname);
if(server->authname)
g_free(server->authname);
if(server->listenaddr)
g_free(server->listenaddr);
if(server->prerun)
g_free(server->prerun);
if(server->postrun)
g_free(server->postrun);
g_free(server);
}
| Exec Code Overflow | 0 | void remove_server(gpointer s) {
SERVER *server;
server=(SERVER*)s;
g_free(server->exportname);
if(server->authname)
g_free(server->authname);
if(server->listenaddr)
g_free(server->listenaddr);
if(server->prerun)
g_free(server->prerun);
if(server->postrun)
g_free(server->postrun);
g_free(server);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,768 | void serve_err(SERVER* serve, const char* msg) {
g_message("Export of %s on port %d failed:", serve->exportname,
serve->port);
err(msg);
}
| Exec Code Overflow | 0 | void serve_err(SERVER* serve, const char* msg) {
g_message("Export of %s on port %d failed:", serve->exportname,
serve->port);
err(msg);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,769 | void serveconnection(CLIENT *client) {
if(do_run(client->server->prerun, client->exportname)) {
exit(EXIT_FAILURE);
}
setupexport(client);
if (client->server->flags & F_COPYONWRITE) {
copyonwrite_prepare(client);
}
setmysockopt(client->net);
mainloop(client);
do_run(client->server->postrun, client->exportname);
}
| Exec Code Overflow | 0 | void serveconnection(CLIENT *client) {
if(do_run(client->server->prerun, client->exportname)) {
exit(EXIT_FAILURE);
}
setupexport(client);
if (client->server->flags & F_COPYONWRITE) {
copyonwrite_prepare(client);
}
setmysockopt(client->net);
mainloop(client);
do_run(client->server->postrun, client->exportname);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,770 | int serveloop(GArray* servers) {
struct sockaddr_storage addrin;
socklen_t addrinlen=sizeof(addrin);
int i;
int max;
int sock;
fd_set mset;
fd_set rset;
/*
* Set up the master fd_set. The set of descriptors we need
* to select() for never changes anyway and it buys us a *lot*
* of time to only build this once. However, if we ever choose
* to not fork() for clients anymore, we may have to revisit
* this.
*/
max=0;
FD_ZERO(&mset);
for(i=0;i<servers->len;i++) {
if((sock=(g_array_index(servers, SERVER, i)).socket)) {
FD_SET(sock, &mset);
max=sock>max?sock:max;
}
}
if(modernsock) {
FD_SET(modernsock, &mset);
max=modernsock>max?modernsock:max;
}
for(;;) {
CLIENT *client = NULL;
pid_t *pid;
memcpy(&rset, &mset, sizeof(fd_set));
if(select(max+1, &rset, NULL, NULL, NULL)>0) {
int net = 0;
SERVER* serve;
DEBUG("accept, ");
if(FD_ISSET(modernsock, &rset)) {
if((net=accept(modernsock, (struct sockaddr *) &addrin, &addrinlen)) < 0)
err("accept: %m");
client = negotiate(net, NULL, servers);
if(!client) {
err_nonfatal("negotiation failed");
close(net);
net=0;
}
}
for(i=0;i<servers->len && !net;i++) {
serve=&(g_array_index(servers, SERVER, i));
if(FD_ISSET(serve->socket, &rset)) {
if ((net=accept(serve->socket, (struct sockaddr *) &addrin, &addrinlen)) < 0)
err("accept: %m");
}
}
if(net) {
int sock_flags;
if(serve->max_connections > 0 &&
g_hash_table_size(children) >= serve->max_connections) {
msg2(LOG_INFO, "Max connections reached");
close(net);
continue;
}
if((sock_flags = fcntl(net, F_GETFL, 0))==-1) {
err("fcntl F_GETFL");
}
if(fcntl(net, F_SETFL, sock_flags &~O_NONBLOCK)==-1) {
err("fcntl F_SETFL ~O_NONBLOCK");
}
if(!client) {
client = g_new0(CLIENT, 1);
client->server=serve;
client->exportsize=OFFT_MAX;
client->net=net;
}
set_peername(net, client);
if (!authorized_client(client)) {
msg2(LOG_INFO,"Unauthorized client") ;
close(net);
continue;
}
msg2(LOG_INFO,"Authorized client") ;
pid=g_malloc(sizeof(pid_t));
#ifndef NOFORK
if ((*pid=fork())<0) {
msg3(LOG_INFO,"Could not fork (%s)",strerror(errno)) ;
close(net);
continue;
}
if (*pid>0) { /* parent */
close(net);
g_hash_table_insert(children, pid, pid);
continue;
}
/* child */
g_hash_table_destroy(children);
for(i=0;i<servers->len;i++) {
serve=&g_array_index(servers, SERVER, i);
close(serve->socket);
}
/* FALSE does not free the
actual data. This is required,
because the client has a
direct reference into that
data, and otherwise we get a
segfault... */
g_array_free(servers, FALSE);
#endif // NOFORK
msg2(LOG_INFO,"Starting to serve");
serveconnection(client);
exit(EXIT_SUCCESS);
}
}
}
}
| Exec Code Overflow | 0 | int serveloop(GArray* servers) {
struct sockaddr_storage addrin;
socklen_t addrinlen=sizeof(addrin);
int i;
int max;
int sock;
fd_set mset;
fd_set rset;
/*
* Set up the master fd_set. The set of descriptors we need
* to select() for never changes anyway and it buys us a *lot*
* of time to only build this once. However, if we ever choose
* to not fork() for clients anymore, we may have to revisit
* this.
*/
max=0;
FD_ZERO(&mset);
for(i=0;i<servers->len;i++) {
if((sock=(g_array_index(servers, SERVER, i)).socket)) {
FD_SET(sock, &mset);
max=sock>max?sock:max;
}
}
if(modernsock) {
FD_SET(modernsock, &mset);
max=modernsock>max?modernsock:max;
}
for(;;) {
CLIENT *client = NULL;
pid_t *pid;
memcpy(&rset, &mset, sizeof(fd_set));
if(select(max+1, &rset, NULL, NULL, NULL)>0) {
int net = 0;
SERVER* serve;
DEBUG("accept, ");
if(FD_ISSET(modernsock, &rset)) {
if((net=accept(modernsock, (struct sockaddr *) &addrin, &addrinlen)) < 0)
err("accept: %m");
client = negotiate(net, NULL, servers);
if(!client) {
err_nonfatal("negotiation failed");
close(net);
net=0;
}
}
for(i=0;i<servers->len && !net;i++) {
serve=&(g_array_index(servers, SERVER, i));
if(FD_ISSET(serve->socket, &rset)) {
if ((net=accept(serve->socket, (struct sockaddr *) &addrin, &addrinlen)) < 0)
err("accept: %m");
}
}
if(net) {
int sock_flags;
if(serve->max_connections > 0 &&
g_hash_table_size(children) >= serve->max_connections) {
msg2(LOG_INFO, "Max connections reached");
close(net);
continue;
}
if((sock_flags = fcntl(net, F_GETFL, 0))==-1) {
err("fcntl F_GETFL");
}
if(fcntl(net, F_SETFL, sock_flags &~O_NONBLOCK)==-1) {
err("fcntl F_SETFL ~O_NONBLOCK");
}
if(!client) {
client = g_new0(CLIENT, 1);
client->server=serve;
client->exportsize=OFFT_MAX;
client->net=net;
}
set_peername(net, client);
if (!authorized_client(client)) {
msg2(LOG_INFO,"Unauthorized client") ;
close(net);
continue;
}
msg2(LOG_INFO,"Authorized client") ;
pid=g_malloc(sizeof(pid_t));
#ifndef NOFORK
if ((*pid=fork())<0) {
msg3(LOG_INFO,"Could not fork (%s)",strerror(errno)) ;
close(net);
continue;
}
if (*pid>0) { /* parent */
close(net);
g_hash_table_insert(children, pid, pid);
continue;
}
/* child */
g_hash_table_destroy(children);
for(i=0;i<servers->len;i++) {
serve=&g_array_index(servers, SERVER, i);
close(serve->socket);
}
/* FALSE does not free the
actual data. This is required,
because the client has a
direct reference into that
data, and otherwise we get a
segfault... */
g_array_free(servers, FALSE);
#endif // NOFORK
msg2(LOG_INFO,"Starting to serve");
serveconnection(client);
exit(EXIT_SUCCESS);
}
}
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,771 | void set_peername(int net, CLIENT *client) {
struct sockaddr_storage addrin;
struct sockaddr_storage netaddr;
struct sockaddr_in *netaddr4 = NULL;
struct sockaddr_in6 *netaddr6 = NULL;
size_t addrinlen = sizeof( addrin );
struct addrinfo hints;
struct addrinfo *ai = NULL;
char peername[NI_MAXHOST];
char netname[NI_MAXHOST];
char *tmp = NULL;
int i;
int e;
int shift;
if (getpeername(net, (struct sockaddr *) &addrin, (socklen_t *)&addrinlen) < 0)
err("getsockname failed: %m");
getnameinfo((struct sockaddr *)&addrin, (socklen_t)addrinlen,
peername, sizeof (peername), NULL, 0, NI_NUMERICHOST);
memset(&hints, '\0', sizeof (hints));
hints.ai_flags = AI_ADDRCONFIG;
e = getaddrinfo(peername, NULL, &hints, &ai);
if(e != 0) {
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
freeaddrinfo(ai);
return;
}
switch(client->server->virtstyle) {
case VIRT_NONE:
client->exportname=g_strdup(client->server->exportname);
break;
case VIRT_IPHASH:
for(i=0;i<strlen(peername);i++) {
if(peername[i]=='.') {
peername[i]='/';
}
}
case VIRT_IPLIT:
client->exportname=g_strdup_printf(client->server->exportname, peername);
break;
case VIRT_CIDR:
memcpy(&netaddr, &addrin, addrinlen);
if(ai->ai_family == AF_INET) {
netaddr4 = (struct sockaddr_in *)&netaddr;
(netaddr4->sin_addr).s_addr>>=32-(client->server->cidrlen);
(netaddr4->sin_addr).s_addr<<=32-(client->server->cidrlen);
getnameinfo((struct sockaddr *) netaddr4, (socklen_t) addrinlen,
netname, sizeof (netname), NULL, 0, NI_NUMERICHOST);
tmp=g_strdup_printf("%s/%s", netname, peername);
}else if(ai->ai_family == AF_INET6) {
netaddr6 = (struct sockaddr_in6 *)&netaddr;
shift = 128-(client->server->cidrlen);
i = 3;
while(shift >= 32) {
((netaddr6->sin6_addr).s6_addr32[i])=0;
shift-=32;
i--;
}
(netaddr6->sin6_addr).s6_addr32[i]>>=shift;
(netaddr6->sin6_addr).s6_addr32[i]<<=shift;
getnameinfo((struct sockaddr *)netaddr6, (socklen_t)addrinlen,
netname, sizeof(netname), NULL, 0, NI_NUMERICHOST);
tmp=g_strdup_printf("%s/%s", netname, peername);
}
if(tmp != NULL)
client->exportname=g_strdup_printf(client->server->exportname, tmp);
break;
}
freeaddrinfo(ai);
msg4(LOG_INFO, "connect from %s, assigned file is %s",
peername, client->exportname);
client->clientname=g_strdup(peername);
}
| Exec Code Overflow | 0 | void set_peername(int net, CLIENT *client) {
struct sockaddr_storage addrin;
struct sockaddr_storage netaddr;
struct sockaddr_in *netaddr4 = NULL;
struct sockaddr_in6 *netaddr6 = NULL;
size_t addrinlen = sizeof( addrin );
struct addrinfo hints;
struct addrinfo *ai = NULL;
char peername[NI_MAXHOST];
char netname[NI_MAXHOST];
char *tmp = NULL;
int i;
int e;
int shift;
if (getpeername(net, (struct sockaddr *) &addrin, (socklen_t *)&addrinlen) < 0)
err("getsockname failed: %m");
getnameinfo((struct sockaddr *)&addrin, (socklen_t)addrinlen,
peername, sizeof (peername), NULL, 0, NI_NUMERICHOST);
memset(&hints, '\0', sizeof (hints));
hints.ai_flags = AI_ADDRCONFIG;
e = getaddrinfo(peername, NULL, &hints, &ai);
if(e != 0) {
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
freeaddrinfo(ai);
return;
}
switch(client->server->virtstyle) {
case VIRT_NONE:
client->exportname=g_strdup(client->server->exportname);
break;
case VIRT_IPHASH:
for(i=0;i<strlen(peername);i++) {
if(peername[i]=='.') {
peername[i]='/';
}
}
case VIRT_IPLIT:
client->exportname=g_strdup_printf(client->server->exportname, peername);
break;
case VIRT_CIDR:
memcpy(&netaddr, &addrin, addrinlen);
if(ai->ai_family == AF_INET) {
netaddr4 = (struct sockaddr_in *)&netaddr;
(netaddr4->sin_addr).s_addr>>=32-(client->server->cidrlen);
(netaddr4->sin_addr).s_addr<<=32-(client->server->cidrlen);
getnameinfo((struct sockaddr *) netaddr4, (socklen_t) addrinlen,
netname, sizeof (netname), NULL, 0, NI_NUMERICHOST);
tmp=g_strdup_printf("%s/%s", netname, peername);
}else if(ai->ai_family == AF_INET6) {
netaddr6 = (struct sockaddr_in6 *)&netaddr;
shift = 128-(client->server->cidrlen);
i = 3;
while(shift >= 32) {
((netaddr6->sin6_addr).s6_addr32[i])=0;
shift-=32;
i--;
}
(netaddr6->sin6_addr).s6_addr32[i]>>=shift;
(netaddr6->sin6_addr).s6_addr32[i]<<=shift;
getnameinfo((struct sockaddr *)netaddr6, (socklen_t)addrinlen,
netname, sizeof(netname), NULL, 0, NI_NUMERICHOST);
tmp=g_strdup_printf("%s/%s", netname, peername);
}
if(tmp != NULL)
client->exportname=g_strdup_printf(client->server->exportname, tmp);
break;
}
freeaddrinfo(ai);
msg4(LOG_INFO, "connect from %s, assigned file is %s",
peername, client->exportname);
client->clientname=g_strdup(peername);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,772 | int setup_serve(SERVER *serve) {
struct addrinfo hints;
struct addrinfo *ai = NULL;
gchar *port = NULL;
int e;
if(!do_oldstyle) {
return serve->servename ? 1 : 0;
}
memset(&hints,'\0',sizeof(hints));
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_NUMERICSERV;
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = serve->socket_family;
port = g_strdup_printf ("%d", serve->port);
if (port == NULL)
return 0;
e = getaddrinfo(serve->listenaddr,port,&hints,&ai);
g_free(port);
if(e != 0) {
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
serve->socket = -1;
freeaddrinfo(ai);
exit(EXIT_FAILURE);
}
if(serve->socket_family == AF_UNSPEC)
serve->socket_family = ai->ai_family;
#ifdef WITH_SDP
if ((serve->flags) && F_SDP) {
if (ai->ai_family == AF_INET)
ai->ai_family = AF_INET_SDP;
else (ai->ai_family == AF_INET6)
ai->ai_family = AF_INET6_SDP;
}
#endif
if ((serve->socket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) < 0)
err("socket: %m");
dosockopts(serve->socket);
DEBUG("Waiting for connections... bind, ");
e = bind(serve->socket, ai->ai_addr, ai->ai_addrlen);
if (e != 0 && errno != EADDRINUSE)
err("bind: %m");
DEBUG("listen, ");
if (listen(serve->socket, 1) < 0)
err("listen: %m");
freeaddrinfo (ai);
if(serve->servename) {
return 1;
} else {
return 0;
}
}
| Exec Code Overflow | 0 | int setup_serve(SERVER *serve) {
struct addrinfo hints;
struct addrinfo *ai = NULL;
gchar *port = NULL;
int e;
if(!do_oldstyle) {
return serve->servename ? 1 : 0;
}
memset(&hints,'\0',sizeof(hints));
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_NUMERICSERV;
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = serve->socket_family;
port = g_strdup_printf ("%d", serve->port);
if (port == NULL)
return 0;
e = getaddrinfo(serve->listenaddr,port,&hints,&ai);
g_free(port);
if(e != 0) {
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
serve->socket = -1;
freeaddrinfo(ai);
exit(EXIT_FAILURE);
}
if(serve->socket_family == AF_UNSPEC)
serve->socket_family = ai->ai_family;
#ifdef WITH_SDP
if ((serve->flags) && F_SDP) {
if (ai->ai_family == AF_INET)
ai->ai_family = AF_INET_SDP;
else (ai->ai_family == AF_INET6)
ai->ai_family = AF_INET6_SDP;
}
#endif
if ((serve->socket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) < 0)
err("socket: %m");
dosockopts(serve->socket);
DEBUG("Waiting for connections... bind, ");
e = bind(serve->socket, ai->ai_addr, ai->ai_addrlen);
if (e != 0 && errno != EADDRINUSE)
err("bind: %m");
DEBUG("listen, ");
if (listen(serve->socket, 1) < 0)
err("listen: %m");
freeaddrinfo (ai);
if(serve->servename) {
return 1;
} else {
return 0;
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,773 | void sigchld_handler(int s) {
int status;
int* i;
pid_t pid;
while((pid=waitpid(-1, &status, WNOHANG)) > 0) {
if(WIFEXITED(status)) {
msg3(LOG_INFO, "Child exited with %d", WEXITSTATUS(status));
}
i=g_hash_table_lookup(children, &pid);
if(!i) {
msg3(LOG_INFO, "SIGCHLD received for an unknown child with PID %ld", (long)pid);
} else {
DEBUG2("Removing %d from the list of children", pid);
g_hash_table_remove(children, &pid);
}
}
}
| Exec Code Overflow | 0 | void sigchld_handler(int s) {
int status;
int* i;
pid_t pid;
while((pid=waitpid(-1, &status, WNOHANG)) > 0) {
if(WIFEXITED(status)) {
msg3(LOG_INFO, "Child exited with %d", WEXITSTATUS(status));
}
i=g_hash_table_lookup(children, &pid);
if(!i) {
msg3(LOG_INFO, "SIGCHLD received for an unknown child with PID %ld", (long)pid);
} else {
DEBUG2("Removing %d from the list of children", pid);
g_hash_table_remove(children, &pid);
}
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,774 | void sigterm_handler(int s) {
int parent=0;
g_hash_table_foreach(children, killchild, &parent);
if(parent) {
unlink(pidfname);
}
exit(EXIT_SUCCESS);
}
| Exec Code Overflow | 0 | void sigterm_handler(int s) {
int parent=0;
g_hash_table_foreach(children, killchild, &parent);
if(parent) {
unlink(pidfname);
}
exit(EXIT_SUCCESS);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,775 | void usage() {
printf("This is nbd-server version " VERSION "\n");
printf("Usage: [ip:|ip6@]port file_to_export [size][kKmM] [-l authorize_file] [-r] [-m] [-c] [-C configuration file] [-p PID file name] [-o section name] [-M max connections]\n"
"\t-r|--read-only\t\tread only\n"
"\t-m|--multi-file\t\tmultiple file\n"
"\t-c|--copy-on-write\tcopy on write\n"
"\t-C|--config-file\tspecify an alternate configuration file\n"
"\t-l|--authorize-file\tfile with list of hosts that are allowed to\n\t\t\t\tconnect.\n"
"\t-p|--pid-file\t\tspecify a filename to write our PID to\n"
"\t-o|--output-config\toutput a config file section for what you\n\t\t\t\tspecified on the command line, with the\n\t\t\t\tspecified section name\n"
"\t-M|--max-connections\tspecify the maximum number of opened connections\n\n"
"\tif port is set to 0, stdin is used (for running from inetd)\n"
"\tif file_to_export contains '%%s', it is substituted with the IP\n"
"\t\taddress of the machine trying to connect\n"
"\tif ip is set, it contains the local IP address on which we're listening.\n\tif not, the server will listen on all local IP addresses\n");
printf("Using configuration file %s\n", CFILE);
}
| Exec Code Overflow | 0 | void usage() {
printf("This is nbd-server version " VERSION "\n");
printf("Usage: [ip:|ip6@]port file_to_export [size][kKmM] [-l authorize_file] [-r] [-m] [-c] [-C configuration file] [-p PID file name] [-o section name] [-M max connections]\n"
"\t-r|--read-only\t\tread only\n"
"\t-m|--multi-file\t\tmultiple file\n"
"\t-c|--copy-on-write\tcopy on write\n"
"\t-C|--config-file\tspecify an alternate configuration file\n"
"\t-l|--authorize-file\tfile with list of hosts that are allowed to\n\t\t\t\tconnect.\n"
"\t-p|--pid-file\t\tspecify a filename to write our PID to\n"
"\t-o|--output-config\toutput a config file section for what you\n\t\t\t\tspecified on the command line, with the\n\t\t\t\tspecified section name\n"
"\t-M|--max-connections\tspecify the maximum number of opened connections\n\n"
"\tif port is set to 0, stdin is used (for running from inetd)\n"
"\tif file_to_export contains '%%s', it is substituted with the IP\n"
"\t\taddress of the machine trying to connect\n"
"\tif ip is set, it contains the local IP address on which we're listening.\n\tif not, the server will listen on all local IP addresses\n");
printf("Using configuration file %s\n", CFILE);
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,776 | inline void writeit(int f, void *buf, size_t len) {
ssize_t res;
while (len > 0) {
DEBUG("+");
if ((res = write(f, buf, len)) <= 0)
err("Send failed: %m");
len -= res;
buf += res;
}
}
| Exec Code Overflow | 0 | inline void writeit(int f, void *buf, size_t len) {
ssize_t res;
while (len > 0) {
DEBUG("+");
if ((res = write(f, buf, len)) <= 0)
err("Send failed: %m");
len -= res;
buf += res;
}
}
| @@ -150,7 +150,7 @@ gboolean do_oldstyle=FALSE;
#define OFFT_MAX ~((off_t)1<<(sizeof(off_t)*8-1))
#define LINELEN 256 /**< Size of static buffer used to read the
authorization file (yuck) */
-#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define BUFSIZE ((1024*1024)+sizeof(struct nbd_reply)) /**< Size of buffer that can hold requests */
#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
#define F_READONLY 1 /**< flag to tell us a file is readonly */
#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
@@ -1389,7 +1389,7 @@ int mainloop(CLIENT *client) {
if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");
- if (len > BUFSIZE + sizeof(struct nbd_reply))
+ if (len > BUFSIZE - sizeof(struct nbd_reply))
err("Request too big!");
#ifdef DODBG
printf("%s from %llu (%llu) len %d, ", request.type ? "WRITE" : | CWE-119 | null | null |
14,777 | static int expand_ipv6(char *addr, int type)
{
int ret;
struct in6_addr v6_addr;
ret = inet_pton(AF_INET6, addr, &v6_addr);
if (ret != 1) {
if (type == NETMASK)
return 1;
return 0;
}
sprintf(addr, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
"%02x%02x:%02x%02x:%02x%02x",
(int)v6_addr.s6_addr[0], (int)v6_addr.s6_addr[1],
(int)v6_addr.s6_addr[2], (int)v6_addr.s6_addr[3],
(int)v6_addr.s6_addr[4], (int)v6_addr.s6_addr[5],
(int)v6_addr.s6_addr[6], (int)v6_addr.s6_addr[7],
(int)v6_addr.s6_addr[8], (int)v6_addr.s6_addr[9],
(int)v6_addr.s6_addr[10], (int)v6_addr.s6_addr[11],
(int)v6_addr.s6_addr[12], (int)v6_addr.s6_addr[13],
(int)v6_addr.s6_addr[14], (int)v6_addr.s6_addr[15]);
return 1;
}
| DoS | 0 | static int expand_ipv6(char *addr, int type)
{
int ret;
struct in6_addr v6_addr;
ret = inet_pton(AF_INET6, addr, &v6_addr);
if (ret != 1) {
if (type == NETMASK)
return 1;
return 0;
}
sprintf(addr, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
"%02x%02x:%02x%02x:%02x%02x",
(int)v6_addr.s6_addr[0], (int)v6_addr.s6_addr[1],
(int)v6_addr.s6_addr[2], (int)v6_addr.s6_addr[3],
(int)v6_addr.s6_addr[4], (int)v6_addr.s6_addr[5],
(int)v6_addr.s6_addr[6], (int)v6_addr.s6_addr[7],
(int)v6_addr.s6_addr[8], (int)v6_addr.s6_addr[9],
(int)v6_addr.s6_addr[10], (int)v6_addr.s6_addr[11],
(int)v6_addr.s6_addr[12], (int)v6_addr.s6_addr[13],
(int)v6_addr.s6_addr[14], (int)v6_addr.s6_addr[15]);
return 1;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,778 | static unsigned int hweight32(unsigned int *w)
{
unsigned int res = *w - ((*w >> 1) & 0x55555555);
res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
res = (res + (res >> 4)) & 0x0F0F0F0F;
res = res + (res >> 8);
return (res + (res >> 16)) & 0x000000FF;
}
| DoS | 0 | static unsigned int hweight32(unsigned int *w)
{
unsigned int res = *w - ((*w >> 1) & 0x55555555);
res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
res = (res + (res >> 4)) & 0x0F0F0F0F;
res = res + (res >> 8);
return (res + (res >> 16)) & 0x000000FF;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,779 | static int is_ipv4(char *addr)
{
int ret;
struct in_addr ipv4_addr;
ret = inet_pton(AF_INET, addr, &ipv4_addr);
if (ret == 1)
return 1;
return 0;
}
| DoS | 0 | static int is_ipv4(char *addr)
{
int ret;
struct in_addr ipv4_addr;
ret = inet_pton(AF_INET, addr, &ipv4_addr);
if (ret == 1)
return 1;
return 0;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,780 | static void kvp_acquire_lock(int pool)
{
struct flock fl = {F_WRLCK, SEEK_SET, 0, 0, 0};
fl.l_pid = getpid();
if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) {
syslog(LOG_ERR, "Failed to acquire the lock pool: %d", pool);
exit(EXIT_FAILURE);
}
}
| DoS | 0 | static void kvp_acquire_lock(int pool)
{
struct flock fl = {F_WRLCK, SEEK_SET, 0, 0, 0};
fl.l_pid = getpid();
if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) {
syslog(LOG_ERR, "Failed to acquire the lock pool: %d", pool);
exit(EXIT_FAILURE);
}
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,781 | static int kvp_file_init(void)
{
int fd;
FILE *filep;
size_t records_read;
char *fname;
struct kvp_record *record;
struct kvp_record *readp;
int num_blocks;
int i;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
if (access("/var/opt/hyperv", F_OK)) {
if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
exit(EXIT_FAILURE);
}
}
for (i = 0; i < KVP_POOL_COUNT; i++) {
fname = kvp_file_info[i].fname;
records_read = 0;
num_blocks = 1;
sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
if (fd == -1)
return 1;
filep = fopen(fname, "r");
if (!filep)
return 1;
record = malloc(alloc_unit * num_blocks);
if (record == NULL) {
fclose(filep);
return 1;
}
for (;;) {
readp = &record[records_read];
records_read += fread(readp, sizeof(struct kvp_record),
ENTRIES_PER_BLOCK,
filep);
if (ferror(filep)) {
syslog(LOG_ERR, "Failed to read file, pool: %d",
i);
exit(EXIT_FAILURE);
}
if (!feof(filep)) {
/*
* We have more data to read.
*/
num_blocks++;
record = realloc(record, alloc_unit *
num_blocks);
if (record == NULL) {
fclose(filep);
return 1;
}
continue;
}
break;
}
kvp_file_info[i].fd = fd;
kvp_file_info[i].num_blocks = num_blocks;
kvp_file_info[i].records = record;
kvp_file_info[i].num_records = records_read;
fclose(filep);
}
return 0;
}
| DoS | 0 | static int kvp_file_init(void)
{
int fd;
FILE *filep;
size_t records_read;
char *fname;
struct kvp_record *record;
struct kvp_record *readp;
int num_blocks;
int i;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
if (access("/var/opt/hyperv", F_OK)) {
if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) {
syslog(LOG_ERR, " Failed to create /var/opt/hyperv");
exit(EXIT_FAILURE);
}
}
for (i = 0; i < KVP_POOL_COUNT; i++) {
fname = kvp_file_info[i].fname;
records_read = 0;
num_blocks = 1;
sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i);
fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
if (fd == -1)
return 1;
filep = fopen(fname, "r");
if (!filep)
return 1;
record = malloc(alloc_unit * num_blocks);
if (record == NULL) {
fclose(filep);
return 1;
}
for (;;) {
readp = &record[records_read];
records_read += fread(readp, sizeof(struct kvp_record),
ENTRIES_PER_BLOCK,
filep);
if (ferror(filep)) {
syslog(LOG_ERR, "Failed to read file, pool: %d",
i);
exit(EXIT_FAILURE);
}
if (!feof(filep)) {
/*
* We have more data to read.
*/
num_blocks++;
record = realloc(record, alloc_unit *
num_blocks);
if (record == NULL) {
fclose(filep);
return 1;
}
continue;
}
break;
}
kvp_file_info[i].fd = fd;
kvp_file_info[i].num_blocks = num_blocks;
kvp_file_info[i].records = record;
kvp_file_info[i].num_records = records_read;
fclose(filep);
}
return 0;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,782 | kvp_get_domain_name(char *buffer, int length)
{
struct addrinfo hints, *info ;
int error = 0;
gethostname(buffer, length);
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET; /*Get only ipv4 addrinfo. */
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
error = getaddrinfo(buffer, NULL, &hints, &info);
if (error != 0) {
strcpy(buffer, "getaddrinfo failed\n");
return error;
}
strcpy(buffer, info->ai_canonname);
freeaddrinfo(info);
return error;
}
| DoS | 0 | kvp_get_domain_name(char *buffer, int length)
{
struct addrinfo hints, *info ;
int error = 0;
gethostname(buffer, length);
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET; /*Get only ipv4 addrinfo. */
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
error = getaddrinfo(buffer, NULL, &hints, &info);
if (error != 0) {
strcpy(buffer, "getaddrinfo failed\n");
return error;
}
strcpy(buffer, info->ai_canonname);
freeaddrinfo(info);
return error;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,783 | kvp_get_ip_info(int family, char *if_name, int op,
void *out_buffer, int length)
{
struct ifaddrs *ifap;
struct ifaddrs *curp;
int offset = 0;
int sn_offset = 0;
int error = 0;
char *buffer;
struct hv_kvp_ipaddr_value *ip_buffer;
char cidr_mask[5]; /* /xyz */
int weight;
int i;
unsigned int *w;
char *sn_str;
struct sockaddr_in6 *addr6;
if (op == KVP_OP_ENUMERATE) {
buffer = out_buffer;
} else {
ip_buffer = out_buffer;
buffer = (char *)ip_buffer->ip_addr;
ip_buffer->addr_family = 0;
}
/*
* On entry into this function, the buffer is capable of holding the
* maximum key value.
*/
if (getifaddrs(&ifap)) {
strcpy(buffer, "getifaddrs failed\n");
return HV_E_FAIL;
}
curp = ifap;
while (curp != NULL) {
if (curp->ifa_addr == NULL) {
curp = curp->ifa_next;
continue;
}
if ((if_name != NULL) &&
(strncmp(curp->ifa_name, if_name, strlen(if_name)))) {
/*
* We want info about a specific interface;
* just continue.
*/
curp = curp->ifa_next;
continue;
}
/*
* We only support two address families: AF_INET and AF_INET6.
* If a family value of 0 is specified, we collect both
* supported address families; if not we gather info on
* the specified address family.
*/
if ((((family != 0) &&
(curp->ifa_addr->sa_family != family))) ||
(curp->ifa_flags & IFF_LOOPBACK)) {
curp = curp->ifa_next;
continue;
}
if ((curp->ifa_addr->sa_family != AF_INET) &&
(curp->ifa_addr->sa_family != AF_INET6)) {
curp = curp->ifa_next;
continue;
}
if (op == KVP_OP_GET_IP_INFO) {
/*
* Gather info other than the IP address.
* IP address info will be gathered later.
*/
if (curp->ifa_addr->sa_family == AF_INET) {
ip_buffer->addr_family |= ADDR_FAMILY_IPV4;
/*
* Get subnet info.
*/
error = kvp_process_ip_address(
curp->ifa_netmask,
AF_INET,
(char *)
ip_buffer->sub_net,
length,
&sn_offset);
if (error)
goto gather_ipaddr;
} else {
ip_buffer->addr_family |= ADDR_FAMILY_IPV6;
/*
* Get subnet info in CIDR format.
*/
weight = 0;
sn_str = (char *)ip_buffer->sub_net;
addr6 = (struct sockaddr_in6 *)
curp->ifa_netmask;
w = addr6->sin6_addr.s6_addr32;
for (i = 0; i < 4; i++)
weight += hweight32(&w[i]);
sprintf(cidr_mask, "/%d", weight);
if ((length - sn_offset) <
(strlen(cidr_mask) + 1))
goto gather_ipaddr;
if (sn_offset == 0)
strcpy(sn_str, cidr_mask);
else
strcat(sn_str, cidr_mask);
strcat((char *)ip_buffer->sub_net, ";");
sn_offset += strlen(sn_str) + 1;
}
/*
* Collect other ip related configuration info.
*/
kvp_get_ipconfig_info(if_name, ip_buffer);
}
gather_ipaddr:
error = kvp_process_ip_address(curp->ifa_addr,
curp->ifa_addr->sa_family,
buffer,
length, &offset);
if (error)
goto getaddr_done;
curp = curp->ifa_next;
}
getaddr_done:
freeifaddrs(ifap);
return error;
}
| DoS | 0 | kvp_get_ip_info(int family, char *if_name, int op,
void *out_buffer, int length)
{
struct ifaddrs *ifap;
struct ifaddrs *curp;
int offset = 0;
int sn_offset = 0;
int error = 0;
char *buffer;
struct hv_kvp_ipaddr_value *ip_buffer;
char cidr_mask[5]; /* /xyz */
int weight;
int i;
unsigned int *w;
char *sn_str;
struct sockaddr_in6 *addr6;
if (op == KVP_OP_ENUMERATE) {
buffer = out_buffer;
} else {
ip_buffer = out_buffer;
buffer = (char *)ip_buffer->ip_addr;
ip_buffer->addr_family = 0;
}
/*
* On entry into this function, the buffer is capable of holding the
* maximum key value.
*/
if (getifaddrs(&ifap)) {
strcpy(buffer, "getifaddrs failed\n");
return HV_E_FAIL;
}
curp = ifap;
while (curp != NULL) {
if (curp->ifa_addr == NULL) {
curp = curp->ifa_next;
continue;
}
if ((if_name != NULL) &&
(strncmp(curp->ifa_name, if_name, strlen(if_name)))) {
/*
* We want info about a specific interface;
* just continue.
*/
curp = curp->ifa_next;
continue;
}
/*
* We only support two address families: AF_INET and AF_INET6.
* If a family value of 0 is specified, we collect both
* supported address families; if not we gather info on
* the specified address family.
*/
if ((((family != 0) &&
(curp->ifa_addr->sa_family != family))) ||
(curp->ifa_flags & IFF_LOOPBACK)) {
curp = curp->ifa_next;
continue;
}
if ((curp->ifa_addr->sa_family != AF_INET) &&
(curp->ifa_addr->sa_family != AF_INET6)) {
curp = curp->ifa_next;
continue;
}
if (op == KVP_OP_GET_IP_INFO) {
/*
* Gather info other than the IP address.
* IP address info will be gathered later.
*/
if (curp->ifa_addr->sa_family == AF_INET) {
ip_buffer->addr_family |= ADDR_FAMILY_IPV4;
/*
* Get subnet info.
*/
error = kvp_process_ip_address(
curp->ifa_netmask,
AF_INET,
(char *)
ip_buffer->sub_net,
length,
&sn_offset);
if (error)
goto gather_ipaddr;
} else {
ip_buffer->addr_family |= ADDR_FAMILY_IPV6;
/*
* Get subnet info in CIDR format.
*/
weight = 0;
sn_str = (char *)ip_buffer->sub_net;
addr6 = (struct sockaddr_in6 *)
curp->ifa_netmask;
w = addr6->sin6_addr.s6_addr32;
for (i = 0; i < 4; i++)
weight += hweight32(&w[i]);
sprintf(cidr_mask, "/%d", weight);
if ((length - sn_offset) <
(strlen(cidr_mask) + 1))
goto gather_ipaddr;
if (sn_offset == 0)
strcpy(sn_str, cidr_mask);
else
strcat(sn_str, cidr_mask);
strcat((char *)ip_buffer->sub_net, ";");
sn_offset += strlen(sn_str) + 1;
}
/*
* Collect other ip related configuration info.
*/
kvp_get_ipconfig_info(if_name, ip_buffer);
}
gather_ipaddr:
error = kvp_process_ip_address(curp->ifa_addr,
curp->ifa_addr->sa_family,
buffer,
length, &offset);
if (error)
goto getaddr_done;
curp = curp->ifa_next;
}
getaddr_done:
freeifaddrs(ifap);
return error;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,784 | void kvp_get_os_info(void)
{
FILE *file;
char *p, buf[512];
uname(&uts_buf);
os_version = uts_buf.release;
os_build = strdup(uts_buf.release);
os_name = uts_buf.sysname;
processor_arch = uts_buf.machine;
/*
* The current windows host (win7) expects the build
* string to be of the form: x.y.z
* Strip additional information we may have.
*/
p = strchr(os_version, '-');
if (p)
*p = '\0';
/*
* Parse the /etc/os-release file if present:
* http://www.freedesktop.org/software/systemd/man/os-release.html
*/
file = fopen("/etc/os-release", "r");
if (file != NULL) {
while (fgets(buf, sizeof(buf), file)) {
char *value, *q;
/* Ignore comments */
if (buf[0] == '#')
continue;
/* Split into name=value */
p = strchr(buf, '=');
if (!p)
continue;
*p++ = 0;
/* Remove quotes and newline; un-escape */
value = p;
q = p;
while (*p) {
if (*p == '\\') {
++p;
if (!*p)
break;
*q++ = *p++;
} else if (*p == '\'' || *p == '"' ||
*p == '\n') {
++p;
} else {
*q++ = *p++;
}
}
*q = 0;
if (!strcmp(buf, "NAME")) {
p = strdup(value);
if (!p)
break;
os_name = p;
} else if (!strcmp(buf, "VERSION_ID")) {
p = strdup(value);
if (!p)
break;
os_major = p;
}
}
fclose(file);
return;
}
/* Fallback for older RH/SUSE releases */
file = fopen("/etc/SuSE-release", "r");
if (file != NULL)
goto kvp_osinfo_found;
file = fopen("/etc/redhat-release", "r");
if (file != NULL)
goto kvp_osinfo_found;
/*
* We don't have information about the os.
*/
return;
kvp_osinfo_found:
/* up to three lines */
p = fgets(buf, sizeof(buf), file);
if (p) {
p = strchr(buf, '\n');
if (p)
*p = '\0';
p = strdup(buf);
if (!p)
goto done;
os_name = p;
/* second line */
p = fgets(buf, sizeof(buf), file);
if (p) {
p = strchr(buf, '\n');
if (p)
*p = '\0';
p = strdup(buf);
if (!p)
goto done;
os_major = p;
/* third line */
p = fgets(buf, sizeof(buf), file);
if (p) {
p = strchr(buf, '\n');
if (p)
*p = '\0';
p = strdup(buf);
if (p)
os_minor = p;
}
}
}
done:
fclose(file);
return;
}
| DoS | 0 | void kvp_get_os_info(void)
{
FILE *file;
char *p, buf[512];
uname(&uts_buf);
os_version = uts_buf.release;
os_build = strdup(uts_buf.release);
os_name = uts_buf.sysname;
processor_arch = uts_buf.machine;
/*
* The current windows host (win7) expects the build
* string to be of the form: x.y.z
* Strip additional information we may have.
*/
p = strchr(os_version, '-');
if (p)
*p = '\0';
/*
* Parse the /etc/os-release file if present:
* http://www.freedesktop.org/software/systemd/man/os-release.html
*/
file = fopen("/etc/os-release", "r");
if (file != NULL) {
while (fgets(buf, sizeof(buf), file)) {
char *value, *q;
/* Ignore comments */
if (buf[0] == '#')
continue;
/* Split into name=value */
p = strchr(buf, '=');
if (!p)
continue;
*p++ = 0;
/* Remove quotes and newline; un-escape */
value = p;
q = p;
while (*p) {
if (*p == '\\') {
++p;
if (!*p)
break;
*q++ = *p++;
} else if (*p == '\'' || *p == '"' ||
*p == '\n') {
++p;
} else {
*q++ = *p++;
}
}
*q = 0;
if (!strcmp(buf, "NAME")) {
p = strdup(value);
if (!p)
break;
os_name = p;
} else if (!strcmp(buf, "VERSION_ID")) {
p = strdup(value);
if (!p)
break;
os_major = p;
}
}
fclose(file);
return;
}
/* Fallback for older RH/SUSE releases */
file = fopen("/etc/SuSE-release", "r");
if (file != NULL)
goto kvp_osinfo_found;
file = fopen("/etc/redhat-release", "r");
if (file != NULL)
goto kvp_osinfo_found;
/*
* We don't have information about the os.
*/
return;
kvp_osinfo_found:
/* up to three lines */
p = fgets(buf, sizeof(buf), file);
if (p) {
p = strchr(buf, '\n');
if (p)
*p = '\0';
p = strdup(buf);
if (!p)
goto done;
os_name = p;
/* second line */
p = fgets(buf, sizeof(buf), file);
if (p) {
p = strchr(buf, '\n');
if (p)
*p = '\0';
p = strdup(buf);
if (!p)
goto done;
os_major = p;
/* third line */
p = fgets(buf, sizeof(buf), file);
if (p) {
p = strchr(buf, '\n');
if (p)
*p = '\0';
p = strdup(buf);
if (p)
os_minor = p;
}
}
}
done:
fclose(file);
return;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,785 | static char *kvp_if_name_to_mac(char *if_name)
{
FILE *file;
char *p, *x;
char buf[256];
char addr_file[256];
int i;
char *mac_addr = NULL;
snprintf(addr_file, sizeof(addr_file), "%s%s%s", "/sys/class/net/",
if_name, "/address");
file = fopen(addr_file, "r");
if (file == NULL)
return NULL;
p = fgets(buf, sizeof(buf), file);
if (p) {
x = strchr(p, '\n');
if (x)
*x = '\0';
for (i = 0; i < strlen(p); i++)
p[i] = toupper(p[i]);
mac_addr = strdup(p);
}
fclose(file);
return mac_addr;
}
| DoS | 0 | static char *kvp_if_name_to_mac(char *if_name)
{
FILE *file;
char *p, *x;
char buf[256];
char addr_file[256];
int i;
char *mac_addr = NULL;
snprintf(addr_file, sizeof(addr_file), "%s%s%s", "/sys/class/net/",
if_name, "/address");
file = fopen(addr_file, "r");
if (file == NULL)
return NULL;
p = fgets(buf, sizeof(buf), file);
if (p) {
x = strchr(p, '\n');
if (x)
*x = '\0';
for (i = 0; i < strlen(p); i++)
p[i] = toupper(p[i]);
mac_addr = strdup(p);
}
fclose(file);
return mac_addr;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,786 | static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
int value_size)
{
int i;
int num_records;
struct kvp_record *record;
int num_blocks;
if ((key_size > HV_KVP_EXCHANGE_MAX_KEY_SIZE) ||
(value_size > HV_KVP_EXCHANGE_MAX_VALUE_SIZE))
return 1;
/*
* First update the in-memory state.
*/
kvp_update_mem_state(pool);
num_records = kvp_file_info[pool].num_records;
record = kvp_file_info[pool].records;
num_blocks = kvp_file_info[pool].num_blocks;
for (i = 0; i < num_records; i++) {
if (memcmp(key, record[i].key, key_size))
continue;
/*
* Found a match; just update the value -
* this is the modify case.
*/
memcpy(record[i].value, value, value_size);
kvp_update_file(pool);
return 0;
}
/*
* Need to add a new entry;
*/
if (num_records == (ENTRIES_PER_BLOCK * num_blocks)) {
/* Need to allocate a larger array for reg entries. */
record = realloc(record, sizeof(struct kvp_record) *
ENTRIES_PER_BLOCK * (num_blocks + 1));
if (record == NULL)
return 1;
kvp_file_info[pool].num_blocks++;
}
memcpy(record[i].value, value, value_size);
memcpy(record[i].key, key, key_size);
kvp_file_info[pool].records = record;
kvp_file_info[pool].num_records++;
kvp_update_file(pool);
return 0;
}
| DoS | 0 | static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
int value_size)
{
int i;
int num_records;
struct kvp_record *record;
int num_blocks;
if ((key_size > HV_KVP_EXCHANGE_MAX_KEY_SIZE) ||
(value_size > HV_KVP_EXCHANGE_MAX_VALUE_SIZE))
return 1;
/*
* First update the in-memory state.
*/
kvp_update_mem_state(pool);
num_records = kvp_file_info[pool].num_records;
record = kvp_file_info[pool].records;
num_blocks = kvp_file_info[pool].num_blocks;
for (i = 0; i < num_records; i++) {
if (memcmp(key, record[i].key, key_size))
continue;
/*
* Found a match; just update the value -
* this is the modify case.
*/
memcpy(record[i].value, value, value_size);
kvp_update_file(pool);
return 0;
}
/*
* Need to add a new entry;
*/
if (num_records == (ENTRIES_PER_BLOCK * num_blocks)) {
/* Need to allocate a larger array for reg entries. */
record = realloc(record, sizeof(struct kvp_record) *
ENTRIES_PER_BLOCK * (num_blocks + 1));
if (record == NULL)
return 1;
kvp_file_info[pool].num_blocks++;
}
memcpy(record[i].value, value, value_size);
memcpy(record[i].key, key, key_size);
kvp_file_info[pool].records = record;
kvp_file_info[pool].num_records++;
kvp_update_file(pool);
return 0;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,787 | static int kvp_key_delete(int pool, __u8 *key, int key_size)
{
int i;
int j, k;
int num_records;
struct kvp_record *record;
/*
* First update the in-memory state.
*/
kvp_update_mem_state(pool);
num_records = kvp_file_info[pool].num_records;
record = kvp_file_info[pool].records;
for (i = 0; i < num_records; i++) {
if (memcmp(key, record[i].key, key_size))
continue;
/*
* Found a match; just move the remaining
* entries up.
*/
if (i == num_records) {
kvp_file_info[pool].num_records--;
kvp_update_file(pool);
return 0;
}
j = i;
k = j + 1;
for (; k < num_records; k++) {
strcpy(record[j].key, record[k].key);
strcpy(record[j].value, record[k].value);
j++;
}
kvp_file_info[pool].num_records--;
kvp_update_file(pool);
return 0;
}
return 1;
}
| DoS | 0 | static int kvp_key_delete(int pool, __u8 *key, int key_size)
{
int i;
int j, k;
int num_records;
struct kvp_record *record;
/*
* First update the in-memory state.
*/
kvp_update_mem_state(pool);
num_records = kvp_file_info[pool].num_records;
record = kvp_file_info[pool].records;
for (i = 0; i < num_records; i++) {
if (memcmp(key, record[i].key, key_size))
continue;
/*
* Found a match; just move the remaining
* entries up.
*/
if (i == num_records) {
kvp_file_info[pool].num_records--;
kvp_update_file(pool);
return 0;
}
j = i;
k = j + 1;
for (; k < num_records; k++) {
strcpy(record[j].key, record[k].key);
strcpy(record[j].value, record[k].value);
j++;
}
kvp_file_info[pool].num_records--;
kvp_update_file(pool);
return 0;
}
return 1;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,788 | static char *kvp_mac_to_if_name(char *mac)
{
DIR *dir;
struct dirent *entry;
FILE *file;
char *p, *q, *x;
char *if_name = NULL;
char buf[256];
char *kvp_net_dir = "/sys/class/net/";
char dev_id[256];
int i;
dir = opendir(kvp_net_dir);
if (dir == NULL)
return NULL;
snprintf(dev_id, sizeof(dev_id), kvp_net_dir);
q = dev_id + strlen(kvp_net_dir);
while ((entry = readdir(dir)) != NULL) {
/*
* Set the state for the next pass.
*/
*q = '\0';
strcat(dev_id, entry->d_name);
strcat(dev_id, "/address");
file = fopen(dev_id, "r");
if (file == NULL)
continue;
p = fgets(buf, sizeof(buf), file);
if (p) {
x = strchr(p, '\n');
if (x)
*x = '\0';
for (i = 0; i < strlen(p); i++)
p[i] = toupper(p[i]);
if (!strcmp(p, mac)) {
/*
* Found the MAC match; return the interface
* name. The caller will free the memory.
*/
if_name = strdup(entry->d_name);
fclose(file);
break;
}
}
fclose(file);
}
closedir(dir);
return if_name;
}
| DoS | 0 | static char *kvp_mac_to_if_name(char *mac)
{
DIR *dir;
struct dirent *entry;
FILE *file;
char *p, *q, *x;
char *if_name = NULL;
char buf[256];
char *kvp_net_dir = "/sys/class/net/";
char dev_id[256];
int i;
dir = opendir(kvp_net_dir);
if (dir == NULL)
return NULL;
snprintf(dev_id, sizeof(dev_id), kvp_net_dir);
q = dev_id + strlen(kvp_net_dir);
while ((entry = readdir(dir)) != NULL) {
/*
* Set the state for the next pass.
*/
*q = '\0';
strcat(dev_id, entry->d_name);
strcat(dev_id, "/address");
file = fopen(dev_id, "r");
if (file == NULL)
continue;
p = fgets(buf, sizeof(buf), file);
if (p) {
x = strchr(p, '\n');
if (x)
*x = '\0';
for (i = 0; i < strlen(p); i++)
p[i] = toupper(p[i]);
if (!strcmp(p, mac)) {
/*
* Found the MAC match; return the interface
* name. The caller will free the memory.
*/
if_name = strdup(entry->d_name);
fclose(file);
break;
}
}
fclose(file);
}
closedir(dir);
return if_name;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,789 | static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
__u8 *value, int value_size)
{
struct kvp_record *record;
/*
* First update our in-memory database.
*/
kvp_update_mem_state(pool);
record = kvp_file_info[pool].records;
if (index >= kvp_file_info[pool].num_records) {
return 1;
}
memcpy(key, record[index].key, key_size);
memcpy(value, record[index].value, value_size);
return 0;
}
| DoS | 0 | static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size,
__u8 *value, int value_size)
{
struct kvp_record *record;
/*
* First update our in-memory database.
*/
kvp_update_mem_state(pool);
record = kvp_file_info[pool].records;
if (index >= kvp_file_info[pool].num_records) {
return 1;
}
memcpy(key, record[index].key, key_size);
memcpy(value, record[index].value, value_size);
return 0;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,790 | static void kvp_process_ipconfig_file(char *cmd,
char *config_buf, int len,
int element_size, int offset)
{
char buf[256];
char *p;
char *x;
FILE *file;
/*
* First execute the command.
*/
file = popen(cmd, "r");
if (file == NULL)
return;
if (offset == 0)
memset(config_buf, 0, len);
while ((p = fgets(buf, sizeof(buf), file)) != NULL) {
if ((len - strlen(config_buf)) < (element_size + 1))
break;
x = strchr(p, '\n');
*x = '\0';
strcat(config_buf, p);
strcat(config_buf, ";");
}
pclose(file);
}
| DoS | 0 | static void kvp_process_ipconfig_file(char *cmd,
char *config_buf, int len,
int element_size, int offset)
{
char buf[256];
char *p;
char *x;
FILE *file;
/*
* First execute the command.
*/
file = popen(cmd, "r");
if (file == NULL)
return;
if (offset == 0)
memset(config_buf, 0, len);
while ((p = fgets(buf, sizeof(buf), file)) != NULL) {
if ((len - strlen(config_buf)) < (element_size + 1))
break;
x = strchr(p, '\n');
*x = '\0';
strcat(config_buf, p);
strcat(config_buf, ";");
}
pclose(file);
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,791 | static void kvp_release_lock(int pool)
{
struct flock fl = {F_UNLCK, SEEK_SET, 0, 0, 0};
fl.l_pid = getpid();
if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) {
perror("fcntl");
syslog(LOG_ERR, "Failed to release the lock pool: %d", pool);
exit(EXIT_FAILURE);
}
}
| DoS | 0 | static void kvp_release_lock(int pool)
{
struct flock fl = {F_UNLCK, SEEK_SET, 0, 0, 0};
fl.l_pid = getpid();
if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) {
perror("fcntl");
syslog(LOG_ERR, "Failed to release the lock pool: %d", pool);
exit(EXIT_FAILURE);
}
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,792 | static void kvp_update_file(int pool)
{
FILE *filep;
size_t bytes_written;
/*
* We are going to write our in-memory registry out to
* disk; acquire the lock first.
*/
kvp_acquire_lock(pool);
filep = fopen(kvp_file_info[pool].fname, "w");
if (!filep) {
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
exit(EXIT_FAILURE);
}
bytes_written = fwrite(kvp_file_info[pool].records,
sizeof(struct kvp_record),
kvp_file_info[pool].num_records, filep);
if (ferror(filep) || fclose(filep)) {
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to write file, pool: %d", pool);
exit(EXIT_FAILURE);
}
kvp_release_lock(pool);
}
| DoS | 0 | static void kvp_update_file(int pool)
{
FILE *filep;
size_t bytes_written;
/*
* We are going to write our in-memory registry out to
* disk; acquire the lock first.
*/
kvp_acquire_lock(pool);
filep = fopen(kvp_file_info[pool].fname, "w");
if (!filep) {
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
exit(EXIT_FAILURE);
}
bytes_written = fwrite(kvp_file_info[pool].records,
sizeof(struct kvp_record),
kvp_file_info[pool].num_records, filep);
if (ferror(filep) || fclose(filep)) {
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to write file, pool: %d", pool);
exit(EXIT_FAILURE);
}
kvp_release_lock(pool);
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,793 | static void kvp_update_mem_state(int pool)
{
FILE *filep;
size_t records_read = 0;
struct kvp_record *record = kvp_file_info[pool].records;
struct kvp_record *readp;
int num_blocks = kvp_file_info[pool].num_blocks;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
kvp_acquire_lock(pool);
filep = fopen(kvp_file_info[pool].fname, "r");
if (!filep) {
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
exit(EXIT_FAILURE);
}
for (;;) {
readp = &record[records_read];
records_read += fread(readp, sizeof(struct kvp_record),
ENTRIES_PER_BLOCK * num_blocks,
filep);
if (ferror(filep)) {
syslog(LOG_ERR, "Failed to read file, pool: %d", pool);
exit(EXIT_FAILURE);
}
if (!feof(filep)) {
/*
* We have more data to read.
*/
num_blocks++;
record = realloc(record, alloc_unit * num_blocks);
if (record == NULL) {
syslog(LOG_ERR, "malloc failed");
exit(EXIT_FAILURE);
}
continue;
}
break;
}
kvp_file_info[pool].num_blocks = num_blocks;
kvp_file_info[pool].records = record;
kvp_file_info[pool].num_records = records_read;
fclose(filep);
kvp_release_lock(pool);
}
| DoS | 0 | static void kvp_update_mem_state(int pool)
{
FILE *filep;
size_t records_read = 0;
struct kvp_record *record = kvp_file_info[pool].records;
struct kvp_record *readp;
int num_blocks = kvp_file_info[pool].num_blocks;
int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
kvp_acquire_lock(pool);
filep = fopen(kvp_file_info[pool].fname, "r");
if (!filep) {
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
exit(EXIT_FAILURE);
}
for (;;) {
readp = &record[records_read];
records_read += fread(readp, sizeof(struct kvp_record),
ENTRIES_PER_BLOCK * num_blocks,
filep);
if (ferror(filep)) {
syslog(LOG_ERR, "Failed to read file, pool: %d", pool);
exit(EXIT_FAILURE);
}
if (!feof(filep)) {
/*
* We have more data to read.
*/
num_blocks++;
record = realloc(record, alloc_unit * num_blocks);
if (record == NULL) {
syslog(LOG_ERR, "malloc failed");
exit(EXIT_FAILURE);
}
continue;
}
break;
}
kvp_file_info[pool].num_blocks = num_blocks;
kvp_file_info[pool].records = record;
kvp_file_info[pool].num_records = records_read;
fclose(filep);
kvp_release_lock(pool);
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,794 | static int kvp_write_file(FILE *f, char *s1, char *s2, char *s3)
{
int ret;
ret = fprintf(f, "%s%s%s%s\n", s1, s2, "=", s3);
if (ret < 0)
return HV_E_FAIL;
return 0;
}
| DoS | 0 | static int kvp_write_file(FILE *f, char *s1, char *s2, char *s3)
{
int ret;
ret = fprintf(f, "%s%s%s%s\n", s1, s2, "=", s3);
if (ret < 0)
return HV_E_FAIL;
return 0;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,795 | netlink_send(int fd, struct cn_msg *msg)
{
struct nlmsghdr *nlh;
unsigned int size;
struct msghdr message;
char buffer[64];
struct iovec iov[2];
size = NLMSG_SPACE(sizeof(struct cn_msg) + msg->len);
nlh = (struct nlmsghdr *)buffer;
nlh->nlmsg_seq = 0;
nlh->nlmsg_pid = getpid();
nlh->nlmsg_type = NLMSG_DONE;
nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh));
nlh->nlmsg_flags = 0;
iov[0].iov_base = nlh;
iov[0].iov_len = sizeof(*nlh);
iov[1].iov_base = msg;
iov[1].iov_len = size;
memset(&message, 0, sizeof(message));
message.msg_name = &addr;
message.msg_namelen = sizeof(addr);
message.msg_iov = iov;
message.msg_iovlen = 2;
return sendmsg(fd, &message, 0);
}
| DoS | 0 | netlink_send(int fd, struct cn_msg *msg)
{
struct nlmsghdr *nlh;
unsigned int size;
struct msghdr message;
char buffer[64];
struct iovec iov[2];
size = NLMSG_SPACE(sizeof(struct cn_msg) + msg->len);
nlh = (struct nlmsghdr *)buffer;
nlh->nlmsg_seq = 0;
nlh->nlmsg_pid = getpid();
nlh->nlmsg_type = NLMSG_DONE;
nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh));
nlh->nlmsg_flags = 0;
iov[0].iov_base = nlh;
iov[0].iov_len = sizeof(*nlh);
iov[1].iov_base = msg;
iov[1].iov_len = size;
memset(&message, 0, sizeof(message));
message.msg_name = &addr;
message.msg_namelen = sizeof(addr);
message.msg_iov = iov;
message.msg_iovlen = 2;
return sendmsg(fd, &message, 0);
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,796 | static int process_ip_string(FILE *f, char *ip_string, int type)
{
int error = 0;
char addr[INET6_ADDRSTRLEN];
int i = 0;
int j = 0;
char str[256];
char sub_str[10];
int offset = 0;
memset(addr, 0, sizeof(addr));
while (parse_ip_val_buffer(ip_string, &offset, addr,
(MAX_IP_ADDR_SIZE * 2))) {
sub_str[0] = 0;
if (is_ipv4(addr)) {
switch (type) {
case IPADDR:
snprintf(str, sizeof(str), "%s", "IPADDR");
break;
case NETMASK:
snprintf(str, sizeof(str), "%s", "NETMASK");
break;
case GATEWAY:
snprintf(str, sizeof(str), "%s", "GATEWAY");
break;
case DNS:
snprintf(str, sizeof(str), "%s", "DNS");
break;
}
if (i != 0) {
if (type != DNS) {
snprintf(sub_str, sizeof(sub_str),
"_%d", i++);
} else {
snprintf(sub_str, sizeof(sub_str),
"%d", ++i);
}
} else if (type == DNS) {
snprintf(sub_str, sizeof(sub_str), "%d", ++i);
}
} else if (expand_ipv6(addr, type)) {
switch (type) {
case IPADDR:
snprintf(str, sizeof(str), "%s", "IPV6ADDR");
break;
case NETMASK:
snprintf(str, sizeof(str), "%s", "IPV6NETMASK");
break;
case GATEWAY:
snprintf(str, sizeof(str), "%s",
"IPV6_DEFAULTGW");
break;
case DNS:
snprintf(str, sizeof(str), "%s", "DNS");
break;
}
if ((j != 0) || (type == DNS)) {
if (type != DNS) {
snprintf(sub_str, sizeof(sub_str),
"_%d", j++);
} else {
snprintf(sub_str, sizeof(sub_str),
"%d", ++i);
}
} else if (type == DNS) {
snprintf(sub_str, sizeof(sub_str),
"%d", ++i);
}
} else {
return HV_INVALIDARG;
}
error = kvp_write_file(f, str, sub_str, addr);
if (error)
return error;
memset(addr, 0, sizeof(addr));
}
return 0;
}
| DoS | 0 | static int process_ip_string(FILE *f, char *ip_string, int type)
{
int error = 0;
char addr[INET6_ADDRSTRLEN];
int i = 0;
int j = 0;
char str[256];
char sub_str[10];
int offset = 0;
memset(addr, 0, sizeof(addr));
while (parse_ip_val_buffer(ip_string, &offset, addr,
(MAX_IP_ADDR_SIZE * 2))) {
sub_str[0] = 0;
if (is_ipv4(addr)) {
switch (type) {
case IPADDR:
snprintf(str, sizeof(str), "%s", "IPADDR");
break;
case NETMASK:
snprintf(str, sizeof(str), "%s", "NETMASK");
break;
case GATEWAY:
snprintf(str, sizeof(str), "%s", "GATEWAY");
break;
case DNS:
snprintf(str, sizeof(str), "%s", "DNS");
break;
}
if (i != 0) {
if (type != DNS) {
snprintf(sub_str, sizeof(sub_str),
"_%d", i++);
} else {
snprintf(sub_str, sizeof(sub_str),
"%d", ++i);
}
} else if (type == DNS) {
snprintf(sub_str, sizeof(sub_str), "%d", ++i);
}
} else if (expand_ipv6(addr, type)) {
switch (type) {
case IPADDR:
snprintf(str, sizeof(str), "%s", "IPV6ADDR");
break;
case NETMASK:
snprintf(str, sizeof(str), "%s", "IPV6NETMASK");
break;
case GATEWAY:
snprintf(str, sizeof(str), "%s",
"IPV6_DEFAULTGW");
break;
case DNS:
snprintf(str, sizeof(str), "%s", "DNS");
break;
}
if ((j != 0) || (type == DNS)) {
if (type != DNS) {
snprintf(sub_str, sizeof(sub_str),
"_%d", j++);
} else {
snprintf(sub_str, sizeof(sub_str),
"%d", ++i);
}
} else if (type == DNS) {
snprintf(sub_str, sizeof(sub_str),
"%d", ++i);
}
} else {
return HV_INVALIDARG;
}
error = kvp_write_file(f, str, sub_str, addr);
if (error)
return error;
memset(addr, 0, sizeof(addr));
}
return 0;
}
| @@ -1486,13 +1486,19 @@ int main(void)
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
- if (len < 0 || addr.nl_pid) {
+ if (len < 0) {
syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
addr.nl_pid, errno, strerror(errno));
close(fd);
return -1;
}
+ if (addr.nl_pid) {
+ syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
+ addr.nl_pid);
+ continue;
+ }
+
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; | null | null | null |
14,797 | int __ref __add_pages(int nid, struct zone *zone, unsigned long phys_start_pfn,
unsigned long nr_pages)
{
unsigned long i;
int err = 0;
int start_sec, end_sec;
/* during initialize mem_map, align hot-added range to section */
start_sec = pfn_to_section_nr(phys_start_pfn);
end_sec = pfn_to_section_nr(phys_start_pfn + nr_pages - 1);
for (i = start_sec; i <= end_sec; i++) {
err = __add_section(nid, zone, i << PFN_SECTION_SHIFT);
/*
* EEXIST is finally dealt with by ioresource collision
* check. see add_memory() => register_memory_resource()
* Warning will be printed if there is collision.
*/
if (err && (err != -EEXIST))
break;
err = 0;
}
return err;
}
| DoS | 0 | int __ref __add_pages(int nid, struct zone *zone, unsigned long phys_start_pfn,
unsigned long nr_pages)
{
unsigned long i;
int err = 0;
int start_sec, end_sec;
/* during initialize mem_map, align hot-added range to section */
start_sec = pfn_to_section_nr(phys_start_pfn);
end_sec = pfn_to_section_nr(phys_start_pfn + nr_pages - 1);
for (i = start_sec; i <= end_sec; i++) {
err = __add_section(nid, zone, i << PFN_SECTION_SHIFT);
/*
* EEXIST is finally dealt with by ioresource collision
* check. see add_memory() => register_memory_resource()
* Warning will be printed if there is collision.
*/
if (err && (err != -EEXIST))
break;
err = 0;
}
return err;
}
| @@ -512,19 +512,20 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages)
zone->present_pages += onlined_pages;
zone->zone_pgdat->node_present_pages += onlined_pages;
- if (need_zonelists_rebuild)
- build_all_zonelists(NULL, zone);
- else
- zone_pcp_update(zone);
+ if (onlined_pages) {
+ node_set_state(zone_to_nid(zone), N_HIGH_MEMORY);
+ if (need_zonelists_rebuild)
+ build_all_zonelists(NULL, zone);
+ else
+ zone_pcp_update(zone);
+ }
mutex_unlock(&zonelists_mutex);
init_per_zone_wmark_min();
- if (onlined_pages) {
+ if (onlined_pages)
kswapd_run(zone_to_nid(zone));
- node_set_state(zone_to_nid(zone), N_HIGH_MEMORY);
- }
vm_total_pages = nr_free_pagecache_pages();
| null | null | null |
14,798 | static int __meminit __add_section(int nid, struct zone *zone,
unsigned long phys_start_pfn)
{
int nr_pages = PAGES_PER_SECTION;
int ret;
if (pfn_valid(phys_start_pfn))
return -EEXIST;
ret = sparse_add_one_section(zone, phys_start_pfn, nr_pages);
if (ret < 0)
return ret;
ret = __add_zone(zone, phys_start_pfn);
if (ret < 0)
return ret;
return register_new_memory(nid, __pfn_to_section(phys_start_pfn));
}
| DoS | 0 | static int __meminit __add_section(int nid, struct zone *zone,
unsigned long phys_start_pfn)
{
int nr_pages = PAGES_PER_SECTION;
int ret;
if (pfn_valid(phys_start_pfn))
return -EEXIST;
ret = sparse_add_one_section(zone, phys_start_pfn, nr_pages);
if (ret < 0)
return ret;
ret = __add_zone(zone, phys_start_pfn);
if (ret < 0)
return ret;
return register_new_memory(nid, __pfn_to_section(phys_start_pfn));
}
| @@ -512,19 +512,20 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages)
zone->present_pages += onlined_pages;
zone->zone_pgdat->node_present_pages += onlined_pages;
- if (need_zonelists_rebuild)
- build_all_zonelists(NULL, zone);
- else
- zone_pcp_update(zone);
+ if (onlined_pages) {
+ node_set_state(zone_to_nid(zone), N_HIGH_MEMORY);
+ if (need_zonelists_rebuild)
+ build_all_zonelists(NULL, zone);
+ else
+ zone_pcp_update(zone);
+ }
mutex_unlock(&zonelists_mutex);
init_per_zone_wmark_min();
- if (onlined_pages) {
+ if (onlined_pages)
kswapd_run(zone_to_nid(zone));
- node_set_state(zone_to_nid(zone), N_HIGH_MEMORY);
- }
vm_total_pages = nr_free_pagecache_pages();
| null | null | null |
14,799 | static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
{
struct pglist_data *pgdat = zone->zone_pgdat;
int nr_pages = PAGES_PER_SECTION;
int nid = pgdat->node_id;
int zone_type;
unsigned long flags;
zone_type = zone - pgdat->node_zones;
if (!zone->wait_table) {
int ret;
ret = init_currently_empty_zone(zone, phys_start_pfn,
nr_pages, MEMMAP_HOTPLUG);
if (ret)
return ret;
}
pgdat_resize_lock(zone->zone_pgdat, &flags);
grow_zone_span(zone, phys_start_pfn, phys_start_pfn + nr_pages);
grow_pgdat_span(zone->zone_pgdat, phys_start_pfn,
phys_start_pfn + nr_pages);
pgdat_resize_unlock(zone->zone_pgdat, &flags);
memmap_init_zone(nr_pages, nid, zone_type,
phys_start_pfn, MEMMAP_HOTPLUG);
return 0;
}
| DoS | 0 | static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
{
struct pglist_data *pgdat = zone->zone_pgdat;
int nr_pages = PAGES_PER_SECTION;
int nid = pgdat->node_id;
int zone_type;
unsigned long flags;
zone_type = zone - pgdat->node_zones;
if (!zone->wait_table) {
int ret;
ret = init_currently_empty_zone(zone, phys_start_pfn,
nr_pages, MEMMAP_HOTPLUG);
if (ret)
return ret;
}
pgdat_resize_lock(zone->zone_pgdat, &flags);
grow_zone_span(zone, phys_start_pfn, phys_start_pfn + nr_pages);
grow_pgdat_span(zone->zone_pgdat, phys_start_pfn,
phys_start_pfn + nr_pages);
pgdat_resize_unlock(zone->zone_pgdat, &flags);
memmap_init_zone(nr_pages, nid, zone_type,
phys_start_pfn, MEMMAP_HOTPLUG);
return 0;
}
| @@ -512,19 +512,20 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages)
zone->present_pages += onlined_pages;
zone->zone_pgdat->node_present_pages += onlined_pages;
- if (need_zonelists_rebuild)
- build_all_zonelists(NULL, zone);
- else
- zone_pcp_update(zone);
+ if (onlined_pages) {
+ node_set_state(zone_to_nid(zone), N_HIGH_MEMORY);
+ if (need_zonelists_rebuild)
+ build_all_zonelists(NULL, zone);
+ else
+ zone_pcp_update(zone);
+ }
mutex_unlock(&zonelists_mutex);
init_per_zone_wmark_min();
- if (onlined_pages) {
+ if (onlined_pages)
kswapd_run(zone_to_nid(zone));
- node_set_state(zone_to_nid(zone), N_HIGH_MEMORY);
- }
vm_total_pages = nr_free_pagecache_pages();
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.