From 8380835fc6de38706d9af29dc7f0fa4cec4f9c90 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 4 May 2011 11:38:26 -0700 Subject: [PATCH] Fix warning messages caused by addition of null check in fstrcpy macro. --- source3/client/client.c | 4 ++-- source3/groupdb/mapping.c | 4 ++-- source3/libnet/libnet_dssync_passdb.c | 12 ++++++------ source3/libnet/libnet_samsync_passdb.c | 10 +++++----- source3/nmbd/nmbd_browsesync.c | 6 ++++-- source3/nmbd/nmbd_incomingdgrams.c | 6 +++--- source3/nmbd/nmbd_workgroupdb.c | 2 +- source3/printing/lpq_parse.c | 3 ++- source3/rpc_server/spoolss/srv_spoolss_nt.c | 2 +- source3/smbd/password.c | 6 +++--- source3/smbd/trans2.c | 4 ++-- source3/torture/locktest.c | 4 ++-- source3/utils/net_groupmap.c | 10 +++++----- source3/utils/net_rpc.c | 6 +++--- source3/utils/smbpasswd.c | 4 ++-- source3/winbindd/idmap_hash/mapfile.c | 4 ++-- source3/winbindd/wb_fill_pwent.c | 4 +++- source3/winbindd/winbindd_cm.c | 2 +- source3/winbindd/winbindd_wins.c | 16 ++++++++++------ 19 files changed, 59 insertions(+), 50 deletions(-) diff --git a/source3/client/client.c b/source3/client/client.c index 75d57165cf8..836d1016be1 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -5046,9 +5046,9 @@ static int do_message_op(struct user_auth_info *a_info) make_nmb_name(&calling, calling_name, 0x0); make_nmb_name(&called , desthost, name_type); - fstrcpy(server_name, desthost); + strlcpy(server_name, desthost,sizeof(server_name)); snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type); - fstrcat(server_name, name_type_hex); + strlcat(server_name, name_type_hex,sizeof(server_name)); zero_sockaddr(&ss); if (have_ip) diff --git a/source3/groupdb/mapping.c b/source3/groupdb/mapping.c index 3646e04d0a3..d35f3c5f34d 100644 --- a/source3/groupdb/mapping.c +++ b/source3/groupdb/mapping.c @@ -777,8 +777,8 @@ NTSTATUS pdb_create_builtin_alias(uint32 rid) map.gid = gid; sid_copy(&map.sid, &sid); map.sid_name_use = SID_NAME_ALIAS; - fstrcpy(map.nt_name, groupname); - fstrcpy(map.comment, ""); + strlcpy(map.nt_name, groupname, sizeof(map.nt_name)); + strlcpy(map.comment, "", sizeof(map.comment)); status = pdb_add_group_mapping_entry(&map); diff --git a/source3/libnet/libnet_dssync_passdb.c b/source3/libnet/libnet_dssync_passdb.c index ab347567f14..7380efabb8a 100644 --- a/source3/libnet/libnet_dssync_passdb.c +++ b/source3/libnet/libnet_dssync_passdb.c @@ -1531,11 +1531,11 @@ static NTSTATUS handle_alias_object(struct dssync_passdb *pctx, map.sid_name_use = SID_NAME_ALIAS; } - fstrcpy(map.nt_name, name); + strlcpy(map.nt_name, name, sizeof(map.nt_name)); if (description) { - fstrcpy(map.comment, comment); + strlcpy(map.comment, comment, sizeof(map.comment)); } else { - fstrcpy(map.comment, ""); + strlcpy(map.comment, "", sizeof(map.comment)); } if (insert) @@ -1636,11 +1636,11 @@ static NTSTATUS handle_group_object(struct dssync_passdb *pctx, map.gid = grp->gr_gid; map.sid = group_sid; map.sid_name_use = SID_NAME_DOM_GRP; - fstrcpy(map.nt_name, name); + strlcpy(map.nt_name, name, sizeof(map.nt_name)); if (description) { - fstrcpy(map.comment, comment); + strlcpy(map.comment, comment, sizeof(map.comment)); } else { - fstrcpy(map.comment, ""); + strlcpy(map.comment, "", sizeof(map.comment)); } if (insert) diff --git a/source3/libnet/libnet_samsync_passdb.c b/source3/libnet/libnet_samsync_passdb.c index b579723f6fd..d8928c85a68 100644 --- a/source3/libnet/libnet_samsync_passdb.c +++ b/source3/libnet/libnet_samsync_passdb.c @@ -428,11 +428,11 @@ static NTSTATUS fetch_group_info(TALLOC_CTX *mem_ctx, map.gid = grp->gr_gid; map.sid = group_sid; map.sid_name_use = SID_NAME_DOM_GRP; - fstrcpy(map.nt_name, name); + strlcpy(map.nt_name, name, sizeof(map.nt_name)); if (r->description.string) { - fstrcpy(map.comment, comment); + strlcpy(map.comment, comment, sizeof(map.comment)); } else { - fstrcpy(map.comment, ""); + strlcpy(map.comment, "", sizeof(map.comment)); } if (insert) @@ -617,8 +617,8 @@ static NTSTATUS fetch_alias_info(TALLOC_CTX *mem_ctx, else map.sid_name_use = SID_NAME_ALIAS; - fstrcpy(map.nt_name, name); - fstrcpy(map.comment, comment); + strlcpy(map.nt_name, name, sizeof(map.nt_name)); + strlcpy(map.comment, comment, sizeof(map.comment)); if (insert) pdb_add_group_mapping_entry(&map); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 4a6f9f2d47d..1a262e4728e 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -435,7 +435,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub if(!(nb_flags & NB_GROUP) && (name_type == 0x00) && server_name[0] == 0) { /* this is almost certainly the server netbios name */ - unstrcpy(server_name, qname); + strlcpy(server_name, qname, sizeof(server_name)); continue; } @@ -461,7 +461,9 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub return; /* remember who the master is */ - unstrcpy(work->local_master_browser_name, server_name); + strlcpy(work->local_master_browser_name, + server_name, + sizeof(work->local_master_browser_name)); make_nmb_name(&nmbname, server_name, 0x20); work->dmb_name = nmbname; work->dmb_addr = from_ip; diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 6993e183583..d3b9d3d439b 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -172,7 +172,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p /* Update the record. */ servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; update_server_ttl( servrec, ttl); - fstrcpy(servrec->serv.comment,comment); + strlcpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)); } } else { /* @@ -338,7 +338,7 @@ a local master browser for workgroup %s and we think we are master. Forcing elec /* Update the record. */ servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; update_server_ttl(servrec, ttl); - fstrcpy(servrec->serv.comment,comment); + strlcpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)); } set_workgroup_local_master_browser_name( work, server_name ); @@ -512,7 +512,7 @@ originate from OS/2 Warp client. Ignoring packet.\n")); /* Update the record. */ servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; update_server_ttl( servrec, ttl); - fstrcpy(servrec->serv.comment,comment); + strlcpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)); } } else { /* diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 5ce10e64d46..819d5048ad1 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -52,7 +52,7 @@ static void name_to_unstring(unstring unname, const char *name) if (errno == E2BIG) { unstring tname; pull_ascii_nstring(tname, sizeof(tname), nname); - unstrcpy(unname, tname); + strlcpy(unname, tname, sizeof(nname)); DEBUG(0,("name_to_nstring: workgroup name %s is too long. Truncating to %s\n", name, tname)); } else { diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index 16b9b09fef3..9104497f9f6 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -801,8 +801,9 @@ static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first) fstring tmp; char *p = strrchr_m(tok[6],'/'); if (p) { + size_t len = strlen(tok[6])+1; fstrcpy(tmp,p+1); - fstrcpy(tok[6],tmp); + strlcpy(tok[6],tmp, len); } } diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c index 02587cae0dd..c50e2845936 100644 --- a/source3/rpc_server/spoolss/srv_spoolss_nt.c +++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c @@ -727,7 +727,7 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx, DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname)); - fstrcpy(Printer->sharename, sname); + strlcpy(Printer->sharename, sname, sizeof(Printer->sharename)); return WERR_OK; } diff --git a/source3/smbd/password.c b/source3/smbd/password.c index 54746c3f565..34384342afb 100644 --- a/source3/smbd/password.c +++ b/source3/smbd/password.c @@ -644,7 +644,7 @@ bool authorise_login(struct smbd_server_connection *sconn, get_session_workgroup(sconn), user2,password)) { ok = True; - fstrcpy(user,user2); + strlcpy(user,user2,sizeof(user)); DEBUG(3,("authorise_login: ACCEPTED: session " "list username (%s) and given " "password ok\n", user)); @@ -695,7 +695,7 @@ bool authorise_login(struct smbd_server_connection *sconn, get_session_workgroup(sconn), user2,password)) { ok = True; - fstrcpy(user,user2); + strlcpy(user,user2,sizeof(user)); DEBUG(3,("authorise_login: ACCEPTED: " "user list username and " "given password ok (%s)\n", @@ -714,7 +714,7 @@ bool authorise_login(struct smbd_server_connection *sconn, fstrcpy(guestname,lp_guestaccount()); guest_pw = Get_Pwnam_alloc(talloc_tos(), guestname); if (guest_pw != NULL) { - fstrcpy(user,guestname); + strlcpy(user,guestname,sizeof(user)); ok = True; DEBUG(3,("authorise_login: ACCEPTED: guest account " "and guest ok (%s)\n", user)); diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 39e653afaed..7c8b43c10c0 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -388,7 +388,7 @@ static unsigned int fill_ea_buffer(TALLOC_CTX *mem_ctx, char *pdata, unsigned in SCVAL(p,0,ea_list->ea.flags); SCVAL(p,1,dos_namelen); SSVAL(p,2,ea_list->ea.value.length); - fstrcpy(p+4, dos_ea_name); + strlcpy(p+4, dos_ea_name, dos_namelen+1); memcpy( p + 4 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length); total_data_size -= 4 + dos_namelen + 1 + ea_list->ea.value.length; @@ -452,7 +452,7 @@ static NTSTATUS fill_ea_chained_buffer(TALLOC_CTX *mem_ctx, SCVAL(p, 0x04, ea_list->ea.flags); SCVAL(p, 0x05, dos_namelen); SSVAL(p, 0x06, ea_list->ea.value.length); - fstrcpy((char *)(p+0x08), dos_ea_name); + strlcpy((char *)(p+0x08), dos_ea_name, dos_namelen+1); memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length); total_data_size -= this_size; diff --git a/source3/torture/locktest.c b/source3/torture/locktest.c index 27e3a131335..242099092b6 100644 --- a/source3/torture/locktest.c +++ b/source3/torture/locktest.c @@ -232,8 +232,8 @@ static struct cli_state *connect_one(char *share, int snum) } if (got_pass == 1) { - fstrcpy(password[1], password[0]); - fstrcpy(username[1], username[0]); + strlcpy(password[1], password[0],sizeof(password[1])); + strlcpy(username[1], username[0],sizeof(username[1])); } status = cli_session_setup(c, username[snum], diff --git a/source3/utils/net_groupmap.c b/source3/utils/net_groupmap.c index 818905e122f..9145093f52d 100644 --- a/source3/utils/net_groupmap.c +++ b/source3/utils/net_groupmap.c @@ -130,7 +130,7 @@ static int net_groupmap_list(struct net_context *c, int argc, const char **argv) GROUP_MAP map; if ( sid_string[0] ) - fstrcpy( ntgroup, sid_string); + strlcpy(ntgroup, sid_string, sizeof(ntgroup)); if (!get_sid_from_input(&sid, ntgroup)) { return -1; @@ -324,7 +324,7 @@ static int net_groupmap_add(struct net_context *c, int argc, const char **argv) } if (!ntgroup[0] ) - fstrcpy( ntgroup, unixgrp ); + strlcpy(ntgroup, unixgrp, sizeof(ntgroup)); if (!NT_STATUS_IS_OK(add_initial_entry(gid, string_sid, sid_type, ntgroup, ntcomment))) { d_fprintf(stderr, _("adding entry for group %s failed!\n"), ntgroup); @@ -457,10 +457,10 @@ static int net_groupmap_modify(struct net_context *c, int argc, const char **arg /* Change comment if new one */ if ( ntcomment[0] ) - fstrcpy( map.comment, ntcomment ); + strlcpy(map.comment, ntcomment, sizeof(map.comment)); if ( ntgroup[0] ) - fstrcpy( map.nt_name, ntgroup ); + strlcpy(map.nt_name, ntgroup, sizeof(map.nt_name)); if ( unixgrp[0] ) { gid = nametogid( unixgrp ); @@ -528,7 +528,7 @@ static int net_groupmap_delete(struct net_context *c, int argc, const char **arg /* give preference to the SID if we have that */ if ( sid_string[0] ) - fstrcpy( ntgroup, sid_string ); + strlcpy(ntgroup, sid_string, sizeof(ntgroup)); if ( !get_sid_from_input(&sid, ntgroup) ) { d_fprintf(stderr, _("Unable to resolve group %s to a SID\n"), diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index a3657262c4d..43398524ec0 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -3763,8 +3763,8 @@ static NTSTATUS copy_fn(const char *mnt, struct file_info *f, } /* search below that directory */ - fstrcpy(new_mask, dir); - fstrcat(new_mask, "\\*"); + strlcpy(new_mask, dir, sizeof(new_mask)); + strlcat(new_mask, "\\*", sizeof(new_mask)); old_dir = local_state->cwd; local_state->cwd = dir; @@ -4802,7 +4802,7 @@ static bool get_user_tokens_from_file(FILE *f, token = &((*tokens)[*num_tokens-1]); - fstrcpy(token->name, line); + strlcpy(token->name, line, sizeof(token->name)); token->token.num_sids = 0; token->token.sids = NULL; continue; diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index ada057c2479..8c780498b5b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -378,7 +378,7 @@ static int process_root(int local_flags) */ slprintf(buf, sizeof(buf)-1, "%s$", user_name); - fstrcpy(user_name, buf); + strlcpy(user_name, buf, sizeof(user_name)); } else if (local_flags & LOCAL_INTERDOM_ACCOUNT) { static fstring buf; @@ -395,7 +395,7 @@ static int process_root(int local_flags) /* prepare uppercased and '$' terminated username */ slprintf(buf, sizeof(buf) - 1, "%s$", user_name); - fstrcpy(user_name, buf); + strlcpy(user_name, buf, sizeof(user_name)); } else { diff --git a/source3/winbindd/idmap_hash/mapfile.c b/source3/winbindd/idmap_hash/mapfile.c index 28280590934..1183328a3f1 100644 --- a/source3/winbindd/idmap_hash/mapfile.c +++ b/source3/winbindd/idmap_hash/mapfile.c @@ -87,8 +87,8 @@ static bool mapfile_read_line(fstring key, fstring value) *p = '\0'; p++; - fstrcpy(key, buffer); - fstrcpy(value, p); + strlcpy(key, buffer, sizeof(key)); + strlcpy(value, p, sizeof(value)); /* Eat whitespace */ diff --git a/source3/winbindd/wb_fill_pwent.c b/source3/winbindd/wb_fill_pwent.c index 37d45357db7..6fad5f43605 100644 --- a/source3/winbindd/wb_fill_pwent.c +++ b/source3/winbindd/wb_fill_pwent.c @@ -131,7 +131,9 @@ static void wb_fill_pwent_sid2gid_done(struct tevent_req *subreq) true); } - fstrcpy(state->pw->pw_name, output_username); + strlcpy(state->pw->pw_name, + output_username, + sizeof(state->pw->pw_name)); fstrcpy(state->pw->pw_gecos, state->info->full_name); /* Home directory and shell */ diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c index bf877429e9c..f5a9e73905d 100644 --- a/source3/winbindd/winbindd_cm.c +++ b/source3/winbindd/winbindd_cm.c @@ -1549,7 +1549,7 @@ static NTSTATUS cm_open_connection(struct winbindd_domain *domain, return NT_STATUS_UNSUCCESSFUL; } if (dcip_to_name(mem_ctx, domain, &ss, saf_name )) { - fstrcpy( domain->dcname, saf_name ); + strlcpy(domain->dcname, saf_name, sizeof(domain->dcname)); } else { winbind_add_failed_connection_entry( domain, saf_servername, diff --git a/source3/winbindd/winbindd_wins.c b/source3/winbindd/winbindd_wins.c index e1beb1d80bf..5ac61094112 100644 --- a/source3/winbindd/winbindd_wins.c +++ b/source3/winbindd/winbindd_wins.c @@ -140,7 +140,9 @@ void winbindd_wins_byip(struct winbindd_cli_state *state) response[strlen(response)-1] = '\n'; TALLOC_FREE(status); } - fstrcpy(state->response->data.winsresp,response); + strlcpy(state->response->data.winsresp, + response, + sizeof(state->response->data.winsresp)); request_ok(state); } @@ -181,8 +183,8 @@ void winbindd_wins_byname(struct winbindd_cli_state *state) response[strlen(response)-1] = ' '; } } - fstrcat(response,addr); - fstrcat(response,"\t"); + strlcat(response,addr,sizeof(response)); + strlcat(response,"\t",sizeof(response)); } size = strlen(state->request->data.winsreq) + strlen(response); if (size > maxlen) { @@ -190,15 +192,17 @@ void winbindd_wins_byname(struct winbindd_cli_state *state) request_error(state); return; } - fstrcat(response,state->request->data.winsreq); - fstrcat(response,"\n"); + strlcat(response,state->request->data.winsreq,sizeof(response)); + strlcat(response,"\n",sizeof(response)); TALLOC_FREE(ip_list); } else { request_error(state); return; } - fstrcpy(state->response->data.winsresp,response); + strlcpy(state->response->data.winsresp, + response, + sizeof(state->response->data.winsresp)); request_ok(state); } -- 2.34.1