Bug 5374 - thread issue - smbc_parse_path
Summary: thread issue - smbc_parse_path
Status: RESOLVED INVALID
Alias: None
Product: Samba 3.0
Classification: Unclassified
Component: libsmbclient (show other bugs)
Version: 3.0.28a
Hardware: x86 Linux
: P3 normal
Target Milestone: none
Assignee: Derrell Lipman
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-06 08:00 UTC by Walter Doekes
Modified: 2008-04-06 09:40 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Walter Doekes 2008-04-06 08:00:55 UTC
SUMMARY:
When using libsmbclient with multiple threads, sometimes the fname (path) gets mixed up and incorrect results are returned. I.e. files that should exist cannot be accessed.

PROBABLE CAUSE:
smbc_parse_path uses a static buffer that occasionally gets overwritten by another thread.

SYMPTOMS:
I saw the following output from my program:
2008-04-06 12:17:53: proto_smb: In authentication function for smb://som/likaan.
2008-04-06 12:17:53: proto_smb: Stat/open failed for `smb://som/share/music/some_random_file.mp3'
This happened while I was iterating over the files of two shares simultaneously: smb://som/share and smb://depelikaan/share. As you can see, smb://som/likaan is a mix of both the share paths.

TESTS:
I replaced the "static pstring s" in libsmbclient.c with "pstring s" and I could not reproduce the bug.

PATCH:
--- samba-3.0.28a/source/libsmb/libsmbclient.c.orig     2008-04-06 14:34:14.822198288 +0200
+++ samba-3.0.28a/source/libsmb/libsmbclient.c  2008-04-06 14:37:51.378276760 +0200
@@ -281,7 +281,7 @@
                 char *password, int password_len,
                 char *options, int options_len)
 {
-       static pstring s;
+       pstring s;
        pstring userinfo;
        const char *p;
        char *q, *r;
Comment 1 Derrell Lipman 2008-04-06 09:40:03 UTC
Samba 3.2, the current version, has no pstrings, and more importantly, no staticly-declared buffers in libsmbclient.

The Samba3 core is getting closer to being thread-safe, but AFAIK, still is not.  libsmbclient has a few potential issues with thread safety (particularly with tracking initialization state) which must be looked at when the core of Samba3 is deemed thread safe.  Until then, however, you should not assume that libsmbclient is thread safe.

Derrell