Skip to content

Commit

Permalink
[Security] Use 'g_strlcpy' instead of 'strcpy'
Browse files Browse the repository at this point in the history
Fixes Clang static analyzer warnings:

warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
  • Loading branch information
sc0w committed Mar 5, 2019
1 parent fc162df commit 76a5cff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/core/testasyncgetprop.c
Expand Up @@ -37,6 +37,7 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <assert.h> #include <assert.h>
#include <glib.h>


#ifndef TRUE #ifndef TRUE
#define TRUE 1 #define TRUE 1
Expand Down Expand Up @@ -138,7 +139,7 @@ my_strdup (const char *str)
fprintf (stderr, "malloc failed\n"); fprintf (stderr, "malloc failed\n");
exit (1); exit (1);
} }
strcpy (s, str); g_strlcpy (s, str, (strlen (str) + 1));


return s; return s;
} }
Expand Down
6 changes: 3 additions & 3 deletions src/core/xprops.c
Expand Up @@ -821,7 +821,7 @@ class_hint_from_results (GetPropertyResults *results,
return FALSE; return FALSE;
} }


strcpy (class_hint->res_name, (char *)results->prop); g_strlcpy (class_hint->res_name, (char *)results->prop, (len_name + 1));


if (len_name == (int) results->n_items) if (len_name == (int) results->n_items)
len_name--; len_name--;
Expand All @@ -837,7 +837,7 @@ class_hint_from_results (GetPropertyResults *results,
return FALSE; return FALSE;
} }


strcpy (class_hint->res_class, (char *)results->prop + len_name + 1); g_strlcpy (class_hint->res_class, (char *)results->prop + len_name + 1, (len_class + 1));


XFree (results->prop); XFree (results->prop);
results->prop = NULL; results->prop = NULL;
Expand Down Expand Up @@ -1133,7 +1133,7 @@ meta_prop_get_values (MetaDisplay *display,
xmalloc_new_str = ag_Xmalloc (strlen (new_str) + 1); xmalloc_new_str = ag_Xmalloc (strlen (new_str) + 1);
if (xmalloc_new_str != NULL) if (xmalloc_new_str != NULL)
{ {
strcpy (xmalloc_new_str, new_str); g_strlcpy (xmalloc_new_str, new_str, (strlen (new_str) + 1));
meta_XFree (values[i].v.str); meta_XFree (values[i].v.str);
values[i].v.str = xmalloc_new_str; values[i].v.str = xmalloc_new_str;
} }
Expand Down

0 comments on commit 76a5cff

Please sign in to comment.