From: Flole998 Date: Sat, 20 Feb 2021 20:19:36 +0000 (+0100) Subject: Rewrite scanfile.c for dynamic memory allocation (#1387) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0046c96d8d17f455caa8251c569355b77fe9f104;p=thirdparty%2Ftvheadend.git Rewrite scanfile.c for dynamic memory allocation (#1387) --- diff --git a/src/input/mpegts/scanfile.c b/src/input/mpegts/scanfile.c index c0f005625..8ffa55572 100644 --- a/src/input/mpegts/scanfile.c +++ b/src/input/mpegts/scanfile.c @@ -331,11 +331,12 @@ scanfile_create_network { scanfile_region_t *reg = NULL; scanfile_network_t *net; - char buf[270], buf2[263], buf3[270], *str; + char *buf, *buf2, *buf3, *str; int opos; /* Region */ - strlcpy(buf, name, sizeof(buf)); + buf = malloc(strlen(name) + 1); + strcpy(buf, name); if (!strcmp(type, "dvb-s")) { reg = scanfile_region_create(type, "geo", "Geo-synchronous Orbit"); } else { @@ -364,12 +365,21 @@ scanfile_create_network *str = '\0'; opos = INT_MAX; if (!strcmp(type, "dvb-s") && scanfile_network_dvbs_pos(buf, &opos)) { - snprintf(buf3, sizeof(buf3), "%c%3i.%i%c:%s", opos < 0 ? '<' : '>', + int sizeneeded = snprintf(NULL, 0, "%c%3i.%i%c:%s", opos < 0 ? '<' : '>', abs(opos) / 10, abs(opos) % 10, opos < 0 ? 'W' :'E', buf); - strcpy(buf, buf3); + + buf3 = malloc(sizeneeded + 1); + + snprintf(buf3, sizeneeded, "%c%3i.%i%c:%s", opos < 0 ? '<' : '>', + abs(opos) / 10, abs(opos) % 10, + opos < 0 ? 'W' :'E', buf); + free(buf); + buf = buf3; } - snprintf(buf2, sizeof(buf2), "%s_%s", type, buf); + int sizeneeded = snprintf(NULL, 0, "%s_%s", type, buf); + buf2 = malloc(sizeneeded + 1); + snprintf(buf2, sizeneeded, "%s_%s", type, buf); net = calloc(1, sizeof(scanfile_network_t)); memoryinfo_alloc(&scanfile_memoryinfo, sizeof(*net) + strlen(buf2) + 1 + strlen(buf) + 1 + strlen(path) + 1 + strlen(type) + 1); @@ -380,6 +390,9 @@ scanfile_create_network net->sfn_satpos = opos; LIST_INSERT_SORTED(®->sfr_networks, net, sfn_link, scanfile_network_cmp); + free(buf); + free(buf2); + *_net = net; return 0; }