[PATCH] Replace StrnCpy with strlcpy
Volker Lendecke
Volker.Lendecke at SerNet.DE
Mon Jan 7 14:35:10 UTC 2019
Hi!
Review appreciated!
Thanks, Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: 0551-370000-0, mailto:kontakt at sernet.de
Gesch.F.: Dr. Johannes Loxen und Reinhild Jung
AG Göttingen: HR-B 2816 - http://www.sernet.de
-------------- next part --------------
From 2a127c53c60b0e85632256e687001ee3463e561e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 31 Dec 2018 07:14:48 +0100
Subject: [PATCH 1/4] libsmb: Use strlcpy instead of StrnCpy
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/libsmb/namequery.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 6564f4869ea..abeed972403 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -274,7 +274,7 @@ static struct node_status *parse_node_status(TALLOC_CTX *mem_ctx, char *p,
p++;
for (i=0;i< *num_names;i++) {
- StrnCpy(ret[i].name,p,15);
+ strlcpy(ret[i].name,p,16);
trim_char(ret[i].name,'\0',' ');
ret[i].type = CVAL(p,15);
ret[i].flags = p[16];
--
2.11.0
From 043d7c7d42cd85971253600dc1ec46e132e32ce2 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 31 Dec 2018 07:15:03 +0100
Subject: [PATCH 2/4] nmbd: Use strlcpy instead of StrnCpy
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/nmbd/nmbd_incomingdgrams.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c
index 6fedcfd0255..e8980055b19 100644
--- a/source3/nmbd/nmbd_incomingdgrams.c
+++ b/source3/nmbd/nmbd_incomingdgrams.c
@@ -607,7 +607,7 @@ static void send_backup_list_response(struct subnet_record *subrec,
if(!(servrec->serv.type & SV_TYPE_BACKUP_BROWSER))
continue;
- StrnCpy(p, servrec->serv.name, 15);
+ strlcpy(p, servrec->serv.name, 16);
strupper_m(p);
count++;
--
2.11.0
From 874bf9f38fa360c6c2e699758b48859ed5672222 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 31 Dec 2018 07:15:21 +0100
Subject: [PATCH 3/4] smbd: Use strlcpy instead of StrnCpy
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/lanman.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c
index dcc7f916d6e..9637194f697 100644
--- a/source3/smbd/lanman.c
+++ b/source3/smbd/lanman.c
@@ -364,7 +364,7 @@ static int package(struct pack_desc *p, ...)
{
char *s = va_arg(args,char*);
if (p->buflen >= needed) {
- StrnCpy(p->structbuf,s?s:"",needed-1);
+ strlcpy(p->structbuf,s?s:"",needed);
}
}
break;
--
2.11.0
From 13d60b9ee4f42446d2e263c90e41642d2a3509d0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 31 Dec 2018 07:16:29 +0100
Subject: [PATCH 4/4] lib: Remove StrnCpy
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/proto.h | 1 -
source3/lib/util_str.c | 26 --------------------------
2 files changed, 27 deletions(-)
diff --git a/source3/include/proto.h b/source3/include/proto.h
index d2f9986c244..c92d9921d6e 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -574,7 +574,6 @@ size_t str_charnum(const char *s);
bool trim_char(char *s,char cfront,char cback);
bool strhasupper(const char *s);
bool strhaslower(const char *s);
-char *StrnCpy(char *dest,const char *src,size_t n);
bool in_list(const char *s, const char *list, bool casesensitive);
void fstring_sub(char *s,const char *pattern,const char *insert);
char *realloc_string_sub2(char *string,
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index eb36478d8a2..8568af46c17 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -171,32 +171,6 @@ bool trim_char(char *s,char cfront,char cback)
}
/**
- Like strncpy but always null terminates. Make sure there is room!
- The variable n should always be one less than the available size.
-**/
-char *StrnCpy(char *dest,const char *src,size_t n)
-{
- char *d = dest;
-
- if (!dest) {
- smb_panic("ERROR: NULL dest in StrnCpy");
- }
-
- if (!src) {
- *dest = 0;
- return(dest);
- }
-
- while (n-- && (*d = *src)) {
- d++;
- src++;
- }
-
- *d = 0;
- return(dest);
-}
-
-/**
Check if a string is part of a list.
**/
--
2.11.0
More information about the samba-technical
mailing list