security fix: replaced sprintf with snprintf
[xboard.git] / winboard / wsettings.c
index a250e2e..a5d6ce6 100644 (file)
@@ -1,7 +1,7 @@
 /*\r
  * Engine-settings dialog. The complexity come from an attempt to present the engine-defined options\r
  * in a nicey formatted layout. To this end we first run a back-end pre-formatter, which will distribute\r
- * the controls over two columns (the minimum required, as some are double width). It also takes care of \r
+ * the controls over two columns (the minimum required, as some are double width). It also takes care of\r
  * grouping options that start with the same word (mainly for "Polyglot ..." options). It assigns relative\r
  * suitability to break points between lines, and in the end decides if and where to break up the list\r
  * for display in multiple (2*N) columns.\r
@@ -104,7 +104,7 @@ LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionLis
            nextOption++;\r
        }\r
        // We now must be at the end, or looking at a spin or textbox (in nextType)\r
-       if(!stop) \r
+       if(!stop)\r
            nextType = Button; // kudge to flush remaining checks and combos undistorted\r
        // Take a new line if a spin follows combos or checks, or when we encounter a textbox\r
        if((combos+checks || nextType == TextBox) && layout&1) {\r
@@ -122,7 +122,7 @@ LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionLis
        if(nextType == TextBox && lastType == ComboBox)\r
            checkList[checks++] = comboList[--combos];\r
        // Now append the checks behind the (remaining) combos to treat them as one group\r
-       for(i=0; i< checks; i++) \r
+       for(i=0; i< checks; i++)\r
            comboList[combos++] = checkList[i];\r
        // emit the consecutive checks and combos in two columns\r
        right = combos/2; // rounded down if odd!\r
@@ -189,7 +189,7 @@ DesignOptionDialog(ChessProgramState *cps)
                    if( cps->option[k].name[j] != cps->option[k+groupSize].name[j]) break;\r
                groupNameLength = j;\r
                groupSize++;\r
-               \r
+\r
        }\r
        if(groupSize > 3) {\r
                // We found a group to terminates the current section\r
@@ -203,7 +203,7 @@ DesignOptionDialog(ChessProgramState *cps)
     }\r
     if(n != k) LayoutOptions(n, k, "", cps->option); // flush remaining solitary options\r
     // decide if and where we break into two column pairs\r
-    \r
+\r
     // Emit buttons and add OK and cancel\r
 //    for(k=0; k<buttons; k++) layoutList[layout++] = buttonList[k];\r
     // Create the dialog window\r
@@ -281,10 +281,10 @@ SetOptionValues(HWND hDlg, ChessProgramState *cps)
     }\r
     SetDlgItemText( hDlg, IDOK, _("OK") );\r
     SetDlgItemText( hDlg, IDCANCEL, _("Cancel") );\r
-    sprintf(title, _("%s Engine Settings (%s)"), T_(cps->which), cps->tidy); \r
+    snprintf(title, MSG_SIZ, _("%s Engine Settings (%s)"), T_(cps->which), cps->tidy);\r
     title[0] &= ~32; // capitalize\r
     SetWindowText( hDlg, title);\r
-    for(i=0; i<groups; i+=2) { \r
+    for(i=0; i<groups; i+=2) {\r
        int id, p; char buf[MSG_SIZ];\r
        id = k = boxList[i];\r
        if(layoutList[k] < 0) k++;\r
@@ -346,8 +346,10 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps)
            default:\r
                break; // are treated instantly, so they have been sent already\r
        }\r
-       if(changed == 2) sprintf(buf, "option %s=%d\n", cps->option[j].name, new); else\r
-       if(changed == 1) sprintf(buf, "option %s=%s\n", cps->option[j].name, newText);\r
+       if(changed == 2)\r
+         snprintf(buf, MSG_SIZ, "option %s=%d\n", cps->option[j].name, new); else\r
+       if(changed == 1)\r
+         snprintf(buf, MSG_SIZ, "option %s=%s\n", cps->option[j].name, newText);\r
        if(changed) SendToProgram(buf, cps);\r
     }\r
 }\r
@@ -376,7 +378,7 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
             return TRUE;\r
 \r
         case IDCANCEL:\r
-            EndDialog( hDlg, 1 );   \r
+            EndDialog( hDlg, 1 );\r
             return TRUE;\r
 \r
        default:\r
@@ -385,10 +387,10 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
            if( i>=2000 &&  i < 2000+2*(layout+buttons)) {\r
                j = layoutList[(i - 2000)/2];\r
                if(j == -2) {\r
-                         char filter[] = \r
+                         char filter[] =\r
                                "All files\0*.*\0BIN Files\0*.bin\0LOG Files\0*.log\0INI Files\0*.ini\0\0";\r
 /*\r
-{ \r
+{\r
                              'A','l','l',' ','F','i','l','e','s', 0,\r
                              '*','.','*', 0,\r
                              'B','I','N',' ','F','i','l','e','s', 0,\r
@@ -418,7 +420,7 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
                if( activeCps->option[j].type  == SaveButton)\r
                     GetOptionValues(hDlg, activeCps);\r
                else if( activeCps->option[j].type  != Button) break;\r
-               sprintf(buf, "option %s\n", activeCps->option[j].name);\r
+               snprintf(buf, MSG_SIZ, "option %s\n", activeCps->option[j].name);\r
                SendToProgram(buf, activeCps);\r
            }\r
            break;\r
@@ -484,7 +486,7 @@ void AddOption(int x, int y, Control type, int i)
        case Message:\r
            break;\r
     }\r
-    \r
+\r
 }\r
 \r
 void\r
@@ -495,7 +497,7 @@ CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps)
     template.header.cdit = 0;\r
     template.header.cx = 307;\r
     buttonRows = (buttons + 1 + 3)/4; // 4 per row, rounded up\r
-    if(nr > 50) { \r
+    if(nr > 50) {\r
        breakPoint = (nr+2*buttonRows+1)/2 & ~1;\r
        template.header.cx = 625;\r
     }\r
@@ -503,9 +505,9 @@ CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps)
     for(i=0; i<nr; i++) {\r
        if(k < groups && i == boxList[k]) {\r
            y += 10;\r
-           AddControl(x+2, y+13*(i>>1)-2, 301, 13*(boxList[k+1]-boxList[k]>>1)+8, \r
+           AddControl(x+2, y+13*(i>>1)-2, 301, 13*(boxList[k+1]-boxList[k]>>1)+8,\r
                                                0x0082, WS_VISIBLE | WS_CHILD | SS_BLACKFRAME, 2400);\r
-           AddControl(x+60, y+13*(i>>1)-6, 10*groupNameList[k]/3, 10, \r
+           AddControl(x+60, y+13*(i>>1)-6, 10*groupNameList[k]/3, 10,\r
                                                0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, 2*(i+MAX_OPTIONS));\r
        }\r
        j = layoutList[i];\r
@@ -530,7 +532,7 @@ CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps)
     template.header.style &= ~WS_VSCROLL;\r
 }\r
 \r
-void \r
+void\r
 EngineOptionsPopup(HWND hwnd, ChessProgramState *cps)\r
 {\r
     FARPROC lpProc = MakeProcInstance( (FARPROC) SettingsProc, hInst );\r