summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2013-09-06 05:28:38 +0000
committerTarmac <>2013-09-06 05:28:38 +0000
commit024ce2ffac13b48ec2d65ecac991746653f441c2 (patch)
tree48fbfaa58613a56d1a0cb775fe78f3643d4de946
parent853de71b445360cb7d5207d7dee154d1997f9e44 (diff)
parent9a4a67c517fff809bfedaab610cb5438c5c1a825 (diff)
downloadlightdm-024ce2ffac13b48ec2d65ecac991746653f441c2.tar.gz
Fix a bunch of small errors picked up by Coverity.
Approved by PS Jenkins bot, Robert Ancell.
-rw-r--r--src/process.c5
-rw-r--r--tests/src/X.c15
-rw-r--r--tests/src/libsystem.c11
-rw-r--r--tests/src/test-session.c5
-rw-r--r--tests/src/x-server.c8
-rw-r--r--utils/dm-tool.c2
-rw-r--r--utils/lightdm-set-defaults.c10
7 files changed, 26 insertions, 30 deletions
diff --git a/src/process.c b/src/process.c
index 819d879a..073cf866 100644
--- a/src/process.c
+++ b/src/process.c
@@ -322,8 +322,9 @@ handle_signal (GIOChannel *source, GIOCondition condition, gpointer data)
pid_t pid;
Process *process;
- if (read (signal_pipe[0], &signo, sizeof (int)) < 0 ||
- read (signal_pipe[0], &pid, sizeof (pid_t)) < 0)
+ errno = 0;
+ if (read (signal_pipe[0], &signo, sizeof (int)) != sizeof (int) ||
+ read (signal_pipe[0], &pid, sizeof (pid_t)) != sizeof (pid_t))
{
g_warning ("Error reading from signal pipe: %s", strerror (errno));
return TRUE;
diff --git a/tests/src/X.c b/tests/src/X.c
index d89650c2..aae852a7 100644
--- a/tests/src/X.c
+++ b/tests/src/X.c
@@ -146,15 +146,8 @@ xdmcp_failed_cb (XDMCPClient *client, XDMCPFailed *message)
static void
client_connected_cb (XServer *server, XClient *client)
{
- gchar *auth_error = NULL;
-
status_notify ("XSERVER-%d ACCEPT-CONNECT", display_number);
-
- if (auth_error)
- x_client_send_failed (client, auth_error);
- else
- x_client_send_success (client);
- g_free (auth_error);
+ x_client_send_success (client);
}
static void
@@ -394,18 +387,18 @@ main (int argc, char **argv)
" and start again.\n", display_number, lock_path);
g_free (lock_path);
lock_path = NULL;
- quit (EXIT_FAILURE);
+ return EXIT_FAILURE;
}
pid_string = g_strdup_printf ("%10ld", (long) getpid ());
if (write (lock_file, pid_string, strlen (pid_string)) < 0)
{
g_warning ("Error writing PID file: %s", strerror (errno));
- quit (EXIT_FAILURE);
+ return EXIT_FAILURE;
}
g_free (pid_string);
if (!x_server_start (xserver))
- quit (EXIT_FAILURE);
+ return EXIT_FAILURE;
/* Enable XDMCP */
if (do_xdmcp)
diff --git a/tests/src/libsystem.c b/tests/src/libsystem.c
index 5cbf203f..6ba9cee0 100644
--- a/tests/src/libsystem.c
+++ b/tests/src/libsystem.c
@@ -329,7 +329,7 @@ stat64 (const char *path, struct stat *buf)
_stat64 = (int (*)(const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "stat64");
new_path = redirect_path (path);
- ret = _stat (new_path, buf);
+ ret = _stat64 (new_path, buf);
g_free (new_path);
return ret;
@@ -1236,8 +1236,12 @@ pam_setcred (pam_handle_t *pamh, int flags)
if (group)
{
groups_length = getgroups (0, NULL);
+ if (groups_length < 0)
+ return PAM_SYSTEM_ERR;
groups = malloc (sizeof (gid_t) * (groups_length + 1));
groups_length = getgroups (groups_length, groups);
+ if (groups_length < 0)
+ return PAM_SYSTEM_ERR;
groups[groups_length] = group->gr_gid;
groups_length++;
setgroups (groups_length, groups);
@@ -1376,7 +1380,6 @@ xcb_connect_to_display_with_auth_info (const char *display, xcb_auth_info_t *aut
{
xcb_connection_t *c;
gchar *socket_path;
- GSocketAddress *address;
GError *error = NULL;
c = malloc (sizeof (xcb_connection_t));
@@ -1401,6 +1404,7 @@ xcb_connect_to_display_with_auth_info (const char *display, xcb_auth_info_t *aut
if (c->error == 0)
{
gchar *d;
+ GSocketAddress *address;
/* Skip the hostname, we'll assume it's localhost */
d = g_strdup_printf (".x%s", strchr (display, ':'));
@@ -1410,6 +1414,7 @@ xcb_connect_to_display_with_auth_info (const char *display, xcb_auth_info_t *aut
address = g_unix_socket_address_new (socket_path);
if (!g_socket_connect (c->socket, address, NULL, &error))
c->error = XCB_CONN_ERROR;
+ g_object_unref (address);
if (error)
g_printerr ("Failed to connect to X socket %s: %s\n", socket_path, error->message);
g_free (socket_path);
@@ -1421,8 +1426,6 @@ xcb_connect_to_display_with_auth_info (const char *display, xcb_auth_info_t *aut
{
}
- g_object_unref (address);
-
return c;
}
diff --git a/tests/src/test-session.c b/tests/src/test-session.c
index 1b2b78cc..f905112d 100644
--- a/tests/src/test-session.c
+++ b/tests/src/test-session.c
@@ -104,6 +104,11 @@ request_cb (const gchar *request)
GString *group_list;
n_groups = getgroups (0, NULL);
+ if (n_groups < 0)
+ {
+ g_printerr ("Failed to get groups: %s", strerror (errno));
+ n_groups = 0;
+ }
groups = malloc (sizeof (gid_t) * n_groups);
n_groups = getgroups (n_groups, groups);
group_list = g_string_new ("");
diff --git a/tests/src/x-server.c b/tests/src/x-server.c
index d3d1f3de..a9ae7f2f 100644
--- a/tests/src/x-server.c
+++ b/tests/src/x-server.c
@@ -54,7 +54,9 @@ x_client_send_failed (XClient *client, const gchar *reason)
gchar *message;
message = g_strdup_printf ("FAILED:%s", reason);
- send (g_io_channel_unix_get_fd (client->priv->channel), message, strlen (message), 0);
+ errno = 0;
+ if (send (g_io_channel_unix_get_fd (client->priv->channel), message, strlen (message), 0) != strlen (message))
+ g_printerr ("Failed to send FAILED: %s\n", strerror (errno));
g_free (message);
}
@@ -64,7 +66,9 @@ x_client_send_success (XClient *client)
gchar *message;
message = g_strdup ("SUCCESS");
- send (g_io_channel_unix_get_fd (client->priv->channel), message, strlen (message), 0);
+ errno = 0;
+ if (send (g_io_channel_unix_get_fd (client->priv->channel), message, strlen (message), 0) != strlen (message))
+ g_printerr ("Failed to send SUCCESS: %s\n", strerror (errno));
g_free (message);
}
diff --git a/utils/dm-tool.c b/utils/dm-tool.c
index 3382da76..fbb89d7b 100644
--- a/utils/dm-tool.c
+++ b/utils/dm-tool.c
@@ -199,7 +199,7 @@ main (int argc, char **argv)
{
gchar *username, *session = "";
- if (n_options > 1)
+ if (n_options > 2)
{
g_printerr ("Usage switch-to-user USERNAME [SESSION]\n");
usage ();
diff --git a/utils/lightdm-set-defaults.c b/utils/lightdm-set-defaults.c
index b4a7d959..75ea17c0 100644
--- a/utils/lightdm-set-defaults.c
+++ b/utils/lightdm-set-defaults.c
@@ -77,16 +77,12 @@ update_boolean(const gboolean new_value,
const gchar *key_name,
GKeyFile *keyfile)
{
- gboolean success = TRUE;
-
if (keep_old)
g_debug ("keep-old mode: keep previous default value");
else {
g_debug ("Update to %d for %s", new_value, key_name);
g_key_file_set_boolean (keyfile, key_group, key_name, new_value);
}
- if (!success)
- return(2);
return(0);
}
@@ -99,8 +95,6 @@ update_string(const gchar *default_value,
const gchar *key_name,
GKeyFile *keyfile)
{
- gboolean success = TRUE;
-
if (!(default_value) || (strlen(default_value) < 1)) {
g_debug ("No existing valid value for %s. Set to %s", key_name, new_value);
g_key_file_set_string (keyfile, key_group, key_name, new_value);
@@ -110,8 +104,6 @@ update_string(const gchar *default_value,
if (g_strcmp0 (default_value, new_value) == 0) {
g_debug ("Remove %s as default value for %s", default_value, key_name);
g_key_file_set_string (keyfile, key_group, key_name, "");
- if (!success)
- return(2);
return(0);
}
g_debug ("Can't remove: %s is not the default value for %s", default_value, key_name);
@@ -127,8 +119,6 @@ update_string(const gchar *default_value,
}
}
}
- if (!success)
- return(2);
return(0);
}