This is an automated email from Gerrit.

Antonio Borneo ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/5322

-- gerrit

commit 3886fd4c6efd9c1bf703c7b4b974b80d1a1b3651
Author: Antonio Borneo <[email protected]>
Date:   Thu Oct 17 18:02:38 2019 +0200

    semihosting_fileio: fix null terminated string length for GDB
    
    The semihosting code builds strings as null terminated, then pass
    to the debugger the string pointer and the string length. The
    length is computed through strlen(), thus doesn't include the
    trailing zero character.
    The trailing zero is properly taken in consideration by OpenOCD
    for local file handling, but OpenOCD does not pass it correctly to
    GDB in remote file I/O mode. In fact, as explicitly stated inside
    a comment in GDB source code [1]:
        /* 1. Parameter: Ptr to pathname / length incl. trailing zero.  */
    the length field should include the trailing zero character.
    
    This issue affects the semihosting calls "open", "unlink",
    "rename" and "system".
    
    Fix it by adding a "+1" to the string length.
    
    [1] 
http://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;f=gdb/remote-fileio.c;h=11c141e42c4d#l381
    
    Change-Id: I35461bcb30f734fe2d51f7f0d418e3d04b4af506
    Signed-off-by: Antonio Borneo <[email protected]>
    Fixes: c0e7ccbd87cf ("semihosting: support fileio operation")

diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c
index ce6a791..7390172 100644
--- a/src/target/semihosting_common.c
+++ b/src/target/semihosting_common.c
@@ -710,7 +710,7 @@ int semihosting_common(struct target *target)
                                                        semihosting->hit_fileio 
= true;
                                                        fileio_info->identifier 
= "open";
                                                        fileio_info->param_1 = 
addr;
-                                                       fileio_info->param_2 = 
len;
+                                                       fileio_info->param_2 = 
len + 1;
                                                        fileio_info->param_3 = 
open_modeflags[mode];
                                                        fileio_info->param_4 = 
0644;
                                                }
@@ -881,7 +881,7 @@ int semihosting_common(struct target *target)
                                        semihosting->hit_fileio = true;
                                        fileio_info->identifier = "unlink";
                                        fileio_info->param_1 = addr;
-                                       fileio_info->param_2 = len;
+                                       fileio_info->param_2 = len + 1;
                                } else {
                                        uint8_t *fn = malloc(len+1);
                                        if (!fn) {
@@ -937,9 +937,9 @@ int semihosting_common(struct target *target)
                                        semihosting->hit_fileio = true;
                                        fileio_info->identifier = "rename";
                                        fileio_info->param_1 = addr1;
-                                       fileio_info->param_2 = len1;
+                                       fileio_info->param_2 = len1 + 1;
                                        fileio_info->param_3 = addr2;
-                                       fileio_info->param_4 = len2;
+                                       fileio_info->param_4 = len2 + 1;
                                } else {
                                        uint8_t *fn1 = malloc(len1+1);
                                        uint8_t *fn2 = malloc(len2+1);
@@ -1054,7 +1054,7 @@ int semihosting_common(struct target *target)
                                        semihosting->hit_fileio = true;
                                        fileio_info->identifier = "system";
                                        fileio_info->param_1 = addr;
-                                       fileio_info->param_2 = len;
+                                       fileio_info->param_2 = len + 1;
                                } else {
                                        uint8_t *cmd = malloc(len+1);
                                        if (!cmd) {

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to