@@ -121,7 +121,7 @@ int already_running(void)
121121 exit (1 );
122122 }
123123 ftruncate (fd , 0 );
124- sprintf (buf , "%ld" , (long )getpid ());
124+ snprintf (buf , sizeof ( buf ) , "%ld" , (long )getpid ());
125125 write (fd , buf , strlen (buf )+ 1 );
126126 return (0 );
127127}
@@ -203,7 +203,7 @@ void record_saveStatus(RecordContext_t* recCtx, RecordStatus_e recStatus)
203203 LOGE ( "can't lock %s: %s" , REC_dataFILE , strerror (errno ));
204204 }
205205 ftruncate (fd , 0 );
206- sprintf (buf , "%d" , recCtx -> status );
206+ snprintf (buf , sizeof ( buf ) , "%d" , recCtx -> status );
207207 write (fd , buf , strlen (buf )+ 1 );
208208 close (fd );
209209
@@ -354,13 +354,13 @@ int record_start(RecordContext_t* recCtx)
354354 char sFile [256 ];
355355 switch (recCtx -> params .fileNaming ) {
356356 case NAMING_CONTIGUOUS :
357- REC_filePathGet (sFile , recCtx -> params .packPath , REC_packPREFIX , nbFileIndex , recCtx -> params .packType );
357+ REC_filePathGet (sFile , sizeof ( sFile ), recCtx -> params .packPath , REC_packPREFIX , nbFileIndex , recCtx -> params .packType );
358358 break ;
359359 case NAMING_DATE : {
360360 const time_t t = time (0 );
361361 const struct tm * date = localtime (& t );
362- sprintf (dateString , "%04d%02d%02d-%02d%02d%02d" , date -> tm_year + 1900 , date -> tm_mon + 1 , date -> tm_mday , date -> tm_hour , date -> tm_min , date -> tm_sec );
363- sprintf (sFile , "%s%s.%s" , recCtx -> params .packPath , dateString , recCtx -> params .packType );
362+ snprintf (dateString , sizeof ( dateString ) , "%04d%02d%02d-%02d%02d%02d" , date -> tm_year + 1900 , date -> tm_mon + 1 , date -> tm_mday , date -> tm_hour , date -> tm_min , date -> tm_sec );
363+ snprintf (sFile , sizeof ( sFile ) , "%s%s.%s" , recCtx -> params .packPath , dateString , recCtx -> params .packType );
364364 break ;
365365 }
366366 }
@@ -429,7 +429,7 @@ int record_start(RecordContext_t* recCtx)
429429 strcpy (fileName , strrchr (sFile , '/' ) + 1 );
430430 av_dict_set (& ff -> ofmtContext -> metadata , "title" , fileName , 0 );
431431
432- sprintf (localDateString , "%04d-%02d-%02d %02d:%02d:%02d" , date -> tm_year + 1900 , date -> tm_mon + 1 , date -> tm_mday , date -> tm_hour , date -> tm_min , date -> tm_sec );
432+ snprintf (localDateString , sizeof ( localDateString ) , "%04d-%02d-%02d %02d:%02d:%02d" , date -> tm_year + 1900 , date -> tm_mon + 1 , date -> tm_mday , date -> tm_hour , date -> tm_min , date -> tm_sec );
433433 av_dict_set (& ff -> ofmtContext -> metadata , "date" , localDateString , 0 );
434434 }
435435
@@ -462,10 +462,10 @@ int record_start(RecordContext_t* recCtx)
462462
463463 switch (recCtx -> params .fileNaming ) {
464464 case NAMING_CONTIGUOUS :
465- REC_filePathGet (sFile , recCtx -> params .packPath , REC_packPREFIX , nbFileIndex , REC_packSnapTYPE );
465+ REC_filePathGet (sFile , sizeof ( sFile ), recCtx -> params .packPath , REC_packPREFIX , nbFileIndex , REC_packSnapTYPE );
466466 break ;
467467 case NAMING_DATE :
468- sprintf (sFile , "%s%s.%s" , recCtx -> params .packPath , dateString , REC_packSnapTYPE );
468+ snprintf (sFile , sizeof ( sFile ) , "%s%s.%s" , recCtx -> params .packPath , dateString , REC_packSnapTYPE );
469469 break ;
470470 }
471471 ret = record_takePicture (recCtx , sFile );
@@ -519,7 +519,7 @@ bool record_pack(RecordContext_t* recCtx)
519519 VencSpspps_t veHeader = { NULL , 0 };
520520 int nbFileIndex = recCtx -> nbFileIndex ;
521521 char sFile [256 ];
522- REC_filePathGet (sFile , recCtx -> params .packPath , REC_packPREFIX , nbFileIndex , recCtx -> params .packType );
522+ REC_filePathGet (sFile , sizeof ( sFile ), recCtx -> params .packPath , REC_packPREFIX , nbFileIndex , recCtx -> params .packType );
523523
524524 FFPack_t * ff = ffpack_openFile (sFile , NULL );
525525 if ( ff == NULL ) {
@@ -577,7 +577,7 @@ bool record_pack(RecordContext_t* recCtx)
577577
578578 pthread_mutex_unlock (& recCtx -> mutex );
579579
580- REC_filePathGet (sFile , recCtx -> params .packPath , REC_packPREFIX , nbFileIndex , REC_packSnapTYPE );
580+ REC_filePathGet (sFile , sizeof ( sFile ), recCtx -> params .packPath , REC_packPREFIX , nbFileIndex , REC_packSnapTYPE );
581581 record_takePicture (recCtx , sFile );
582582
583583 return true;
@@ -888,7 +888,7 @@ void record_checkConf(RecordContext_t* recCtx, char* confSet)
888888 readlink ("/proc/self/exe" , sTemp , MAX_pathLEN );
889889 p = strrchr (sTemp ,'/' );
890890 * p = '\0' ;
891- sprintf (recCtx -> confFile , "%s/%s" , sTemp , REC_confFILE );
891+ snprintf (recCtx -> confFile , MAX_pathLEN , "%s/%s" , sTemp , REC_confFILE );
892892 }
893893}
894894
0 commit comments