From: Steve Peters Date: Mon, 10 Jul 2006 17:23:02 +0000 (+0000) Subject: Convert some low hanging fruit to my_strlcpy/my_strlcat. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6fca0082ec4f3b34a0dabc78331bad8c22489dd2;p=p5sagit%2Fp5-mst-13.2.git Convert some low hanging fruit to my_strlcpy/my_strlcat. p4raw-id: //depot/perl@28533 --- diff --git a/doio.c b/doio.c index 1fcb165..29b5b19 100644 --- a/doio.c +++ b/doio.c @@ -1443,10 +1443,9 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) char *cmd; /* Make a copy so we can change it */ - const int cmdlen = strlen(incmd); - Newx(cmd, cmdlen+1, char); - strncpy(cmd, incmd, cmdlen); - cmd[cmdlen] = 0; + const Size_t cmdlen = strlen(incmd) + 1; + Newx(cmd, cmdlen, char); + my_strlcpy(cmd, incmd, cmdlen); while (*cmd && isSPACE(*cmd)) cmd++; diff --git a/mg.c b/mg.c index dec8588..168d456 100644 --- a/mg.c +++ b/mg.c @@ -1073,8 +1073,7 @@ Perl_magic_setenv(pTHX_ SV *sv, MAGIC *mg) Stat_t sbuf; int i = 0, j = 0; - strncpy(eltbuf, s, 255); - eltbuf[255] = 0; + my_strlcpy(eltbuf, s, sizeof(eltbuf)); elt = eltbuf; do { /* DCL$PATH may be a search list */ while (1) { /* as may dev portion of any element */ diff --git a/pp_sys.c b/pp_sys.c index 25deca1..a5028ba 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -3580,10 +3580,11 @@ S_dooneliner(pTHX_ const char *cmd, const char *filename) char *s; PerlIO *myfp; int anum = 1; + Size_t size = strlen(cmd) + (strlen(filename) * 2) + 10; - Newx(cmdline, strlen(cmd) + (strlen(filename) * 2) + 10, char); - strcpy(cmdline, cmd); - strcat(cmdline, " "); + Newx(cmdline, size, char); + my_strlcpy(cmdline, cmd, size); + my_strlcat(cmdline, " ", size); for (s = cmdline + strlen(cmdline); *filename; ) { *s++ = '\\'; *s++ = *filename++; diff --git a/toke.c b/toke.c index c6e00ef..f4e4499 100644 --- a/toke.c +++ b/toke.c @@ -499,7 +499,7 @@ S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen) dVAR; HV * const hinthv = GvHV(PL_hintgv); char he_name[32] = "feature_"; - (void) strncpy(&he_name[8], name, 24); + (void) my_strlcpy(&he_name[8], name, 24); return (hinthv && hv_exists(hinthv, he_name, 8 + namelen)); } diff --git a/util.c b/util.c index 7a3be16..1bb7283 100644 --- a/util.c +++ b/util.c @@ -3022,7 +3022,7 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, if ((strlen(tmpbuf) + strlen(scriptname) + MAX_EXT_LEN) >= sizeof tmpbuf) continue; /* don't search dir with too-long name */ - strcat(tmpbuf, scriptname); + my_strlcat(tmpbuf, scriptname, sizeof(tmpbuf)); #else /* !VMS */ #ifdef DOSISH @@ -3054,11 +3054,10 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, len = strlen(scriptname); if (len+MAX_EXT_LEN+1 >= sizeof(tmpbuf)) break; - /* FIXME? Convert to memcpy */ - cur = strcpy(tmpbuf, scriptname); + cur = my_strlcpy(tmpbuf, scriptname, sizeof(tmpbuf)); } } while (extidx >= 0 && ext[extidx] /* try an extension? */ - && strcpy(tmpbuf+len, ext[extidx++])); + && my_strlcpy(tmpbuf+len, ext[extidx++], sizeof(tmpbuf) - len)); #endif } #endif @@ -3135,7 +3134,7 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, #ifdef SEARCH_EXTS } while ( retval < 0 /* not there */ && extidx>=0 && ext[extidx] /* try an extension? */ - && strcpy(tmpbuf+len, ext[extidx++]) + && my_strlcpy(tmpbuf+len, ext[extidx++], sizeof(tmpbuf) - len) ); #endif if (retval < 0)