diff mbox series

[FFmpeg-devel] avutil/timecode: fix sscanf format string with garbage at the end

Message ID 1592666243-30479-1-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel] avutil/timecode: fix sscanf format string with garbage at the end | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Lance Wang June 20, 2020, 3:17 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavutil/timecode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nicolas George June 20, 2020, 3:35 p.m. UTC | #1
lance.lmwang@gmail.com (12020-06-20):
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavutil/timecode.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

I doubt this was actually tested.

Regards,
Lance Wang June 20, 2020, 3:51 p.m. UTC | #2
On Sat, Jun 20, 2020 at 05:35:23PM +0200, Nicolas George wrote:
> lance.lmwang@gmail.com (12020-06-20):
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavutil/timecode.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> I doubt this was actually tested.
I'm testing with below test.c, maybe I'm not catch what's your garbage in the
end. Please give one example for your str?

 lmwang@MacBook-Pro  ~  gcc -o test test.c
 lmwang@MacBook-Pro  ~  ./test
hh: 10, mm: 11, ss: 40, ff: 14
 lmwang@MacBook-Pro  ~  cat test.c
#include <string.h>
#include <stdio.h>

int main()
{
    char c;
    int hh, mm, ss, ff, ret;
    char *str = "10:11:40:14444d";

    if (sscanf(str, "%02u:%02u:%02u%c%02u", &hh, &mm, &ss, &c, &ff) != 5) {
        printf( "failed \n");
    }
    printf( "hh: %d, mm: %d, ss: %d, ff: %d \n", hh, mm, ss, ff);
}

> 
> Regards,
> 
> -- 
>   Nicolas George
diff mbox series

Patch

diff --git a/libavutil/timecode.c b/libavutil/timecode.c
index 60077ba..1facc41 100644
--- a/libavutil/timecode.c
+++ b/libavutil/timecode.c
@@ -196,7 +196,7 @@  int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *st
     char c;
     int hh, mm, ss, ff, ret;
 
-    if (sscanf(str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) {
+    if (sscanf(str, "%02u:%02u:%02u%c%02u", &hh, &mm, &ss, &c, &ff) != 5) {
         av_log(log_ctx, AV_LOG_ERROR, "Unable to parse timecode, "
                                       "syntax: hh:mm:ss[:;.]ff\n");
         return AVERROR_INVALIDDATA;