diff options
| author | 2009-02-14 19:09:27 +0100 | |
|---|---|---|
| committer | 2009-02-14 19:09:27 +0100 | |
| commit | 8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4 (patch) | |
| tree | 7b79d90ded6e64dfb45ea6c9b742904db6e7f13b /src/xplist.c | |
| parent | 3c458d22fdad10b41d810248c6a8efbe5b23f515 (diff) | |
| download | libplist-8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4.tar.gz libplist-8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4.tar.bz2 | |
Fix Invalid memory read and match g_free with g_malloc.
Diffstat (limited to 'src/xplist.c')
| -rw-r--r-- | src/xplist.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/xplist.c b/src/xplist.c index 525706c..e281b4f 100644 --- a/src/xplist.c +++ b/src/xplist.c | |||
| @@ -59,12 +59,12 @@ static const char *plist_base = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\ | |||
| 59 | * | 59 | * |
| 60 | * @return The formatted string. | 60 | * @return The formatted string. |
| 61 | */ | 61 | */ |
| 62 | static char *format_string(const char *buf, int cols, int depth) | 62 | static gchar *format_string(const char *buf, int cols, int depth) |
| 63 | { | 63 | { |
| 64 | int colw = depth + cols + 1; | 64 | int colw = depth + cols + 1; |
| 65 | int len = strlen(buf); | 65 | int len = strlen(buf); |
| 66 | int nlines = len / cols + 1; | 66 | int nlines = len / cols + 1; |
| 67 | char *new_buf = (char *) malloc(nlines * colw + depth + 1); | 67 | gchar *new_buf = (gchar *) g_malloc0(nlines * colw + depth + 1); |
| 68 | int i = 0; | 68 | int i = 0; |
| 69 | int j = 0; | 69 | int j = 0; |
| 70 | 70 | ||
| @@ -76,7 +76,7 @@ static char *format_string(const char *buf, int cols, int depth) | |||
| 76 | new_buf[i * colw] = '\n'; | 76 | new_buf[i * colw] = '\n'; |
| 77 | for (j = 0; j < depth; j++) | 77 | for (j = 0; j < depth; j++) |
| 78 | new_buf[i * colw + 1 + j] = '\t'; | 78 | new_buf[i * colw + 1 + j] = '\t'; |
| 79 | memcpy(new_buf + i * colw + 1 + depth, buf + i * cols, cols); | 79 | memcpy(new_buf + i * colw + 1 + depth, buf + i * cols, (i + 1) * cols <= len ? cols : len - i * cols); |
| 80 | } | 80 | } |
| 81 | new_buf[len + (1 + depth) * nlines] = '\n'; | 81 | new_buf[len + (1 + depth) * nlines] = '\n'; |
| 82 | 82 | ||
