From 21349c19c029f5794c54bc8d50e93364da5c41e4 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Fri, 14 Jun 2013 00:28:14 -0400 Subject: [PATCH] MGR: Use the skin's application short name instead of 'BOINC' for notices from the client. MGR: Remove potential buffer overrun. --- clientgui/NoticeListCtrl.cpp | 56 +++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/clientgui/NoticeListCtrl.cpp b/clientgui/NoticeListCtrl.cpp index a633b421a4..184d5ef0e1 100644 --- a/clientgui/NoticeListCtrl.cpp +++ b/clientgui/NoticeListCtrl.cpp @@ -20,11 +20,18 @@ #endif #include "stdwx.h" +#include "diagnostics.h" +#include "util.h" +#include "mfile.h" +#include "miofile.h" +#include "parse.h" +#include "error_numbers.h" +#include "wizardex.h" +#include "error_numbers.h" +#include "browser.h" #include "Events.h" - -#include "str_replace.h" - #include "BOINCGUIApp.h" +#include "SkinManager.h" #include "MainDocument.h" #include "NoticeListCtrl.h" #include "BOINCInternetFSHandler.h" @@ -478,47 +485,62 @@ void CNoticeListCtrl::OnLinkClicked( wxHtmlLinkEvent& event ) wxString CNoticeListCtrl::OnGetItem(size_t i) const { CMainDocument* pDoc = wxGetApp().GetDocument(); + CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced(); wxString strTitle = wxEmptyString; wxString strDescription = wxEmptyString; wxString strProjectName = wxEmptyString; wxString strURL = wxEmptyString; - wxString create_time = wxEmptyString; + wxString strCreateTime = wxEmptyString; + wxString strCategory = wxEmptyString; wxString strBuffer = wxEmptyString; wxString strTemp = wxEmptyString; wxDateTime dtBuffer; - char buf[1024]; wxASSERT(pDoc); wxASSERT(wxDynamicCast(pDoc, CMainDocument)); + wxASSERT(pSkinAdvanced); + wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced)); if (pDoc->IsConnected()) { NOTICE* np = pDoc->notice((unsigned int)i); + strCategory = wxString(np->category, wxConvUTF8); + + strProjectName = wxString(np->project_name, wxConvUTF8); + strURL = wxString(np->link, wxConvUTF8); - if (!strcmp(np->category, "client")) { - if (strlen(np->project_name)) { - sprintf(buf, "%s: %s", np->project_name, "_(\"Notice from BOINC\")"); + strTitle = wxString(np->title, wxConvUTF8); + + // Fix-up title + if (strCategory == wxT("client")) { + strBuffer.Printf( + wxT("_(\"Notice from %s\")"), + pSkinAdvanced->GetApplicationShortName() + ); + if (strProjectName.size()) { + strTemp.Printf(wxT("%s: %s"), strProjectName.c_str(), strBuffer.c_str()); } else { - safe_strcpy(buf, "_(\"Notice from BOINC\")"); + strTemp.Printf(wxT("%s"), strBuffer.c_str()); } - } else if (!strcmp(np->category, "scheduler")) { - sprintf(buf, "%s: %s", np->project_name, "_(\"Notice from server\")"); + } else if (strCategory == wxT("scheduler")) { + strTemp.Printf(wxT("%s: %s"), strProjectName.c_str(), wxT("_(\"Notice from server\")")); } else { - if (strlen(np->project_name)) { - sprintf(buf, "%s: %s", np->project_name, np->title); + if (strProjectName.size()) { + strTemp.Printf(wxT("%s: %s"), strProjectName.c_str(), strTitle.c_str()); } else { - safe_strcpy(buf, np->title); + strTemp = strTitle; } } - strTitle = wxString(buf, wxConvUTF8); + + strTitle = strTemp; pDoc->LocalizeNoticeText(strTitle, true); strDescription = wxString(np->description.c_str(), wxConvUTF8); pDoc->LocalizeNoticeText(strDescription, true); dtBuffer.Set((time_t)np->create_time); - create_time = dtBuffer.Format(); + strCreateTime = dtBuffer.Format(); strBuffer = wxT("
"); @@ -534,7 +556,7 @@ wxString CNoticeListCtrl::OnGetItem(size_t i) const { strBuffer += wxT("
"); - strBuffer += create_time; + strBuffer += strCreateTime; if (!strURL.IsEmpty()) { strTemp.Printf(