From fdb814979681252a813f6fa8348d6be93a4ee3a9 Mon Sep 17 00:00:00 2001 From: Juha Sointusalo Date: Mon, 23 Nov 2015 21:45:40 +0200 Subject: [PATCH] mgr: replace strncpy with strlcpy strlcpy always null terminates the dest buffer, strncpy doesn't when the buffer is too small --- clientgui/sg_ProjectPanel.cpp | 7 +++---- clientgui/sg_TaskPanel.cpp | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/clientgui/sg_ProjectPanel.cpp b/clientgui/sg_ProjectPanel.cpp index 41a22fc974..602962f532 100644 --- a/clientgui/sg_ProjectPanel.cpp +++ b/clientgui/sg_ProjectPanel.cpp @@ -29,6 +29,7 @@ #include "BOINCBaseWizard.h" #include "WizardAttach.h" #include "sg_ProjectPanel.h" +#include "str_replace.h" #if TESTBIGICONPOPUP #include "test/sah_40.xpm" #include "test/einstein_icon.xpm" @@ -250,8 +251,7 @@ void CSimpleProjectPanel::UpdateInterface() { char* ctrl_url = ((ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(n))->project_url; if (strcmp(m_CurrentSelectedProjectURL, ctrl_url)) { b_needMenuRebuild = true; - strncpy(m_CurrentSelectedProjectURL, ctrl_url, sizeof(m_CurrentSelectedProjectURL)); - m_CurrentSelectedProjectURL[sizeof(m_CurrentSelectedProjectURL)-1] = '\0'; + strlcpy(m_CurrentSelectedProjectURL, ctrl_url, sizeof(m_CurrentSelectedProjectURL)); } PROJECT* project = pDoc->state.lookup_project(ctrl_url); @@ -459,8 +459,7 @@ void CSimpleProjectPanel::UpdateProjectList() { } #endif selData = new ProjectSelectionData; - strncpy(selData->project_url, project->master_url, sizeof(selData->project_url)); - selData->project_url[sizeof(selData->project_url)-1] = '\0'; + strlcpy(selData->project_url, project->master_url, sizeof(selData->project_url)); selData->project_files_downloaded_time = project->project_files_downloaded_time; wxBitmap* projectBM = GetProjectSpecificBitmap(selData->project_url); #if SORTPROJECTLIST diff --git a/clientgui/sg_TaskPanel.cpp b/clientgui/sg_TaskPanel.cpp index fd3878e37e..b6b64e6031 100644 --- a/clientgui/sg_TaskPanel.cpp +++ b/clientgui/sg_TaskPanel.cpp @@ -25,6 +25,7 @@ #include "sg_TaskPanel.h" #include "boinc_api.h" #include "filesys.h" +#include "str_replace.h" #define SORTTASKLIST 1 /* TRUE to sort task selection control alphabetically */ @@ -1012,10 +1013,8 @@ void CSimpleTaskPanel::UpdateTaskSelectionList(bool reskin) { selData = new TaskSelectionData; selData->result = result; - strncpy(selData->result_name, result->name, sizeof(selData->result_name)); - selData->result_name[sizeof(selData->result_name)-1] = '\0'; - strncpy(selData->project_url, result->project_url, sizeof(selData->project_url)); - selData->project_url[sizeof(selData->project_url)-1] = '\0'; + strlcpy(selData->result_name, result->name, sizeof(selData->result_name)); + strlcpy(selData->project_url, result->project_url, sizeof(selData->project_url)); selData->dotColor = -1; FindSlideShowFiles(selData); project = pDoc->state.lookup_project(result->project_url);