Skip to content

Commit af19ed7

Browse files
Fix: Shlemiel the painter needs to paint strncat too
Like wcsncat, the ugly and correct usage is strncat( dest, src, sizeof(dest) - 1 - strlen(dest) );
1 parent 4ded318 commit af19ed7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

platforms/win32/vm/sqWin32Main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ void gatherSystemInfo(void) {
771771
NULL, NULL, (LPBYTE)drivers, &dwSize);
772772
}
773773
if (!ok) {
774-
strncat(tmpString,"\nDriver Versions:",sizeof(tmpString));
774+
strncat(tmpString,"\nDriver Versions:",sizeof(tmpString) - 1 - strlen(tmpString));
775775
/* InstalledDrivers is REG_MULTI_SZ (extra terminating zero) */
776776
for(drv = drivers; drv[0]; drv +=wcslen(drv)) {
777777
DWORD verSize, hh;
@@ -781,9 +781,9 @@ void gatherSystemInfo(void) {
781781

782782
/* Concat driver name */
783783
if (WideCharToMultiByte(CP_UTF8,0,drv,-1,drvA,MAX_PATH_UTF8,NULL,NULL)>0) {
784-
strncat(tmpString, "\n\t", sizeof(tmpString));
785-
strncat(tmpString, drvA , sizeof(tmpString));
786-
strncat(tmpString, ": " , sizeof(tmpString));
784+
strncat(tmpString, "\n\t", sizeof(tmpString) - 1 - strlen(tmpString));
785+
strncat(tmpString, drvA , sizeof(tmpString) - 1 - strlen(tmpString));
786+
strncat(tmpString, ": " , sizeof(tmpString) - 1 - strlen(tmpString));
787787
}
788788

789789
verSize = GetFileVersionInfoSizeW(drv, &hh);
@@ -799,7 +799,7 @@ void gatherSystemInfo(void) {
799799
char *utf8 = (char *)malloc(utf8_len);
800800
if(utf8) {
801801
WideCharToMultiByte(CP_UTF8, 0, vInfo, -1, utf8, utf8_len, NULL, NULL);
802-
strncat(tmpString, utf8,sizeof(tmpString));
802+
strncat(tmpString, utf8,sizeof(tmpString) - 1 - strlen(tmpString));
803803
free(utf8);
804804
goto done;
805805
}
@@ -812,21 +812,21 @@ void gatherSystemInfo(void) {
812812
char *utf8 = (char *)malloc(utf8_len);
813813
if (utf8) {
814814
WideCharToMultiByte(CP_UTF8, 0, vInfo, -1, utf8, utf8_len, NULL, NULL);
815-
strncat(tmpString, utf8, sizeof(tmpString));
815+
strncat(tmpString, utf8, sizeof(tmpString) - 1 - strlen(tmpString));
816816
free(utf8);
817817
goto done;
818818
}
819819
}
820820

821-
strncat(tmpString, "???", sizeof(tmpString));
821+
strncat(tmpString, "???", sizeof(tmpString) - 1 - strlen(tmpString));
822822

823823
done:
824824
if (verInfo) {
825825
free(verInfo);
826826
verInfo = NULL;
827827
}
828828
}
829-
strncat(tmpString,"\n",sizeof(tmpString));
829+
strncat(tmpString,"\n",sizeof(tmpString) - 1 - strlen(tmpString));
830830
}
831831
RegCloseKey(hk);
832832
}

0 commit comments

Comments
 (0)