From 017e0c8d95fe8212b006e1c14aef8d96fed30674 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 May 2011 13:10:01 -0700 Subject: Fix simple uses of safe_strcpy -> strlcpy. Easy ones where we just remove -1. --- lib/util/fault.c | 2 +- lib/util/string_wrappers.h | 8 ++++---- lib/util/tests/str.c | 10 +++++----- libcli/auth/smbencrypt.c | 2 +- nsswitch/winbind_nss_config.h | 2 +- source3/nmbd/nmbd_sendannounce.c | 2 +- source3/torture/msgtest.c | 2 +- source3/utils/net_rap.c | 4 ++-- source3/winbindd/wb_fill_pwent.c | 2 +- source3/winbindd/winbindd_group.c | 4 ++-- source3/winbindd/winbindd_pam.c | 4 ++-- source4/client/client.c | 4 ++-- source4/torture/masktest.c | 4 ++-- source4/winbind/wb_server.h | 2 +- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/util/fault.c b/lib/util/fault.c index 086dc33545..708dc670d1 100644 --- a/lib/util/fault.c +++ b/lib/util/fault.c @@ -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)); diff --git a/lib/util/string_wrappers.h b/lib/util/string_wrappers.h index 75718e942b..4e4f3ec832 100644 --- a/lib/util/string_wrappers.h +++ b/lib/util/string_wrappers.h @@ -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 diff --git a/lib/util/tests/str.c b/lib/util/tests/str.c index b4c45e3751..f9f3abf731 100644 --- a/lib/util/tests/str.c +++ b/lib/util/tests/str.c @@ -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; diff --git a/libcli/auth/smbencrypt.c b/libcli/auth/smbencrypt.c index 366f6df3ad..c59bc515ba 100644 --- a/libcli/auth/smbencrypt.c +++ b/libcli/auth/smbencrypt.c @@ -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; } diff --git a/nsswitch/winbind_nss_config.h b/nsswitch/winbind_nss_config.h index 3e2ce68252..9231e3cf1b 100644 --- a/nsswitch/winbind_nss_config.h +++ b/nsswitch/winbind_nss_config.h @@ -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 */ diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index e04e1f6fe3..b389c02278 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -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); diff --git a/source3/torture/msgtest.c b/source3/torture/msgtest.c index 607d4c3bb1..c7fa3153d8 100644 --- a/source3/torture/msgtest.c +++ b/source3/torture/msgtest.c @@ -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;iopt_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 : ""); diff --git a/source3/winbindd/wb_fill_pwent.c b/source3/winbindd/wb_fill_pwent.c index 23057384c2..37d45357db 100644 --- a/source3/winbindd/wb_fill_pwent.c +++ b/source3/winbindd/wb_fill_pwent.c @@ -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; diff --git a/source3/winbindd/winbindd_group.c b/source3/winbindd/winbindd_group.c index a985fa254f..1e4ad5fa8a 100644 --- a/source3/winbindd/winbindd_group.c +++ b/source3/winbindd/winbindd_group.c @@ -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; } diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c index 412ec8370a..93c691b13b 100644 --- a/source3/winbindd/winbindd_pam.c +++ b/source3/winbindd/winbindd_pam.c @@ -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) { diff --git a/source4/client/client.c b/source4/client/client.c index 923a6f3a23..a226982296 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -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)); diff --git a/source4/torture/masktest.c b/source4/torture/masktest.c index bfd1aff5e8..9f156b807b 100644 --- a/source4/torture/masktest.c +++ b/source4/torture/masktest.c @@ -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, diff --git a/source4/winbind/wb_server.h b/source4/winbind/wb_server.h index f20bc0aa51..12dd1888ed 100644 --- a/source4/winbind/wb_server.h +++ b/source4/winbind/wb_server.h @@ -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) /* -- cgit