From a0bd9d97a3a701fdb1f9a48ce925f63b786a8070 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sat, 19 Jan 2008 15:14:45 +0100 Subject: Tiny memory leak in lib/version.c Hi, while implementing the extra_info version stuff, it occured to me that samba_version_string() potentially allocates memory which is unused but never free'd. If SAMBA_VERSION_VENDOR_PATCH is defined, a second call to asprintf takes place. The result is stored in tmp_version. Afterwards, samba_version is set to tmp_version without free'ing samba_version first. Looks like a simple free(samba_version) is missing. Patch against 3.2-test below. Ok, this only happens once over the lifetime of the application, so it's no big deal, but I though it doesn't hurt to mention it. Corinna * lib/version.c (samba_version_string): Free samba_version before setting to tmp_version. (This used to be commit 373a23d48f2dd24e65dbf814ea58b4add2322128) --- source3/lib/version.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/lib/version.c') diff --git a/source3/lib/version.c b/source3/lib/version.c index 204c2044a8..cbb70ae8a6 100644 --- a/source3/lib/version.c +++ b/source3/lib/version.c @@ -51,6 +51,7 @@ const char *samba_version_string(void) */ assert(res != -1); + free(samba_version); samba_version = tmp_version; #endif -- cgit From 07e07f696ad10f3a5d7a0d9de656ff13600ac97d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Jan 2008 19:31:02 +0100 Subject: Use SAFE_FREE instead of free (This used to be commit 999647329028147d7c29a3348202641b3e03430e) --- source3/lib/version.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/version.c') diff --git a/source3/lib/version.c b/source3/lib/version.c index cbb70ae8a6..3cae02ad2e 100644 --- a/source3/lib/version.c +++ b/source3/lib/version.c @@ -51,7 +51,8 @@ const char *samba_version_string(void) */ assert(res != -1); - free(samba_version); + SAFE_FREE(samba_version); + samba_version = tmp_version; #endif -- cgit From 559603ad693ede382c566cb8bbd8e6bd8d5750a6 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 22 Jan 2008 11:33:17 +0100 Subject: Get Samba version or capability information from Windows On Jan 21 16:18, Danilo Almeida wrote: > Corina wrote: > > > + time_t samba_gitcommitdate; > > And: > > > + SIVAL(pdata,28,extended_info.samba_gitcommitdate); > > + memcpy(pdata+32,extended_info.samba_version_string,32); > > Note that you are dropping bits on a system w/64-bit time_t, and that this has the 2038 problem. Right. I changed samba_gitcommitdate from time_t to NTTIME and shortened samba_version_string to 28 bytes. New patch below. Thanks, Corinna (This used to be commit 28aa1c199d3a22cda34afcaab49c0561eeb0abcb) --- source3/lib/version.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source3/lib/version.c') diff --git a/source3/lib/version.c b/source3/lib/version.c index 3cae02ad2e..38c4f45ac6 100644 --- a/source3/lib/version.c +++ b/source3/lib/version.c @@ -59,3 +59,32 @@ const char *samba_version_string(void) return samba_version; #endif } + +void samba_extended_info_version(struct smb_extended_info *extended_info) +{ + assert(extended_info != NULL); + + extended_info->samba_magic = SAMBA_EXTENDED_INFO_MAGIC; + extended_info->samba_version = ((SAMBA_VERSION_MAJOR & 0xff) << 24) + | ((SAMBA_VERSION_MINOR & 0xff) << 16) + | ((SAMBA_VERSION_RELEASE & 0xff) << 8); +#ifdef SAMBA_VERSION_REVISION + extended_info->samba_version |= (tolower(*SAMBA_VERSION_REVISION) - 'a' + 1) & 0xff; +#endif +#ifdef SAMBA_VERSION_RC_RELEASE + extended_info->samba_subversion |= (SAMBA_VERSION_RC_RELEASE & 0xff) << 24; +#else +#ifdef SAMBA_VERSION_PRE_RELEASE + extended_info->samba_subversion |= (SAMBA_VERSION_PRE_RELEASE & 0xff) << 16; +#endif +#endif +#ifdef SAMBA_VERSION_VENDOR_PATCH + extended_info->samba_subversion |= (SAMBA_VERSION_VENDOR_PATCH & 0xffff); +#endif + /* FIXME: samba_gitcommitdate should contain the git commit date. */ + unix_to_nt_time(&extended_info->samba_gitcommitdate, time(NULL)); + + snprintf (extended_info->samba_version_string, + SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH, + "%s", samba_version_string()); +} -- cgit From 1d99598ca3f21dd863c8d63698f8af2b3b77759b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 22 Jan 2008 12:46:51 +0100 Subject: Avoid use of uninitialized memory (This used to be commit 85123aacdb13e97c3f44aeded1c80e13af53d83d) --- source3/lib/version.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/lib/version.c') diff --git a/source3/lib/version.c b/source3/lib/version.c index 38c4f45ac6..dff45f6259 100644 --- a/source3/lib/version.c +++ b/source3/lib/version.c @@ -84,7 +84,10 @@ void samba_extended_info_version(struct smb_extended_info *extended_info) /* FIXME: samba_gitcommitdate should contain the git commit date. */ unix_to_nt_time(&extended_info->samba_gitcommitdate, time(NULL)); + memset(extended_info->samba_version_string, 0, + sizeof(extended_info->samba_version_string)); + snprintf (extended_info->samba_version_string, - SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH, + sizeof(extended_info->samba_version_string), "%s", samba_version_string()); } -- cgit From d4d962f691d13f36226157c38f706ee4d10b9150 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 22 Jan 2008 13:00:22 +0100 Subject: Move samba_extended_info_version to smbd/trans2.c This is right now only used there, and in version.c it gave linker errors because some binaries (e.g. smbmnt) don't link in time.o (This used to be commit 1f0eaaa5911f893c822465a26fe49ab65afb0730) --- source3/lib/version.c | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'source3/lib/version.c') diff --git a/source3/lib/version.c b/source3/lib/version.c index dff45f6259..3cae02ad2e 100644 --- a/source3/lib/version.c +++ b/source3/lib/version.c @@ -59,35 +59,3 @@ const char *samba_version_string(void) return samba_version; #endif } - -void samba_extended_info_version(struct smb_extended_info *extended_info) -{ - assert(extended_info != NULL); - - extended_info->samba_magic = SAMBA_EXTENDED_INFO_MAGIC; - extended_info->samba_version = ((SAMBA_VERSION_MAJOR & 0xff) << 24) - | ((SAMBA_VERSION_MINOR & 0xff) << 16) - | ((SAMBA_VERSION_RELEASE & 0xff) << 8); -#ifdef SAMBA_VERSION_REVISION - extended_info->samba_version |= (tolower(*SAMBA_VERSION_REVISION) - 'a' + 1) & 0xff; -#endif -#ifdef SAMBA_VERSION_RC_RELEASE - extended_info->samba_subversion |= (SAMBA_VERSION_RC_RELEASE & 0xff) << 24; -#else -#ifdef SAMBA_VERSION_PRE_RELEASE - extended_info->samba_subversion |= (SAMBA_VERSION_PRE_RELEASE & 0xff) << 16; -#endif -#endif -#ifdef SAMBA_VERSION_VENDOR_PATCH - extended_info->samba_subversion |= (SAMBA_VERSION_VENDOR_PATCH & 0xffff); -#endif - /* FIXME: samba_gitcommitdate should contain the git commit date. */ - unix_to_nt_time(&extended_info->samba_gitcommitdate, time(NULL)); - - memset(extended_info->samba_version_string, 0, - sizeof(extended_info->samba_version_string)); - - snprintf (extended_info->samba_version_string, - sizeof(extended_info->samba_version_string), - "%s", samba_version_string()); -} -- cgit