1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

Fix simple uses of safe_strcpy -> strlcpy. Easy ones where we just remove -1.

This commit is contained in:
Jeremy Allison 2011-05-03 13:10:01 -07:00
parent deba880986
commit 017e0c8d95
14 changed files with 26 additions and 26 deletions

View File

@ -119,7 +119,7 @@ static void smb_panic_default(const char *why)
if (panic_action && *panic_action) {
char pidstr[20];
char cmdstring[200];
safe_strcpy(cmdstring, panic_action, sizeof(cmdstring)-1);
strlcpy(cmdstring, panic_action, sizeof(cmdstring));
snprintf(pidstr, sizeof(pidstr), "%d", (int) getpid());
all_string_sub(cmdstring, "%PID%", pidstr, sizeof(cmdstring));
DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmdstring));

View File

@ -47,10 +47,10 @@ size_t __unsafe_string_function_usage_here_size_t__(void);
/* String copy functions - macro hell below adds 'type checking' (limited,
but the best we can do in C) */
#define fstrcpy(d,s) safe_strcpy((d),(s),sizeof(fstring)-1)
#define fstrcat(d,s) safe_strcat((d),(s),sizeof(fstring)-1)
#define nstrcpy(d,s) safe_strcpy((d), (s),sizeof(nstring)-1)
#define unstrcpy(d,s) safe_strcpy((d), (s),sizeof(unstring)-1)
#define fstrcpy(d,s) strlcpy((d),(s) ? (s) : "",sizeof(fstring))
#define fstrcat(d,s) strlcpy((d),(s) ? (s) : "",sizeof(fstring))
#define nstrcpy(d,s) strlcpy((d), (s) ? (s) : "",sizeof(nstring))
#define unstrcpy(d,s) strlcpy((d), (s) ? (s) : "",sizeof(unstring))
/* the addition of the DEVELOPER checks in safe_strcpy means we must
* update a lot of code. To make this a little easier here are some

View File

@ -25,7 +25,7 @@
static bool test_string_sub_simple(struct torture_context *tctx)
{
char tmp[100];
safe_strcpy(tmp, "foobar", sizeof(tmp)-1);
strlcpy(tmp, "foobar", sizeof(tmp));
string_sub(tmp, "foo", "bar", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "barbar", "invalid sub");
return true;
@ -34,7 +34,7 @@ static bool test_string_sub_simple(struct torture_context *tctx)
static bool test_string_sub_multiple(struct torture_context *tctx)
{
char tmp[100];
safe_strcpy(tmp, "fooblafoo", sizeof(tmp)-1);
strlcpy(tmp, "fooblafoo", sizeof(tmp));
string_sub(tmp, "foo", "bar", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "barblabar", "invalid sub");
return true;
@ -43,7 +43,7 @@ static bool test_string_sub_multiple(struct torture_context *tctx)
static bool test_string_sub_longer(struct torture_context *tctx)
{
char tmp[100];
safe_strcpy(tmp, "foobla", sizeof(tmp)-1);
strlcpy(tmp, "foobla", sizeof(tmp));
string_sub(tmp, "foo", "blie", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "bliebla", "invalid sub");
return true;
@ -52,7 +52,7 @@ static bool test_string_sub_longer(struct torture_context *tctx)
static bool test_string_sub_shorter(struct torture_context *tctx)
{
char tmp[100];
safe_strcpy(tmp, "foobla", sizeof(tmp)-1);
strlcpy(tmp, "foobla", sizeof(tmp));
string_sub(tmp, "foo", "bl", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "blbla", "invalid sub");
return true;
@ -61,7 +61,7 @@ static bool test_string_sub_shorter(struct torture_context *tctx)
static bool test_string_sub_special_char(struct torture_context *tctx)
{
char tmp[100];
safe_strcpy(tmp, "foobla", sizeof(tmp)-1);
strlcpy(tmp, "foobla", sizeof(tmp));
string_sub(tmp, "foo", "%b;l", sizeof(tmp));
torture_assert_str_equal(tctx, tmp, "_b_lbla", "invalid sub");
return true;

View File

@ -134,7 +134,7 @@ bool E_deshash(const char *passwd, uint8_t p16[16])
tmpbuf = strupper_talloc(mem_ctx, passwd);
if (tmpbuf == NULL) {
/* Too many callers don't check this result, we need to fill in the buffer with something */
safe_strcpy((char *)dospwd, passwd, sizeof(dospwd)-1);
strlcpy((char *)dospwd, passwd, sizeof(dospwd));
E_P16(dospwd, p16);
return false;
}

View File

@ -54,7 +54,7 @@
#ifndef FSTRING_LEN
#define FSTRING_LEN 256
typedef char fstring[FSTRING_LEN];
#define fstrcpy(d,s) safe_strcpy((d),(s),sizeof(fstring)-1)
#define fstrcpy(d,s) strlcpy((d),(s) ? (s) : "",sizeof(fstring))
#endif
/* Some systems (SCO) treat UNIX domain sockets as FIFOs */

View File

@ -105,7 +105,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type,
SCVAL(p,0,updatecount);
SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */
safe_strcpy(upper_server_name, server_name, sizeof(upper_server_name)-1);
strlcpy(upper_server_name, server_name ? server_name : "", sizeof(upper_server_name));
strupper_m(upper_server_name);
push_string_check(p+5, upper_server_name, 16, STR_ASCII|STR_TERMINATE);

View File

@ -85,7 +85,7 @@ static void pong_message(struct messaging_context *msg_ctx,
/* Now test that the duplicate filtering code works. */
pong_count = 0;
safe_strcpy(buf, "1234567890", sizeof(buf)-1);
strlcpy(buf, "1234567890", sizeof(buf));
for (i=0;i<n;i++) {
messaging_send(msg_ctx, messaging_server_id(msg_ctx), MSG_PING,

View File

@ -824,7 +824,7 @@ static int rap_user_add(struct net_context *c, int argc, const char **argv)
if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli)))
return -1;
safe_strcpy((char *)userinfo.user_name, argv[0], sizeof(userinfo.user_name)-1);
strlcpy((char *)userinfo.user_name, argv[0], sizeof(userinfo.user_name));
if (c->opt_flags == 0)
c->opt_flags = 0x21;
@ -969,7 +969,7 @@ static int rap_group_add(struct net_context *c, int argc, const char **argv)
return -1;
/* BB check for length 21 or smaller explicitly ? BB */
safe_strcpy((char *)grinfo.group_name, argv[0], sizeof(grinfo.group_name)-1);
strlcpy((char *)grinfo.group_name, argv[0], sizeof(grinfo.group_name));
grinfo.reserved1 = '\0';
grinfo.comment = smb_xstrdup(c->opt_comment ? c->opt_comment : "");

View File

@ -194,7 +194,7 @@ static bool fillup_pw_field(const char *lp_template,
if (!templ)
return False;
safe_strcpy(out, templ, sizeof(fstring) - 1);
strlcpy(out, templ, sizeof(fstring));
TALLOC_FREE(templ);
return True;

View File

@ -60,8 +60,8 @@ bool fill_grent(TALLOC_CTX *mem_ctx, struct winbindd_gr *gr,
/* Group name and password */
safe_strcpy(gr->gr_name, full_group_name, sizeof(gr->gr_name) - 1);
safe_strcpy(gr->gr_passwd, "x", sizeof(gr->gr_passwd) - 1);
strlcpy(gr->gr_name, full_group_name, sizeof(gr->gr_name));
strlcpy(gr->gr_passwd, "x", sizeof(gr->gr_passwd));
return True;
}

View File

@ -1514,8 +1514,8 @@ enum winbindd_result winbindd_dual_pam_auth(struct winbindd_domain *domain,
fstr_sprintf( domain_user, "%s%c%s", name_domain,
*lp_winbind_separator(),
name_user );
safe_strcpy( state->request->data.auth.user, domain_user,
sizeof(state->request->data.auth.user)-1 );
strlcpy( state->request->data.auth.user, domain_user,
sizeof(state->request->data.auth.user));
}
if (!domain->online) {

View File

@ -473,8 +473,8 @@ static void add_to_do_list_queue(const char* entry)
}
if (do_list_queue)
{
safe_strcpy(do_list_queue + do_list_queue_end, entry,
do_list_queue_size - do_list_queue_end - 1);
strlcpy(do_list_queue + do_list_queue_end, entry ? entry : "",
do_list_queue_size - do_list_queue_end);
do_list_queue_end = new_end;
DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n",
entry, (int)do_list_queue_start, (int)do_list_queue_end));

View File

@ -175,7 +175,7 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask,
count++;
safe_strcpy(res1, "---", sizeof(res1)-1);
strlcpy(res1, "---", sizeof(res1));
state.mem_ctx = mem_ctx;
@ -189,7 +189,7 @@ static void testpair(TALLOC_CTX *mem_ctx, struct smbcli_state *cli, char *mask,
resultp = res1;
short_name = talloc_strdup(mem_ctx, "");
get_real_name(mem_ctx, cli, &long_name, &short_name);
safe_strcpy(res1, "---", sizeof(res1)-1);
strlcpy(res1, "---", sizeof(res1));
smbcli_list_new(cli->tree, mask,
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,
RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO,

View File

@ -104,7 +104,7 @@ struct wbsrv_connection {
#define WBSRV_SAMBA3_SET_STRING(dest, src) do { \
memset(dest, 0, sizeof(dest));\
safe_strcpy(dest, src, sizeof(dest)-1);\
strlcpy((dest), (src) ? (src) : "", sizeof(dest));\
} while(0)
/*