[vlc-commits] unc: don't depend on MAX_PATH
Rémi Denis-Courmont
git at videolan.org
Sun Feb 23 15:12:01 CET 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb 23 16:03:28 2020 +0200| [e31aedd83ba3ccb00b128a676df5dcd424e1e17d] | committer: Rémi Denis-Courmont
unc: don't depend on MAX_PATH
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e31aedd83ba3ccb00b128a676df5dcd424e1e17d
---
modules/access/unc.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/modules/access/unc.c b/modules/access/unc.c
index f7b6a7be71..fbb3a58240 100644
--- a/modules/access/unc.c
+++ b/modules/access/unc.c
@@ -54,42 +54,44 @@ static void Win32AddConnection(stream_t *access, const char *server,
const char *share, const char *user,
const char *pwd)
{
- NETRESOURCE net_resource;
- char remote_name[MAX_PATH];
+ char *remote_name;
- memset(&net_resource, 0, sizeof (net_resource));
- net_resource.dwType = RESOURCETYPE_DISK;
-
- snprintf(remote_name, sizeof (remote_name), "\\\\%s\\%s", server,
- (share != NULL) ? share + 1 /* skip leading '/' */: "");
+ if (asprintf(&remote_name, "\\\\%s\\%s", server,
+ (share != NULL) ? share + 1 /* skip leading '/' */: "") < 0)
+ return;
/* remove trailings '/' */
char *delim = strchr(remote_name, '/');
if (delim != NULL)
*delim = '\0';
- const char *msg;
- net_resource.lpRemoteName = ToWide(remote_name);
+ NETRESOURCE net_resource = {
+ .dwType = RESOURCETYPE_DISK,
+ .lpRemoteName = ToWide(remote_name),
+ };
+ free(remote_name);
+
+ const char *msg;
wchar_t *wpwd = pwd ? ToWide(pwd) : NULL;
wchar_t *wuser = user ? ToWide(user) : NULL;
switch (WNetAddConnection2(&net_resource, wpwd, wuser, 0))
{
case NO_ERROR:
- msg = "connected to %s";
+ msg = "connected to %ls";
break;
case ERROR_ALREADY_ASSIGNED:
case ERROR_DEVICE_ALREADY_REMEMBERED:
- msg = "already connected to %s";
+ msg = "already connected to %ls";
break;
default:
- msg = "failed to connect to %s";
+ msg = "failed to connect to %ls";
}
+ msg_Dbg(access, msg, net_resource.lpRemoteName);
free(net_resource.lpRemoteName);
free(wpwd);
free(wuser);
- msg_Dbg(access, msg, remote_name);
}
/* Build an SMB URI
More information about the vlc-commits
mailing list