summaryrefslogtreecommitdiffstats
path: root/src/ideviceinstaller.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2014-08-20 08:04:17 +0200
committerGravatar Nikias Bassen2014-08-20 08:04:17 +0200
commit420eaf54939a55d3805d70f50d213b64ed3c9139 (patch)
tree175e679150d3126838012f4aaa92eea93a025532 /src/ideviceinstaller.c
parent5fbd3251e9ab03be952a876f261ca466398c1696 (diff)
downloadideviceinstaller-420eaf54939a55d3805d70f50d213b64ed3c9139.tar.gz
ideviceinstaller-420eaf54939a55d3805d70f50d213b64ed3c9139.tar.bz2
Make sure target buffer for readlink is large enough and gets NULL-terminated
Diffstat (limited to 'src/ideviceinstaller.c')
-rw-r--r--src/ideviceinstaller.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ideviceinstaller.c b/src/ideviceinstaller.c
index 55f3062..3052577 100644
--- a/src/ideviceinstaller.c
+++ b/src/ideviceinstaller.c
@@ -542,9 +542,13 @@ static void afc_upload_dir(afc_client_t afc, const char* path, const char* afcpa
#ifdef HAVE_LSTAT
if ((lstat(fpath, &st) == 0) && S_ISLNK(st.st_mode)) {
- char *target = (char *)malloc(st.st_size);
- readlink(fpath, target, st.st_size);
- afc_make_link(afc, AFC_SYMLINK, target, fpath);
+ char *target = (char *)malloc(st.st_size+1);
+ if (readlink(fpath, target, st.st_size+1) < 0) {
+ fprintf(stderr, "ERROR: readlink: %s (%d)\n", strerror(errno), errno);
+ } else {
+ target[st.st_size] = '\0';
+ afc_make_link(afc, AFC_SYMLINK, target, fpath);
+ }
free(target);
} else
#endif