Skip to content

Commit 76a5cff

Browse files
committed
[Security] Use 'g_strlcpy' instead of 'strcpy'
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
1 parent fc162df commit 76a5cff

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/core/testasyncgetprop.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <errno.h>
3838
#include <signal.h>
3939
#include <assert.h>
40+
#include <glib.h>
4041

4142
#ifndef TRUE
4243
#define TRUE 1
@@ -138,7 +139,7 @@ my_strdup (const char *str)
138139
fprintf (stderr, "malloc failed\n");
139140
exit (1);
140141
}
141-
strcpy (s, str);
142+
g_strlcpy (s, str, (strlen (str) + 1));
142143

143144
return s;
144145
}

src/core/xprops.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ class_hint_from_results (GetPropertyResults *results,
821821
return FALSE;
822822
}
823823

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

826826
if (len_name == (int) results->n_items)
827827
len_name--;
@@ -837,7 +837,7 @@ class_hint_from_results (GetPropertyResults *results,
837837
return FALSE;
838838
}
839839

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

842842
XFree (results->prop);
843843
results->prop = NULL;
@@ -1133,7 +1133,7 @@ meta_prop_get_values (MetaDisplay *display,
11331133
xmalloc_new_str = ag_Xmalloc (strlen (new_str) + 1);
11341134
if (xmalloc_new_str != NULL)
11351135
{
1136-
strcpy (xmalloc_new_str, new_str);
1136+
g_strlcpy (xmalloc_new_str, new_str, (strlen (new_str) + 1));
11371137
meta_XFree (values[i].v.str);
11381138
values[i].v.str = xmalloc_new_str;
11391139
}

0 commit comments

Comments
 (0)