Skip to content

Commit 2fdae72

Browse files
committed
fix smb2 not allow longer than 1024 characters question
1 parent 26d667b commit 2fdae72

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
From 788c78b4310d2562b2c4818841ec2e0bdb803574 Mon Sep 17 00:00:00 2001
2+
From: qianlongxu <[email protected]>
3+
Date: Mon, 11 Nov 2024 18:08:22 +0800
4+
Subject: [PATCH] fix smb2 not allow longer than 1024 characters question
5+
6+
---
7+
lib/init.c | 36 ++++++++++++++++++++++--------------
8+
1 file changed, 22 insertions(+), 14 deletions(-)
9+
10+
diff --git a/lib/init.c b/lib/init.c
11+
index ed9d49b..527099c 100644
12+
--- a/lib/init.c
13+
+++ b/lib/init.c
14+
@@ -181,31 +181,35 @@ smb2_parse_args(struct smb2_context *smb2, const char *args)
15+
struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url)
16+
{
17+
struct smb2_url *u;
18+
- char *ptr, *tmp, str[MAX_URL_SIZE];
19+
+ char *ptr, *tmp, *str = NULL;
20+
char *args;
21+
22+
if (strncmp(url, "smb://", 6)) {
23+
smb2_set_error(smb2, "URL does not start with 'smb://'");
24+
- return NULL;
25+
- }
26+
- if (strlen(url + 6) >= MAX_URL_SIZE) {
27+
- smb2_set_error(smb2, "URL is too long");
28+
- return NULL;
29+
- }
30+
- strncpy(str, url + 6, MAX_URL_SIZE);
31+
-
32+
+ u = NULL;
33+
+ goto end;
34+
+ }
35+
+ // if (strlen(url + 6) >= MAX_URL_SIZE) {
36+
+ // smb2_set_error(smb2, "URL is too long");
37+
+ // return NULL;
38+
+ // }
39+
+ // strncpy(str, url + 6, MAX_URL_SIZE);
40+
+
41+
+ str = strdup(url + 6);
42+
args = strchr(str, '?');
43+
if (args) {
44+
*(args++) = '\0';
45+
if (smb2_parse_args(smb2, args) != 0) {
46+
- return NULL;
47+
+ u = NULL;
48+
+ goto end;
49+
}
50+
}
51+
52+
u = calloc(1, sizeof(struct smb2_url));
53+
if (u == NULL) {
54+
smb2_set_error(smb2, "Failed to allocate smb2_url");
55+
- return NULL;
56+
+ u = NULL;
57+
+ goto end;
58+
}
59+
60+
ptr = str;
61+
@@ -213,7 +217,8 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url)
62+
char *shared_folder = strchr(ptr, '/');
63+
if (!shared_folder) {
64+
smb2_set_error(smb2, "Wrong URL format");
65+
- return NULL;
66+
+ u = NULL;
67+
+ goto end;
68+
}
69+
int len_shared_folder = strlen(shared_folder);
70+
71+
@@ -242,14 +247,17 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url)
72+
/* We only have a share */
73+
if (tmp == NULL) {
74+
u->share = strdup(ptr);
75+
- return u;
76+
+ goto end;
77+
}
78+
79+
/* we have both share and object path */
80+
*(tmp++) = '\0';
81+
u->share = strdup(ptr);
82+
u->path = strdup(tmp);
83+
-
84+
+end:
85+
+ if (str){
86+
+ free(str);
87+
+ }
88+
return u;
89+
}
90+
91+
--
92+
2.39.5 (Apple Git-154)
93+

0 commit comments

Comments
 (0)