diff options
| author | 2014-08-20 08:04:17 +0200 | |
|---|---|---|
| committer | 2014-08-20 08:04:17 +0200 | |
| commit | 420eaf54939a55d3805d70f50d213b64ed3c9139 (patch) | |
| tree | 175e679150d3126838012f4aaa92eea93a025532 /src | |
| parent | 5fbd3251e9ab03be952a876f261ca466398c1696 (diff) | |
| download | ideviceinstaller-420eaf54939a55d3805d70f50d213b64ed3c9139.tar.gz ideviceinstaller-420eaf54939a55d3805d70f50d213b64ed3c9139.tar.bz2 | |
Make sure target buffer for readlink is large enough and gets NULL-terminated
Diffstat (limited to 'src')
| -rw-r--r-- | src/ideviceinstaller.c | 10 |
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 | |||
| 542 | 542 | ||
| 543 | #ifdef HAVE_LSTAT | 543 | #ifdef HAVE_LSTAT |
| 544 | if ((lstat(fpath, &st) == 0) && S_ISLNK(st.st_mode)) { | 544 | if ((lstat(fpath, &st) == 0) && S_ISLNK(st.st_mode)) { |
| 545 | char *target = (char *)malloc(st.st_size); | 545 | char *target = (char *)malloc(st.st_size+1); |
| 546 | readlink(fpath, target, st.st_size); | 546 | if (readlink(fpath, target, st.st_size+1) < 0) { |
| 547 | afc_make_link(afc, AFC_SYMLINK, target, fpath); | 547 | fprintf(stderr, "ERROR: readlink: %s (%d)\n", strerror(errno), errno); |
| 548 | } else { | ||
| 549 | target[st.st_size] = '\0'; | ||
| 550 | afc_make_link(afc, AFC_SYMLINK, target, fpath); | ||
| 551 | } | ||
| 548 | free(target); | 552 | free(target); |
| 549 | } else | 553 | } else |
| 550 | #endif | 554 | #endif |
