Cleanup/security fix: do not use strcpy (at least in new code).
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 18 Aug 2016 13:45:20 +0000 (15:45 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 18 Aug 2016 14:06:11 +0000 (16:06 +0200)
This function is only really secure in a very limited amount of cases,
and can especially bite you later if you change some buffer sizes...
So not worth bothering with it, just always use BLI_strncpy instead.

source/blender/blenkernel/intern/gpencil.c
source/blender/blenloader/intern/versioning_270.c
source/blender/editors/gpencil/gpencil_data.c
source/blender/editors/gpencil/gpencil_edit.c
source/blender/editors/gpencil/gpencil_paint.c
source/blender/makesrna/intern/rna_gpencil.c

index e4bac0a947aea0bb60931c4aceb64023b81c3c83..2242113b79bd612a61115d006dfb8b26a8bebc28 100644 (file)
@@ -1268,7 +1268,7 @@ void BKE_gpencil_palettecolor_changename(bGPdata *gpd, char *oldname, const char
                for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
                        for (gps = gpf->strokes.first; gps; gps = gps->next) {
                                if (STREQ(gps->colorname, oldname)) {
-                                       strcpy(gps->colorname, newname);
+                                       BLI_strncpy(gps->colorname, newname, sizeof(gps->colorname));
                                }
                        }
                }
index d735f099dc0a24d61dd25e87ffab4acbeef78ccf..f6ac42c194113e8d63b0f6f1f1b76abab8783837 100644 (file)
@@ -1318,7 +1318,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                                                        for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
                                                                for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
                                                                        /* set stroke to palette and force recalculation */
-                                                                       strcpy(gps->colorname, gpl->info);
+                                                                       BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname));
                                                                        gps->palcolor = NULL;
                                                                        gps->flag |= GP_STROKE_RECALC_COLOR;
                                                                        gps->thickness = gpl->thickness;
index 8733c7bf5a820d1c3552125bef689f6952d204d0..2aa6d30c1144a60531b5a6db4c0e5baa91b3b131 100644 (file)
@@ -883,7 +883,7 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *UNUSED(op))
 
                                        /* asign new color (only if different) */
                                        if (STREQ(gps->colorname, color->info) == false) {
-                                               strcpy(gps->colorname, color->info);
+                                               BLI_strncpy(gps->colorname, color->info, sizeof(gps->colorname));
                                                gps->flag |= GP_STROKE_RECALC_COLOR;
                                        }
                                }
@@ -1271,7 +1271,7 @@ static int gp_stroke_join_exec(bContext *C, wmOperator *op)
                                                /* if new, set current color */
                                                if (type == GP_STROKE_JOINCOPY) {
                                                        new_stroke->palcolor = palcolor;
-                                                       strcpy(new_stroke->colorname, palcolor->info);
+                                                       BLI_strncpy(new_stroke->colorname, palcolor->info, sizeof(new_stroke->colorname));
                                                        new_stroke->flag |= GP_STROKE_RECALC_COLOR;
                                                }
                                        }
index b298769c6dcb4be5151ddbca1b44524b2d86e5c1..e58178bf2a7fe9659f7f10b8459affd91283ad65 100644 (file)
@@ -207,7 +207,7 @@ static void gp_duplicate_points(const bGPDstroke *gps, ListBase *new_strokes, co
                                
                                /* make a stupid copy first of the entire stroke (to get the flags too) */
                                gpsd = MEM_dupallocN(gps);
-                               strcpy(gpsd->tmp_layerinfo, layername); /* saves original layer name */
+                               BLI_strncpy(gpsd->tmp_layerinfo, layername, sizeof(gpsd->tmp_layerinfo)); /* saves original layer name */
                                
                                /* initialize triangle memory - will be calculated on next redraw */
                                gpsd->triangles = NULL;
@@ -266,7 +266,7 @@ static int gp_duplicate_exec(bContext *C, wmOperator *op)
                                        
                                        /* make direct copies of the stroke and its points */
                                        gpsd = MEM_dupallocN(gps);
-                                       strcpy(gpsd->tmp_layerinfo, gpl->info);
+                                       BLI_strncpy(gpsd->tmp_layerinfo, gpl->info, sizeof(gpsd->tmp_layerinfo));
                                        gpsd->points = MEM_dupallocN(gps->points);
 
                                        /* triangle information - will be calculated on next redraw */
@@ -386,7 +386,7 @@ static int gp_strokes_copy_exec(bContext *C, wmOperator *op)
                                        
                                        /* make direct copies of the stroke and its points */
                                        gpsd = MEM_dupallocN(gps);
-                                       strcpy(gpsd->tmp_layerinfo, gpl->info); /* saves original layer name */
+                                       BLI_strncpy(gpsd->tmp_layerinfo, gpl->info, sizeof(gpsd->tmp_layerinfo)); /* saves original layer name */
                                        gpsd->points = MEM_dupallocN(gps->points);
                                        
                                        /* triangles cache - will be recalculated on next redraw */
index e7e39a8579219c9361b7815908997ff8e0c48fb8..dacdc0cf7778e77b51bba98ea5ea2c470104feb4 100644 (file)
@@ -924,7 +924,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
        bGPDpalette *palette = BKE_gpencil_palette_getactive(p->gpd);
        bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
        gps->palcolor = palcolor;
-       strcpy(gps->colorname, palcolor->info);
+       BLI_strncpy(gps->colorname, palcolor->info, sizeof(gps->colorname));
 
        /* add stroke to frame, usually on tail of the listbase, but if on back is enabled the stroke is added on listbase head 
        * because the drawing order is inverse and the head stroke is the first to draw. This is very useful for artist
index 48d7dcfa2e409938b7738d94c8cd27b2b3f2efa7..3ecaec75c77bb0c933fcb5816d02e9552b712b3f 100644 (file)
@@ -483,7 +483,7 @@ static bGPDstroke *rna_GPencil_stroke_new(bGPDframe *frame, const char *colornam
 {
        bGPDstroke *stroke = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
        if (colorname) {
-               strcpy(stroke->colorname, colorname);
+               BLI_strncpy(stroke->colorname, colorname, sizeof(stroke->colorname));
        }
        stroke->palcolor = NULL;
        stroke->flag |= GP_STROKE_RECALC_COLOR;