changeset 2423:87b7fbed8609 libavcodec

dissallow sprintf
author michael
date Wed, 12 Jan 2005 00:59:42 +0000
parents 18b8b2dcc037
children 35ca0ef0c279
files apiexample.c common.h huffyuv.c imgresample.c mpegaudiodec.c ratecontrol.c utils.c
diffstat 7 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/apiexample.c	Wed Jan 12 00:16:25 2005 +0000
+++ b/apiexample.c	Wed Jan 12 00:59:42 2005 +0000
@@ -415,7 +415,8 @@
     AVCodec* codec = avcodec_find_encoder_by_name((argc > 1) ? argv[2] : "mpeg4");
     const AVOption* c;
     AVCodecContext* avctx;
-    char* def = av_malloc(5000);
+#define DEF_SIZE 5000
+    char* def = av_malloc(DEF_SIZE);
     const char* col = "";
     int i = 0;
 
@@ -449,16 +450,16 @@
 		       "unknown??", c->name);
 		switch (t) {
 		case FF_OPT_TYPE_BOOL:
-		    i += sprintf(def + i, "%s%s=%s",
+		    i += snprintf(def + i, DEF_SIZE-i, "%s%s=%s",
 				 col, c->name,
 				 c->defval != 0. ? "on" : "off");
 		    break;
 		case FF_OPT_TYPE_DOUBLE:
-		    i += sprintf(def + i, "%s%s=%f",
+		    i += snprintf(def + i, DEF_SIZE-i, "%s%s=%f",
 				 col, c->name, c->defval);
 		    break;
 		case FF_OPT_TYPE_INT:
-		    i += sprintf(def + i, "%s%s=%d",
+		    i += snprintf(def + i, DEF_SIZE-i, "%s%s=%d",
 				 col, c->name, (int) c->defval);
 		    break;
 		case FF_OPT_TYPE_STRING:
@@ -467,7 +468,7 @@
 			char* f = strchr(d, ',');
 			if (f)
                             *f = 0;
-			i += sprintf(def + i, "%s%s=%s",
+			i += snprintf(def + i, DEF_SIZE-i, "%s%s=%s",
 				     col, c->name, d);
                         av_free(d);
 		    }
--- a/common.h	Wed Jan 12 00:16:25 2005 +0000
+++ b/common.h	Wed Jan 12 00:59:42 2005 +0000
@@ -499,6 +499,7 @@
 #define time time_is_forbidden_due_to_security_issues
 #define rand rand_is_forbidden_due_to_state_trashing
 #define srand srand_is_forbidden_due_to_state_trashing
+#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
 #if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
 #define printf please_use_av_log
 #define fprintf please_use_av_log
--- a/huffyuv.c	Wed Jan 12 00:16:25 2005 +0000
+++ b/huffyuv.c	Wed Jan 12 00:59:42 2005 +0000
@@ -1170,13 +1170,14 @@
     if((s->flags&CODEC_FLAG_PASS1) && (s->picture_number&31)==0){
         int j;
         char *p= avctx->stats_out;
+        char *end= p + 1024*30;
         for(i=0; i<3; i++){
             for(j=0; j<256; j++){
-                sprintf(p, "%llu ", s->stats[i][j]);
+                snprintf(p, end-p, "%llu ", s->stats[i][j]);
                 p+= strlen(p);
                 s->stats[i][j]= 0;
             }
-            sprintf(p, "\n");
+            snprintf(p, end-p, "\n");
             p++;
         }
     }else{
--- a/imgresample.c	Wed Jan 12 00:16:25 2005 +0000
+++ b/imgresample.c	Wed Jan 12 00:59:42 2005 +0000
@@ -730,7 +730,7 @@
                            img + 50 * XSIZE, XSIZE, XSIZE, YSIZE - 100);
         img_resample_close(s);
 
-        sprintf(buf, "/tmp/out%d.pgm", i);
+        snprintf(buf, sizeof(buf), "/tmp/out%d.pgm", i);
         save_pgm(buf, img1, xsize, ysize);
     }
 
--- a/mpegaudiodec.c	Wed Jan 12 00:16:25 2005 +0000
+++ b/mpegaudiodec.c	Wed Jan 12 00:59:42 2005 +0000
@@ -2130,7 +2130,7 @@
     
     f = files[fnum];
     if (!f) {
-        sprintf(buf, "/tmp/out%d.%s.pcm", 
+        snprintf(buf, sizeof(buf), "/tmp/out%d.%s.pcm", 
                 fnum, 
 #ifdef USE_HIGHPRECISION
                 "hp"
--- a/ratecontrol.c	Wed Jan 12 00:16:25 2005 +0000
+++ b/ratecontrol.c	Wed Jan 12 00:59:42 2005 +0000
@@ -38,7 +38,7 @@
 static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num);
 
 void ff_write_pass1_stats(MpegEncContext *s){
-    sprintf(s->avctx->stats_out, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d;\n",
+    snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d;\n",
             s->current_picture_ptr->display_picture_number, s->current_picture_ptr->coded_picture_number, s->pict_type, 
             s->current_picture.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits, 
             s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count);
--- a/utils.c	Wed Jan 12 00:16:25 2005 +0000
+++ b/utils.c	Wed Jan 12 00:59:42 2005 +0000
@@ -762,7 +762,7 @@
                 strcpy(channels_str, "5:1");
                 break;
             default:
-                sprintf(channels_str, "%d channels", enc->channels);
+                snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels);
                 break;
         }
         if (enc->sample_rate) {