[geany/geany-plugins] 785b83: debugger: Avoid undefined behavior with strcpy()

Colomban Wendling git-noreply at xxxxx
Sun Nov 15 17:28:16 UTC 2015


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sat, 25 Oct 2014 12:43:49 UTC
Commit:      785b83534469eddd212029862f8ccb69a9c4f724
             https://github.com/geany/geany-plugins/commit/785b83534469eddd212029862f8ccb69a9c4f724

Log Message:
-----------
debugger: Avoid undefined behavior with strcpy()

strcpy() requires that the source and destination strings do not
overlap, so fix the code to avoid this.


Modified Paths:
--------------
    debugger/src/dbm_gdb.c

Modified: debugger/src/dbm_gdb.c
7 lines changed, 3 insertions(+), 4 deletions(-)
===================================================================
@@ -225,14 +225,13 @@ static void gdb_input_write_line(const gchar *line)
 	GIOStatus st;
 	GError *err = NULL;
 	gsize count;
-	
+	const char *p;
 	char command[1000];
 	snprintf(command, sizeof command, "%s\n", line);
 	
-	while (strlen(command))
+	for (p = command; *p; p += count)
 	{
-		st = g_io_channel_write_chars(gdb_ch_in, command, strlen(command), &count, &err);
-		strcpy(command, command + count);
+		st = g_io_channel_write_chars(gdb_ch_in, p, strlen(p), &count, &err);
 		if (err || (st == G_IO_STATUS_ERROR) || (st == G_IO_STATUS_EOF))
 		{
 #ifdef DEBUG_OUTPUT



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list