Skip to content

Commit a3faf64

Browse files
committed
fix potential buffer overflow
1 parent 3fb9e7a commit a3faf64

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

filecase/src/FileCase.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const TCHAR *GetMsg(int MsgId);
3434
void InitDialogItems(const struct InitDialogItem *Init, struct FarDialogItem *Item, int ItemsNumber);
3535
int IsCaseMixed(const TCHAR *Str);
3636
const TCHAR *GetOnlyName(const TCHAR *FullName);
37-
TCHAR *GetFullName(TCHAR *Dest, const TCHAR *Dir, const TCHAR *Name);
37+
TCHAR *GetFullName(size_t DestLen, TCHAR *Dest, const TCHAR *Dir, const TCHAR *Name);
3838
void CaseWord(TCHAR *nm, int Type);
3939
void ProcessName(const TCHAR *OldFullName, DWORD FileAttributes);
4040

filecase/src/FileMix.icpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ const TCHAR *GetOnlyName(const TCHAR *FullName)
6161
return Name;
6262
}
6363

64-
TCHAR *GetFullName(TCHAR *Dest,const TCHAR *Dir,const TCHAR *Name)
64+
TCHAR *GetFullName(size_t DestLen, TCHAR *Dest,const TCHAR *Dir,const TCHAR *Name)
6565
{
66-
lstrcpy(Dest,Dir);
67-
int len=lstrlen(Dest);
66+
lstrcpyn(Dest,Dir,DestLen);
67+
int len = DestLen ? std::min(lstrlen(Dest), DestLen - 1) : 0;
6868
if(len)
6969
{
7070
if(Dest[len-1]==_T('/')) --len;
7171
else Dest[len]=_T('/');
72-
lstrcpy(Dest+len+1,GetOnlyName(Name));
72+
lstrcpyn(Dest+len+1,GetOnlyName(Name),DestLen-len-1);
7373
}
74-
else lstrcpy(Dest, Name);
74+
else lstrcpyn(Dest, Name, DestLen);
7575

7676
return Dest;
7777
}

filecase/src/ProcessName.icpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void ProcessName(const TCHAR *OldFullName, DWORD FileAttributes)
8080
#ifdef UNICODE
8181
ProcessName(Items[I].lpwszFileName,Items[I].dwFileAttributes);
8282
#else
83-
GetFullName(NewFullName,OldFullName,Items[I].FindData.cFileName);
83+
GetFullName(ARRAYSIZE(NewFullName),NewFullName,OldFullName,Items[I].FindData.cFileName);
8484
ProcessName(NewFullName,Items[I].FindData.dwFileAttributes);
8585
#endif
8686
}

filecase/src/filecvt.icpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void CaseConversion()
141141
{
142142
Info.Control(PANEL_ACTIVE,FCTL_GETSELECTEDPANELITEM,I,(LONG_PTR)PPI);
143143
#endif
144-
GetFullName(FullName,CurDir,FileName);
144+
GetFullName(ARRAYSIZE(FullName),FullName,CurDir,FileName);
145145
ProcessName(FullName,FileAttr);
146146
#ifdef UNICODE
147147
free(PPI);

0 commit comments

Comments
 (0)