From 6df7551bddc29d7372a3e4f9828810898cb70b79 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 8 Jun 2015 15:40:06 +0200 Subject: [PATCH] DiscoveryPhase: Fix the unlikely case the server resturns utf-8 in permissions UTF-8 size might be bigger than the size of the QString In that case we would end up with a non-nill terminated permissions. --- src/libsync/discoveryphase.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 38aa83c4c..02d034d7a 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -217,17 +217,18 @@ static csync_vio_file_stat_t* propertyMapToFileStat(QMap map) file_stat->directDownloadCookies = strdup(value.toUtf8()); file_stat->fields |= CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADCOOKIES; } else if (property == "permissions") { + auto v = value.toUtf8(); if (value.isEmpty()) { // special meaning for our code: server returned permissions but are empty // meaning only reading is allowed for this resource file_stat->remotePerm[0] = ' '; // see _csync_detect_update() file_stat->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERM; - } else if (value.length() < int(sizeof(file_stat->remotePerm))) { - strncpy(file_stat->remotePerm, value.toUtf8(), sizeof(file_stat->remotePerm)); + } else if (v.length() < int(sizeof(file_stat->remotePerm))) { + strncpy(file_stat->remotePerm, v.constData(), sizeof(file_stat->remotePerm)); file_stat->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERM; } else { - // old server, keep file_stat->remotePerm empty + qWarning() << "permissions too large" << v; } } }