Comments (1)
Hi.
I'm using
libsmb2
on a Windows 11 laptop to connect to a Samba drive on a Linux embedded device. The connection happens through a USB3 cable, where the embedded device is detected as a network card on the laptop using RNDIS.It has been working well so far, with the exception that if I unplug the USB cable during a transfer, then I have a crash when I delete the context later with
smb2_destroy_context
.Now I tried to update the lib to the latest commit on
master
, as my prior version oflibsmb2
was from June 2022.Hang forever
But now with the latest new version, I get an infinite hang if I unplug the cable during a read operation using the sync API:
- It stays stuck forever in the
wait_for_reply
function.- Adding a timeout does not change anything, because
fd
is never invalidated to -1 and the function does not return.- In
smb2_service_fd
, the polling raises flagsPOLLERR
andPOLLHUP
. ThePOLLHUP
block is never reached due to thegoto
inPOLLERR
block. However, in both cases I don't see anything that could invalidate thefd
there.Fix
EDIT: After checking the diff since June 2022, I see that
smb2_service
andsmb2_service_fd
now return at_socket
type instead of anint
. But on Windows, this type is defined as unsigned, so returning-1
and checking for< 0
does not work, causing the function to not return and thus the infinite hang. The faulty commit seems to be4b1ef1f6bd09f96a9f0b78accfeac6e2c2766f34
.Crash
EDIT2: With the latest version and the hang fixed, if I unplug the USB cable while it's transferring a file, and then I close the SMB client and call
smb2_destroy_context
, then I get something looking like memory corruption, causing fully random crashes in the rest of the application. Commenting the linesmb2_destroy_context
in the destructor of my client fixes these crashes. Any idea what could go wrong in that case ? This seems very difficult to find and fix (on Windows, without valgrind); I'll try to replace thecalloc
andfree
functions and put prints, but the nature of the code with multiple callbacks and genericvoid*
types makes it extremely difficult to debug.Fix
EDIT3: After two full days of analysis, the commit
0dc1cc795512c808b52ecc83f7cd3e530936655d
which creates a special case for the close operation is the cause of my crash. In my workflow, I read a file and then close it usingsmb2_close()
(sync). However, if the USB network interface is removed during the transfer, the read operation fails, but thesmb2_close()
is still called to simplify the logic, expecting it to fail as well. In thissmb2_close()
, thewait_for_reply()
call fails with code -1 due to an expected error insmb2_service()
, also returning -1. However in that case, the callback remains set somewhere in a PDU that was queued. So calling thefree()
at the end ofsmb2_close()
frees this memory that is still referenced in a PDU callback. Then during the call tosmb2_destroy_context
when destroying the client, the PDUs in the queues are cancelled and all callback are called. But as the one for the close operation was already freed, it crashes !What could be done to fix these issues? Reverting these 2 commits is maybe not the best fix, as one of them was added to fix a memory leak apparently. In my case I'll fix locally already, because a leak is better than a crash.
Hey there, any news? Because first the commit that i replaced the t_socket was a attenpt to clear a warning also reverting one of them maybe in fact should be the best choice.
from libsmb2.
Related Issues (20)
- libsmb2 mingw32 compilation/usage
- API 'smb2_rename' work abnormal
- Can't delete remote files on a share with libsmb2 HOT 1
- LGPL 2.1 license stuff HOT 7
- Older samba servers crashing when uploading small files or writing last block of larger files
- Does libsmb2 support FSCTL_PIPE_TRANSCEIVE HOT 1
- Building shared library (configure --enable-shared ignored) HOT 3
- Very slow performance w/MacOS SMB server HOT 2
- Build for Apple Silicon arm64 (M1 / M2 / M3) ? HOT 1
- NetBIOS name resolution for hostnames? HOT 2
- ESP_PLATFORM is sys/poll.h, not poll.h. HOT 4
- Initialize p_syntax_id_t
- libsmb2 Debian Package HOT 1
- A couple of questions: (mainly SMBv3 traffic generation) HOT 2
- When will the new version be released?
- smb2_opendir memory leak HOT 3
- Many issues running libsmb2 in the context of a fuse filesystem HOT 9
- Add support to Teensy Micro Controller HOT 2
- error when building for ESP HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libsmb2.