vlc | branch: master | Thomas Guillem <[email protected]> | Thu Aug 8 08:15:14 2019 +0200| [e2f163e89023680e6e9f34f8aeebbd5cfb405cf4] | committer: Thomas Guillem
contrib: smb2: backport getlogin fix cf. https://github.com/sahlberg/libsmb2/pull/94 > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e2f163e89023680e6e9f34f8aeebbd5cfb405cf4 --- ...-ntlmssp-add-support-for-Anonymous-logins.patch | 2 +- .../smb2/0002-Fix-indent-and-white-spaces.patch | 97 ++++++++++++++++++++++ contrib/src/smb2/0003-Fix-getlogin-usage.patch | 58 +++++++++++++ contrib/src/smb2/rules.mak | 2 + 4 files changed, 158 insertions(+), 1 deletion(-) diff --git a/contrib/src/smb2/0001-ntlmssp-add-support-for-Anonymous-logins.patch b/contrib/src/smb2/0001-ntlmssp-add-support-for-Anonymous-logins.patch index 433472086f..11584ed6ac 100644 --- a/contrib/src/smb2/0001-ntlmssp-add-support-for-Anonymous-logins.patch +++ b/contrib/src/smb2/0001-ntlmssp-add-support-for-Anonymous-logins.patch @@ -1,7 +1,7 @@ From 91e4b27ec265d2c08890fcee9043a15382d8a54f Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg <[email protected]> Date: Tue, 6 Aug 2019 13:30:51 +1000 -Subject: [PATCH] ntlmssp: add support for Anonymous logins +Subject: [PATCH 1/3] ntlmssp: add support for Anonymous logins Signed-off-by: Ronnie Sahlberg <[email protected]> --- diff --git a/contrib/src/smb2/0002-Fix-indent-and-white-spaces.patch b/contrib/src/smb2/0002-Fix-indent-and-white-spaces.patch new file mode 100644 index 0000000000..bf3c7e33fa --- /dev/null +++ b/contrib/src/smb2/0002-Fix-indent-and-white-spaces.patch @@ -0,0 +1,97 @@ +From ea434501d1987ac309f7e9a4070be2f7af6ca01d Mon Sep 17 00:00:00 2001 +From: Thomas Guillem <[email protected]> +Date: Tue, 30 Jul 2019 17:46:49 +0200 +Subject: [PATCH 2/3] Fix indent and white spaces + +No functional changes. +--- + lib/init.c | 34 +++++++++++++++++----------------- + 1 file changed, 17 insertions(+), 17 deletions(-) + +diff --git a/lib/init.c b/lib/init.c +index e6cf1e5..eab69a5 100644 +--- a/lib/init.c ++++ b/lib/init.c +@@ -69,12 +69,12 @@ smb2_parse_args(struct smb2_context *smb2, const char *args) + while (args && *args != 0) { + char *next, *value; + +- next = strchr(args, '&'); ++ next = strchr(args, '&'); + if (next) { + *(next++) = '\0'; + } + +- value = strchr(args, '='); ++ value = strchr(args, '='); + if (value) { + *(value++) = '\0'; + } +@@ -135,7 +135,7 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url) + smb2_set_error(smb2, "URL is too long"); + return NULL; + } +- strncpy(str, url + 6, MAX_URL_SIZE); ++ strncpy(str, url + 6, MAX_URL_SIZE); + + args = strchr(str, '?'); + if (args) { +@@ -165,7 +165,7 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url) + *(tmp++) = '\0'; + u->user = strdup(ptr); + ptr = tmp; +- } ++ } + /* server */ + if ((tmp = strchr(ptr, '/')) != NULL) { + *(tmp++) = '\0'; +@@ -287,7 +287,7 @@ void smb2_destroy_context(struct smb2_context *smb2) + void smb2_free_iovector(struct smb2_context *smb2, struct smb2_io_vectors *v) + { + int i; +- ++ + for (i = 0; i < v->niov; i++) { + if (v->iov[i].free) { + v->iov[i].free(v->iov[i].buf); +@@ -316,25 +316,25 @@ struct smb2_iovec *smb2_add_iovector(struct smb2_context *smb2, + + void smb2_set_error(struct smb2_context *smb2, const char *error_string, ...) + { +- va_list ap; +- char errstr[MAX_ERROR_SIZE] = {0}; ++ va_list ap; ++ char errstr[MAX_ERROR_SIZE] = {0}; + +- va_start(ap, error_string); +- if (vsnprintf(errstr, MAX_ERROR_SIZE, error_string, ap) < 0) { +- strncpy(errstr, "could not format error string!", ++ va_start(ap, error_string); ++ if (vsnprintf(errstr, MAX_ERROR_SIZE, error_string, ap) < 0) { ++ strncpy(errstr, "could not format error string!", + MAX_ERROR_SIZE); +- } +- va_end(ap); +- if (smb2 != NULL) { +- strncpy(smb2->error_string, errstr, MAX_ERROR_SIZE); +- } ++ } ++ va_end(ap); ++ if (smb2 != NULL) { ++ strncpy(smb2->error_string, errstr, MAX_ERROR_SIZE); ++ } + } + + const char *smb2_get_error(struct smb2_context *smb2) + { +- return smb2 ? smb2->error_string : ""; ++ return smb2 ? smb2->error_string : ""; + } +- ++ + const char *smb2_get_client_guid(struct smb2_context *smb2) + { + return smb2->client_guid; +-- +2.20.1 + diff --git a/contrib/src/smb2/0003-Fix-getlogin-usage.patch b/contrib/src/smb2/0003-Fix-getlogin-usage.patch new file mode 100644 index 0000000000..00f3c13f14 --- /dev/null +++ b/contrib/src/smb2/0003-Fix-getlogin-usage.patch @@ -0,0 +1,58 @@ +From dd506ff5c5d53c529380b637e809f740a49aece7 Mon Sep 17 00:00:00 2001 +From: Thomas Guillem <[email protected]> +Date: Tue, 30 Jul 2019 18:02:14 +0200 +Subject: [PATCH 3/3] Fix getlogin() usage + +Use the reentrant version (the getlogin() string was statically allocated and +could be overwritten on subsequent calls). + +Also check for error and use "Guest" as a fallback. +--- + lib/init.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/lib/init.c b/lib/init.c +index eab69a5..3c01774 100644 +--- a/lib/init.c ++++ b/lib/init.c +@@ -52,7 +52,7 @@ + #define MAX_URL_SIZE 256 + + #ifdef _MSC_VER +-#define getlogin() "Guest" ++#define getlogin_r() ENXIO + #define random rand + #define getpid GetCurrentProcessId + #endif // _MSC_VER +@@ -60,7 +60,7 @@ + #ifdef ESP_PLATFORM + #include <esp_system.h> + #define random esp_random +-#define getlogin() "Guest" ++#define getlogin_r() ENXIO + #endif + + static int +@@ -206,7 +206,8 @@ void smb2_destroy_url(struct smb2_url *url) + struct smb2_context *smb2_init_context(void) + { + struct smb2_context *smb2; +- int i; ++ char buf[1024]; ++ int i, ret; + + smb2 = malloc(sizeof(struct smb2_context)); + if (smb2 == NULL) { +@@ -214,7 +215,8 @@ struct smb2_context *smb2_init_context(void) + } + memset(smb2, 0, sizeof(struct smb2_context)); + +- smb2_set_user(smb2, getlogin()); ++ ret = getlogin_r(buf, sizeof(buf)); ++ smb2_set_user(smb2, ret == 0 ? buf : "Guest"); + smb2->fd = -1; + smb2->sec = SMB2_SEC_UNDEFINED; + smb2->version = SMB2_VERSION_ANY; +-- +2.20.1 + diff --git a/contrib/src/smb2/rules.mak b/contrib/src/smb2/rules.mak index 52dfdcb15a..5d6132ee05 100644 --- a/contrib/src/smb2/rules.mak +++ b/contrib/src/smb2/rules.mak @@ -19,6 +19,8 @@ $(TARBALLS)/libsmb2-$(SMB2_VERSION).tar.gz: smb2: libsmb2-$(SMB2_VERSION).tar.gz .sum-smb2 $(UNPACK) $(APPLY) $(SRC)/smb2/0001-ntlmssp-add-support-for-Anonymous-logins.patch + $(APPLY) $(SRC)/smb2/0002-Fix-indent-and-white-spaces.patch + $(APPLY) $(SRC)/smb2/0003-Fix-getlogin-usage.patch $(MOVE) .smb2: smb2 _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
