aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libshare/smb.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c
index 1ac1a8d27..f8b7118a3 100644
--- a/lib/libshare/smb.c
+++ b/lib/libshare/smb.c
@@ -72,7 +72,7 @@ smb_retrieve_shares(void)
{
int rc = SA_OK;
char file_path[PATH_MAX], line[512], *token, *key, *value;
- char *dup_value, *path = NULL, *comment = NULL, *name = NULL;
+ char *dup_value = NULL, *path = NULL, *comment = NULL, *name = NULL;
char *guest_ok = NULL;
DIR *shares_dir;
FILE *share_file_fp = NULL;
@@ -136,12 +136,19 @@ smb_retrieve_shares(void)
goto out;
}
- if (strcmp(key, "path") == 0)
+ if (strcmp(key, "path") == 0) {
+ free(path);
path = dup_value;
- if (strcmp(key, "comment") == 0)
+ } else if (strcmp(key, "comment") == 0) {
+ free(comment);
comment = dup_value;
- if (strcmp(key, "guest_ok") == 0)
+ } else if (strcmp(key, "guest_ok") == 0) {
+ free(guest_ok);
guest_ok = dup_value;
+ } else
+ free(dup_value);
+
+ dup_value = NULL;
if (path == NULL || comment == NULL || guest_ok == NULL)
continue; /* Incomplete share definition */
@@ -153,25 +160,24 @@ smb_retrieve_shares(void)
goto out;
}
- strncpy(shares->name, name,
- sizeof (shares->name));
- shares->name [sizeof (shares->name) - 1] = '\0';
+ (void) strlcpy(shares->name, name,
+ sizeof (shares->name));
- strncpy(shares->path, path,
+ (void) strlcpy(shares->path, path,
sizeof (shares->path));
- shares->path [sizeof (shares->path) - 1] = '\0';
- strncpy(shares->comment, comment,
+ (void) strlcpy(shares->comment, comment,
sizeof (shares->comment));
- shares->comment[sizeof (shares->comment)-1] =
- '\0';
shares->guest_ok = atoi(guest_ok);
shares->next = new_shares;
new_shares = shares;
- name = NULL;
+ free(path);
+ free(comment);
+ free(guest_ok);
+
path = NULL;
comment = NULL;
guest_ok = NULL;
@@ -179,13 +185,20 @@ smb_retrieve_shares(void)
}
out:
- if (share_file_fp != NULL)
+ if (share_file_fp != NULL) {
fclose(share_file_fp);
+ share_file_fp = NULL;
+ }
free(name);
free(path);
free(comment);
free(guest_ok);
+
+ name = NULL;
+ path = NULL;
+ comment = NULL;
+ guest_ok = NULL;
}
closedir(shares_dir);