Bug 1089 - nmblib.c: slprintf(buf, buflen, "%-15.15s", name) failed if name has multibyte chars.
Summary: nmblib.c: slprintf(buf, buflen, "%-15.15s", name) failed if name has multibyt...
Status: CLOSED FIXED
Alias: None
Product: Samba 3.0
Classification: Unclassified
Component: Extended Characters (show other bugs)
Version: 3.0.2
Hardware: All Linux
: P3 normal
Target Milestone: none
Assignee: Alexander Bokovoy
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-17 01:00 UTC by SATOH Fumiyasu
Modified: 2005-08-24 10:27 UTC (History)
1 user (show)

See Also:


Attachments
proposed patch to fix this bug (2.07 KB, patch)
2004-02-17 01:10 UTC, SATOH Fumiyasu
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description SATOH Fumiyasu 2004-02-17 01:00:28 UTC
*printf(3) functions have some locale(5) specific behaviors.

In source/libsmb/nmblib.c, put_nmb_name() and name_mangle() function
use slprintf() (snprintf(3)) to format NetBIOS name (in dos charset)
and name type.

But on the following situation, slprintf() fails and buffer is not set:

    slprintf(
        buffuer,
        sizeof(buffuer),
        "%-15.15s",
        "valid chars in dos charset, but invalid in current locale(5) setting"
    );

Please use a locale-indepent functions in this situation.
Comment 1 SATOH Fumiyasu 2004-02-17 01:10:52 UTC
Created attachment 405 [details]
proposed patch to fix this bug

Attach a proposed patch.
Comment 2 SATOH Fumiyasu 2004-02-17 01:18:23 UTC
Oops... s/locale-indepent/locale-independent/ in description.
Comment 3 SATOH Fumiyasu 2004-02-23 02:54:10 UTC
# Can you hear me? :)

Oops. My proposed patch causes SIGSEVG if strlen(name) is longer than 15.

--- nmblib.c.old	2004-02-17 18:08:55.000000000 +0900
+++ nmblib.c	2004-02-23 19:44:16.000000000 +0900
@@ -264,7 +264,9 @@ static void put_name(char *dest, const c
     size_t len = strlen(name);
 
     memcpy(dest, name, (len <= 15) ? len : 15);
-    memset(dest + len, pad, 15 - len);
+    if (len < 15) {
+	memset(dest + len, pad, 15 - len);
+    }
     dest[15] = name_type;
 }
 
Comment 4 Alexander Bokovoy 2004-02-23 03:41:01 UTC
In init_iconv() we go to charset_name() and there we may initialize setlocale()
to locale environment under which application runs if one of 'dos charset, unix
charset, or display charset' settings is 'LOCALE'. It is default for 'display
charset'.

However, nmbd and smbd usually start as daemons and from init scripts thus
having locale POSIX effectively set up. So, you observation is valid for default
Samba settings.

I'll look into the patch soon.
Comment 5 SATOH Fumiyasu 2004-03-17 19:15:27 UTC
The patch in Additional Comment #1 is included in a patch attached in Bug 784.
Comment 6 SATOH Fumiyasu 2004-07-12 19:23:36 UTC
This bug was gone by Samba 3.0.3 or later.
Comment 7 Gerald (Jerry) Carter (dead mail address) 2005-08-24 10:27:52 UTC
sorry for the same, cleaning up the database to prevent unecessary reopens of bugs.