summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas <nordominus@users.noreply.github.com>2019-11-19 05:07:06 +0100
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2019-11-19 13:07:06 +0900
commit346781ff633aee48eee5700a0b379d97cf86c935 (patch)
treeb771a62a82ea9c785fac3d320a06272c426ec455 /src
parentb38a8d1631cf7fc8eec6d1e88b60d5db340ee376 (diff)
downloadDLT-daemon-346781ff633aee48eee5700a0b379d97cf86c935.tar.gz
Fix a potential memory leak in file transfer (#126)
* Fix a potential memory leak in file transfer This potential memory leak in dlt-system-filetransfer.c can happen if only a filename is passed to dirname(). In the current implementation of dlt-daemon, this issue cannot happen. But in case of refactoring or different usage there is a chance that it can be triggered. See: https://linux.die.net/man/3/dirname Signed-off-by: Andreas Seidl <andreas.seidl@daimler.com>
Diffstat (limited to 'src')
-rw-r--r--src/system/dlt-system-filetransfer.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/system/dlt-system-filetransfer.c b/src/system/dlt-system-filetransfer.c
index 85aa380..dbc5431 100644
--- a/src/system/dlt-system-filetransfer.c
+++ b/src/system/dlt-system-filetransfer.c
@@ -272,9 +272,13 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
return -1;
}
- char *fdir = strndup(src, PATH_MAX);
- MALLOC_ASSERT(fdir);
- fdir = dirname(fdir);/*dirname overwrites its argument anyway */
+ char *src_copy = strndup(src, PATH_MAX);
+ MALLOC_ASSERT(src_copy);
+
+ /*dirname overwrites its argument anyway, */
+ /*but depending on argument returned address might change */
+ char *fdir = dirname(src_copy);
+
char *dst_tosend;/*file which is going to be sent */
char *rn = unique_name(src);/*new unique filename based on inode */
@@ -308,7 +312,7 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
DLT_STRING(dst_tocompress));
free(rn);
free(dst_tocompress);
- free(fdir);
+ free(src_copy);
return -1;
}
@@ -321,7 +325,7 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
free(rn);
free(dst_tosend);
free(dst_tocompress);
- free(fdir);
+ free(src_copy);
return -1;
}
@@ -349,7 +353,7 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
DLT_STRING(dst_tosend));
free(rn);
free(dst_tosend);
- free(fdir);
+ free(src_copy);
return -1;
}
}
@@ -362,7 +366,7 @@ int send_one(char *src, FiletransferOptions const *opts, int which)
free(rn);
free(dst_tosend);
- free(fdir);
+ free(src_copy);
return 0;
}