1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-24 10:50:22 +03:00

examples: Remove all uses of strcpy in examples (except for validchr.c).

I can't figure out how to make git handle the CR/LF differences
in this file.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Jeremy Allison 2016-03-16 15:09:12 -07:00 committed by Martin Schwenke
parent 7e435d3cce
commit 4609058a9c
5 changed files with 13 additions and 8 deletions

View File

@ -139,7 +139,8 @@ int main(int argc, const char *argv[])
return 1;
}
strcpy(path, poptGetArg(pc));
strncpy(path, poptGetArg(pc), sizeof(path));
path[sizeof(path)-1] = '\0';
if (smbc_init(get_auth_data_fn, debug) != 0)
{

View File

@ -68,16 +68,18 @@ static smbitem* get_smbitem_list(SMBCCTX *ctx, char *smb_path){
if ((fd = smbc_getFunctionOpendir(ctx)(ctx, smb_path)) == NULL)
return NULL;
while((dirent = smbc_getFunctionReaddir(ctx)(ctx, fd)) != NULL){
size_t slen;
if (strcmp(dirent->name, "") == 0) continue;
if (strcmp(dirent->name, ".") == 0) continue;
if (strcmp(dirent->name, "..") == 0) continue;
if ((item = malloc(sizeof(smbitem) + strlen(dirent->name))) == NULL)
slen = strlen(dirent->name)+1;
if ((item = malloc(sizeof(smbitem) + slen)) == NULL)
continue;
item->next = list;
item->type = dirent->smbc_type;
strcpy(item->name, dirent->name);
memcpy(item->name, dirent->name, slen);
list = item;
}
smbc_getFunctionClose(ctx)(ctx, fd);
@ -113,7 +115,8 @@ static void recurse(SMBCCTX *ctx, const char *smb_group, char *smb_path, int max
else print_smb_path(smb_group, list->name);
if (maxlen < 7 + strlen(list->name)) break;
strcpy(smb_path + 6, list->name);
strncpy(smb_path + 6, list->name, maxlen - 6);
smb_path[maxlen-1] = '\0';
if ((ctx1 = create_smbctx()) != NULL){
recurse(ctx1, smb_group, smb_path, maxlen);
delete_smbctx(ctx1);
@ -128,7 +131,8 @@ static void recurse(SMBCCTX *ctx, const char *smb_group, char *smb_path, int max
if (maxlen < len + strlen(list->name) + 2) break;
smb_path[len] = '/';
strcpy(smb_path + len + 1, list->name);
strncpy(smb_path + len + 1, list->name, maxlen - len - 1);
smb_path[maxlen-1] = '\0';
print_smb_path(smb_group, smb_path + 6);
if (list->type != SMBC_FILE){
recurse(ctx, smb_group, smb_path, maxlen);

View File

@ -115,7 +115,7 @@ int main(int argc, char *argv[])
/* Now, write some date to the file ... */
memset(buff, '\0', sizeof(buff));
strcpy(buff, "Some test data for the moment ...");
snprintf(buff, sizeof(buff), "%s", "Some test data for the moment ...");
err = smbc_write(fd, buff, sizeof(buff));

View File

@ -32,7 +32,7 @@ int main(int argc, char * argv[])
return 1;
}
strcpy(buffer, "Hello world.\nThis is a test.\n");
snprintf(buffer, sizeof(buffer), "%s", "Hello world.\nThis is a test.\n");
ret = smbc_write(fd, buffer, strlen(buffer));
savedErrno = errno;

View File

@ -47,7 +47,7 @@ int main(int argc, char * argv[])
continue;
}
strcpy(buffer, "Hello world\n");
snprintf(buffer, sizeof(buffer), "%s", "Hello world\n");
ret = smbc_write(fd, buffer, strlen(buffer));
savedErrno = errno;