1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

removed NULL-checks after malloc: they are not necessary, they were not consequently used and objects constructed by 3rd party libs are also unchecked

This commit is contained in:
Falk Werner 2020-03-21 21:22:22 +01:00
parent 220df4ad50
commit 214d6b738d
22 changed files with 101 additions and 168 deletions

View File

@ -11,13 +11,10 @@ struct wf_impl_authenticator * wf_impl_authenticator_create(
void * user_data)
{
struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator));
if (NULL != authenticator)
{
authenticator->type = strdup(type);
authenticator->authenticate = authenticate;
authenticator->user_data = user_data;
authenticator->next = NULL;
}
authenticator->type = strdup(type);
authenticator->authenticate = authenticate;
authenticator->user_data = user_data;
authenticator->next = NULL;
return authenticator;
}

View File

@ -99,14 +99,11 @@ struct wf_impl_filesystem * wf_impl_filesystem_create(
struct wf_mountpoint * mountpoint)
{
struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem));
if (NULL != filesystem)
bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint);
if (!success)
{
bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint);
if (!success)
{
free(filesystem);
filesystem = NULL;
}
free(filesystem);
filesystem = NULL;
}
return filesystem;

View File

@ -20,7 +20,7 @@ static char * wf_impl_fill_buffer(
*status = WF_GOOD;
char * buffer = malloc(count);
if ((NULL != buffer) && (0 < count))
if (0 < count)
{
if (0 == strcmp("identity", format))
{

View File

@ -83,13 +83,10 @@ struct wf_server * wf_impl_server_create(
if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory))
{
server = malloc(sizeof(struct wf_server));
if (NULL != server)
{
wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory);
wf_impl_server_config_clone(config, &server->config);
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = wf_impl_server_context_create(server);
}
wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory);
wf_impl_server_config_clone(config, &server->config);
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = wf_impl_server_context_create(server);
}
return server;

View File

@ -56,10 +56,7 @@ void wf_impl_server_config_clone(
struct wf_server_config * wf_impl_server_config_create(void)
{
struct wf_server_config * config = malloc(sizeof(struct wf_server_config));
if (NULL != config)
{
wf_impl_server_config_init(config);
}
wf_impl_server_config_init(config);
return config;
}

View File

@ -85,14 +85,11 @@ struct wf_server_protocol * wf_impl_server_protocol_create(
void * create_mountpoint_context)
{
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
if (NULL != protocol)
{
struct wf_impl_mountpoint_factory mountpoint_factory;
wf_impl_mountpoint_factory_init(&mountpoint_factory,
create_mountpoint, create_mountpoint_context);
struct wf_impl_mountpoint_factory mountpoint_factory;
wf_impl_mountpoint_factory_init(&mountpoint_factory,
create_mountpoint, create_mountpoint_context);
wf_impl_server_protocol_init(protocol, &mountpoint_factory);
}
wf_impl_server_protocol_init(protocol, &mountpoint_factory);
return protocol;

View File

@ -51,18 +51,15 @@ struct wf_impl_session * wf_impl_session_create(
{
struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session));
if (NULL != session)
{
wf_slist_init(&session->filesystems);
session->wsi = wsi;
session->is_authenticated = false;
session->authenticators = authenticators;
session->server = server;
session->mountpoint_factory = mountpoint_factory;
session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
wf_slist_init(&session->messages);
}
wf_slist_init(&session->filesystems);
session->wsi = wsi;
session->is_authenticated = false;
session->authenticators = authenticators;
session->server = server;
session->mountpoint_factory = mountpoint_factory;
session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
wf_slist_init(&session->messages);
return session;
}

View File

@ -12,13 +12,10 @@ extern struct wf_message * wf_message_create(json_t const * value)
{
char * data = malloc(sizeof(struct wf_message) + LWS_PRE + length);
message = (struct wf_message *) data;
if (NULL != message)
{
message->data = &data[sizeof(struct wf_message) + LWS_PRE];
message->length = length;
message->data = &data[sizeof(struct wf_message) + LWS_PRE];
message->length = length;
json_dumpb(value, message->data, length, JSON_COMPACT);
}
json_dumpb(value, message->data, length, JSON_COMPACT);
}
return message;

View File

@ -16,18 +16,15 @@ char * wf_create_string(char const * format, ...)
if (0 <= needed)
{
result = malloc(needed + 1);
if (NULL != result)
{
va_list args;
va_start(args, format);
int count = vsnprintf(result, needed + 1, format, args);
va_end(args);
va_list args;
va_start(args, format);
int count = vsnprintf(result, needed + 1, format, args);
va_end(args);
if ((count < 0) || (needed < count))
{
free(result);
result = NULL;
}
if ((count < 0) || (needed < count))
{
free(result);
result = NULL;
}
}

View File

@ -30,27 +30,24 @@ struct wfp_client * wfp_impl_client_create(
wf_lwslog_disable();
struct wfp_client * client = malloc(sizeof(struct wfp_client));
if (NULL != client)
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
client->info.port = CONTEXT_PORT_NO_LISTEN;
client->info.protocols = client->protocols;
client->info.uid = -1;
client->info.gid = -1;
if ((NULL != config->cert_path) && (NULL != config->key_path))
{
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
client->info.port = CONTEXT_PORT_NO_LISTEN;
client->info.protocols = client->protocols;
client->info.uid = -1;
client->info.gid = -1;
if ((NULL != config->cert_path) && (NULL != config->key_path))
{
}
client->context = lws_create_context(&client->info);
}
client->context = lws_create_context(&client->info);
return client;
}

View File

@ -6,13 +6,10 @@
struct wfp_client_config * wfp_impl_client_config_create(void)
{
struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config));
if (NULL != config)
{
wfp_impl_provider_init(&config->provider);
config->user_data = NULL;
config->key_path = NULL;
config->cert_path = NULL;
}
wfp_impl_provider_init(&config->provider);
config->user_data = NULL;
config->key_path = NULL;
config->cert_path = NULL;
return config;
}

View File

@ -270,10 +270,7 @@ struct wfp_client_protocol * wfp_impl_client_protocol_create(
struct wfp_client_config const * config)
{
struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol));
if (NULL != protocol)
{
wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data);
}
wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data);
return protocol;
}

View File

@ -4,10 +4,7 @@
struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void)
{
struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer));
if (NULL != buffer)
{
buffer->entries = json_array();
}
buffer->entries = json_array();
return buffer;
}

View File

@ -56,22 +56,15 @@ void wfp_impl_respond_read(
{
size_t const size = wf_base64_encoded_size(length) + 1;
char * buffer = malloc(size);
if (NULL != buffer)
{
wf_base64_encode((uint8_t const *) data, length, buffer, size);
wf_base64_encode((uint8_t const *) data, length, buffer, size);
json_t * result = json_object();
json_object_set_new(result, "data", json_string(buffer));
json_object_set_new(result, "format", json_string("base64"));
json_object_set_new(result, "count", json_integer((int) length));
json_t * result = json_object();
json_object_set_new(result, "data", json_string(buffer));
json_object_set_new(result, "format", json_string("base64"));
json_object_set_new(result, "count", json_integer((int) length));
wfp_impl_respond(request, result);
free(buffer);
}
else
{
wfp_impl_respond_error(request, WF_BAD);
}
wfp_impl_respond(request, result);
free(buffer);
}
else
{

View File

@ -8,12 +8,9 @@ struct wfp_request * wfp_impl_request_create(
int id)
{
struct wfp_request * request = malloc(sizeof(struct wfp_request));
if (NULL != request)
{
request->respond = prototype->respond;
request->user_data = prototype->user_data;
request->id = id;
}
request->respond = prototype->respond;
request->user_data = prototype->user_data;
request->id = id;
return request;
}

View File

@ -8,13 +8,10 @@ struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create(
void * user_data)
{
struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method));
if (NULL != method)
{
method->next = NULL;
method->name = strdup(method_name);
method->invoke = invoke;
method->user_data = user_data;
}
method->next = NULL;
method->name = strdup(method_name);
method->invoke = invoke;
method->user_data = user_data;
return method;
}

View File

@ -16,10 +16,7 @@ wf_jsonrpc_impl_proxy_create(
void * user_data)
{
struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy));
if (NULL != proxy)
{
wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data);
}
wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data);
return proxy;
}

View File

@ -29,12 +29,9 @@ wf_jsonrpc_impl_request_create(
void * user_data)
{
struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request));
if (NULL != request)
{
request->id = id;
request->send = send;
request->user_data = user_data;
}
request->id = id;
request->send = send;
request->user_data = user_data;
return request;
}

View File

@ -24,10 +24,7 @@ struct wf_jsonrpc_server *
wf_jsonrpc_impl_server_create(void)
{
struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server));
if (NULL != server)
{
wf_jsonrpc_impl_server_init(server);
}
wf_jsonrpc_impl_server_init(server);
return server;
}

View File

@ -14,10 +14,7 @@ struct wf_timer_manager *
wf_timer_impl_manager_create(void)
{
struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager));
if (NULL != manager)
{
manager->timers = NULL;
}
manager->timers = NULL;
return manager;
}

View File

@ -45,24 +45,21 @@ wf_path_create(
char const * value)
{
struct wf_path * path = malloc(sizeof(struct wf_path));
if (NULL != path)
path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY);
path->capacity = WF_PATH_DEFAULT_CAPACITY;
path->count = 0;
char const * remainder = value;
char const * pos = strchr(remainder, '/');
while (NULL != pos)
{
path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY);
path->capacity = WF_PATH_DEFAULT_CAPACITY;
path->count = 0;
char const * remainder = value;
char const * pos = strchr(remainder, '/');
while (NULL != pos)
{
wf_path_add(path, remainder, (pos - remainder));
remainder = pos + 1;
pos = strchr(remainder, '/');
}
wf_path_add(path, remainder, strlen(remainder));
wf_path_add(path, remainder, (pos - remainder));
remainder = pos + 1;
pos = strchr(remainder, '/');
}
wf_path_add(path, remainder, strlen(remainder));
return path;
}

View File

@ -332,21 +332,18 @@ wfp_static_filesystem_create(
(void) config;
struct wfp_static_filesystem * filesystem = malloc(sizeof(struct wfp_static_filesystem));
if (NULL != filesystem)
{
filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY);
filesystem->size = 0;
filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY;
filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY);
filesystem->size = 0;
filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY;
wfp_static_filesystem_add_dir(filesystem, 0, "<root>");
wfp_static_filesystem_add_dir(filesystem, 0, "<root>");
wfp_client_config_set_userdata(config, filesystem);
wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup);
wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr);
wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir);
wfp_client_config_set_onopen(config, &wfp_static_filesystem_open);
wfp_client_config_set_onread(config, &wfp_static_filesystem_read);
}
wfp_client_config_set_userdata(config, filesystem);
wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup);
wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr);
wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir);
wfp_client_config_set_onopen(config, &wfp_static_filesystem_open);
wfp_client_config_set_onread(config, &wfp_static_filesystem_read);
return filesystem;
}