Convert some low hanging fruit to my_strlcpy/my_strlcat.
authorSteve Peters <steve@fisharerojo.org>
Mon, 10 Jul 2006 17:23:02 +0000 (17:23 +0000)
committerSteve Peters <steve@fisharerojo.org>
Mon, 10 Jul 2006 17:23:02 +0000 (17:23 +0000)
p4raw-id: //depot/perl@28533

doio.c
mg.c
pp_sys.c
toke.c
util.c

diff --git a/doio.c b/doio.c
index 1fcb165..29b5b19 100644 (file)
--- 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 (file)
--- 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 */
index 25deca1..a5028ba 100644 (file)
--- 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 (file)
--- 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 (file)
--- 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)