URL:
  <http://gna.org/bugs/?24328>

                 Summary: A number of text buffers have insufficient size
                 Project: Freeciv
            Submitted by: konved
            Submitted on: Пн 18 янв 2016 21:27:11
                Category: general
                Severity: 2 - Minor
                Priority: 5 - Normal
                  Status: None
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
                 Release: 2.5.x, 2.6, 3.0
         Discussion Lock: Any
        Operating System: Any
         Planned Release: 

    _______________________________________________________

Details:

The issue is related to the Russian i18n, but would be actual for other
languages with non-latin script (for ex: Hebrew, Arabic, Bulgarian, Ukrainian,
etc.), of course if their translators suddenly appear :).


23:35 konved@lark: ~/freeciv25 $ ./freeciv-server
Encodings: Data=UTF-8, Local=UTF-8, Internal=UTF-8
Это сервер игры Freeciv версии 2.5.1+ (modified r31484)
[...]
> set airliftingstyle FROM_ALLIES|TO_ALLIES|SRC_UNLIMITED|DEST_UNLIMITED
Invalid string conversion from UTF-8 to UTF-8: Неверный или
неполный мультибайтный или широкий
символ.
Консоль: значение параметра 'airliftingstyle' было
изменено на "Переброска по воздуху из
союзных �, "Переброска по воздуху в
союзные г�, "Неограниченное число из
пункта от и "Неограниченное число в пункт
н�.
> show airliftingstyle 
------------------------------------------------------------------------------
В столбце '##' показана возможность
изменения значения параметра:
 — знак '!' означает, что изменение
параметра заблокировано набором правил.
 — знак '+' означает, что Вы можете изменить
значение параметра.
 — знак '=' означает, что параметр
установлен в значение по умолчанию.
------------------------------------------------------------------------------
Параметр          ## значение (мин, макс)
------------------------------------------------------------------------------
airliftingstyle           +  "Переброска по воздуху
Invalid string conversion from UTF-8 to UTF-8: Неверный или
неполный мультибайтный или широкий
символ.
                             из союзных �,
                             "Переброска по воздуху
Invalid string conversion from UTF-8 to UTF-8: Неверный или
неполный мультибайтный или широкий
символ.
                             в союзные г�,
                             "Неограниченное число
                             из пункта от и
                             "Неограниченное число
                             в пункт назн
                            
(FROM_ALLIES|TO_ALLIES|SRC_UNLIMITED|DEST_UNLIMITED)
------------------------------------------------------------------------------
Справка по каждому параметру доступна при
помощи команды 'help <параметр>'.
------------------------------------------------------------------------------
>

You can see that some lines are incorrectly cut.

Reference: Russian error text "Неверный или неполный
мультибайтный или широкий символ." came from
libc's i18n and means "Invalid or incomplete multibyte or wide character".

Reference 2: With Russian locale the nowadays string Q_("Allows units to be
airlifted from allied cities") have only 32 characters but is 75 (!) bytes
long in UTF-8 encoding (as strlen() reports).

The 'revealmap' setting have the same issue (/set revealmap DEAD).
----
Okay, let's start patching from setting_bitwise_to_str():

--- server/settings.c   (revision 31484)
+++ server/settings.c   (working copy)
@@ -3234,7 +3234,7 @@
   int bit;
 
   if (pretty) {
-    char buf2[64];
+    char buf2[128];


And we can see (I've dropped head of table):

> set airliftingstyle FROM_ALLIES|TO_ALLIES|SRC_UNLIMITED|DEST_UNLIMITED
Консоль: значение параметра 'airliftingstyle' было
изменено на "Переброска по воздуху из
союзных городов", "Переброска по воздуху в
союзные города", "Неограниченное число из
пункта отправления" и "Неогран.
> show airliftingstyle 
------------------------------------------------------------------------------
airliftingstyle           +  "Переброска по воздуху
                             из союзных городов",
                             "Переброска по воздуху
                             в союзные города",
                             "Неограниченное число
                             из пункта отправления"
                             и "Неограниченное
                             число в пункт
                             назначения"
                             [](FROM_ALLIE|
------------------------------------------------------------------------------


Well, parts of and-list are no longer truncated but the entire list doesn't
fit into another buffer now.

_[some gdb poking skipped]_

Catched show_settings_one(). Patching...

--- server/console.h    (revision 31484)
+++ server/console.h    (working copy)
@@ -15,7 +15,7 @@
 
 #include "support.h"            /* bool type and fc__attribute */
 
-#define MAX_LEN_CONSOLE_LINE 512       /* closing \0 included */
+#define MAX_LEN_CONSOLE_LINE 1024      /* closing \0 included */

----
Testing...

airliftingstyle           +  "Переброска по воздуху
[...]
(FROM_ALLIES|TO_ALLIES|SRC_UNLIMITED|DEST_UNLIMITED)


Bingo!
----
ps. Oh, wait, I remember one more episode since 2.5 have been beta: the
initial screen of any client have the version string, and when IS_BETA_VERSION
is set, then version string also becomes too long.

--- common/version.c    (revision 31484)
+++ common/version.c    (working copy)
@@ -38,7 +38,7 @@
 ***********************************************************************/
 const char *freeciv_name_version(void)
 {
-  static char msgbuf[128];
+  static char msgbuf[256];

----
pps. Maybe there're more buffers with insufficient size, so I'd suggest to
double size of all buffers which can contain translated text...




    _______________________________________________________

Reply to this item at:

  <http://gna.org/bugs/?24328>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to