mgr: replace strncpy with strlcpy

strlcpy always null terminates the dest buffer, strncpy doesn't when the
buffer is too small
This commit is contained in:
Juha Sointusalo 2015-11-23 21:45:40 +02:00
parent 80135f9c95
commit fdb8149796
2 changed files with 6 additions and 8 deletions

View File

@ -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

View File

@ -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);