[dvblast-devel] [Git][videolan/dvblast][master] 3 commits: if hour, min or sec is >= 100 we can overflow duration_str

Georgi Chorbadzhiyski georgi at unixsol.net
Tue Sep 15 08:14:12 CEST 2020


On 14.09.20 19:50, Christophe Massiot wrote:
> Can your propose a fix?

I guess something like the attached, a bigger buffer and snprintf.

-- 
Georgi Chorbadzhiyski | https://georgi.unixsol.org/ | https://georgi.unixsol.org/git/
-------------- next part --------------
>From 4f707a50da2245827b56480c39e2c5b3f57c7be4 Mon Sep 17 00:00:00 2001
From: Georgi Chorbadzhiyski <georgi at unixsol.org>
Date: Tue, 15 Sep 2020 09:04:02 +0300
Subject: [PATCH] Revert "if hour, min or sec is >= 100 we can overflow
 duration_str"

This reimplements ff1e5700c032b156b950a668fa05362459177963 and fixes
a regression that the hour number was not zero padded.
---
 dvblastctl.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/dvblastctl.c b/dvblastctl.c
index 9254b3d..657e89d 100644
--- a/dvblastctl.c
+++ b/dvblastctl.c
@@ -217,31 +217,32 @@ void print_eit_events(uint8_t *p_eit, f_print pf_print, void *print_opaque, f_ic
     uint8_t j = 0;
     while ((p_event = eit_get_event(p_eit, j)) != NULL) {
         j++;
-        char start_str[24];
+        char start_str[24], duration_str[32];
         int duration, hour, min, sec;
         time_t start_ts;
 
         start_ts = dvb_time_format_UTC(eitn_get_start_time(p_event), NULL, start_str);
 
         dvb_time_decode_bcd(eitn_get_duration_bcd(p_event), &duration, &hour, &min, &sec);
+        snprintf(duration_str, sizeof(duration_str) - 1, "%02d:%02d:%02d", hour, min, sec);
 
         switch (i_print_type) {
         case PRINT_XML:
             pf_print(print_opaque, "<EVENT id=\"%u\" start_time=\"%ld\" start_time_dec=\"%s\""
-                                   " duration=\"%u\" duration_dec=\"%u:%02u:%02u\""
+                                   " duration=\"%u\" duration_dec=\"%s\""
                                    " running=\"%d\" free_CA=\"%d\">",
                      eitn_get_event_id(p_event),
                      start_ts, start_str,
-                     duration, hour, min, sec,
+                     duration, duration_str,
                      eitn_get_running(p_event),
                      eitn_get_ca(p_event)
                     );
             break;
         default:
-            pf_print(print_opaque, "  * EVENT id=%u start_time=%ld start_time_dec=\"%s\" duration=%u duration_dec=%u:%02u:%02u running=%d free_CA=%d",
+            pf_print(print_opaque, "  * EVENT id=%u start_time=%ld start_time_dec=\"%s\" duration=%u duration_dec=%s running=%d free_CA=%d",
                      eitn_get_event_id(p_event),
                      start_ts, start_str,
-                     duration, hour, min, sec,
+                     duration, duration_dec,
                      eitn_get_running(p_event),
                      eitn_get_ca(p_event)
                     );
-- 
2.24.3 (Apple Git-128)



More information about the dvblast-devel mailing list