From c78fd7aa1569a694d062853b366350624e53019b Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens <hauke@hauke-m.de> Date: Thu, 22 Aug 2019 13:55:09 +0200 Subject: [PATCH] BLE: FileTrans: Null terminate the original buffer. We get a pointer to our own buffer back and we made it 1 byte longer, so we can simply null terminate the buffer. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> --- epicardium/ble/filetransfer.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/epicardium/ble/filetransfer.c b/epicardium/ble/filetransfer.c index 5c88fef7d..20facb8b7 100644 --- a/epicardium/ble/filetransfer.c +++ b/epicardium/ble/filetransfer.c @@ -257,21 +257,12 @@ static int bleFileCreateOrOpen(char *filepath) static uint8_t bleFileOpen(dmConnId_t connId, uint8_t *pValue, uint16_t len) { - char filepath[100]; - - if (len > sizeof(filepath)) { - sendCrcResponse(connId, 'e', 0, NULL, "path too long"); - return ATT_ERR_RESOURCES; - } - - /* Copy only file path and not type, make sure this is NULL terminated */ - strncpy(filepath, (char *)pValue + 1, len - 1); - filepath[len - 1] = 0; + pValue[len] = 0; if (file_fd != -1) epic_file_close(file_fd); - file_fd = bleFileCreateOrOpen(filepath); + file_fd = bleFileCreateOrOpen((char *)pValue); if (file_fd < 0) { sendCrcResponse(connId, 'e', 0, NULL, "open failed"); return ATT_ERR_RESOURCES; -- GitLab