From: Adam Sutton Date: Thu, 13 Dec 2012 20:57:09 +0000 (+0000) Subject: Issue #1454 - Remove usage of non re-entrant strtok() X-Git-Tag: v3.5~238 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86fac417c20734383e904e38169f1c88b42a6da9;p=thirdparty%2Ftvheadend.git Issue #1454 - Remove usage of non re-entrant strtok() Thanks to Jaroslav Kysela for providing the initial fix. --- diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c index 9ac90bb3b..c6f1006ef 100644 --- a/src/epggrab/module/xmltv.c +++ b/src/epggrab/module/xmltv.c @@ -634,7 +634,7 @@ static void _xmltv_load_grabbers ( void ) size_t i, p, n; char *outbuf; char name[1000]; - char *tmp, *path; + char *tmp, *tmp2, *path; /* Load data */ outlen = spawn_and_store_stdout(XMLTV_FIND, NULL, &outbuf); @@ -668,7 +668,7 @@ static void _xmltv_load_grabbers ( void ) NULL }; path = strdup(tmp); - tmp = strtok(path, ":"); + tmp = strtok_r(path, ":", &tmp2); while (tmp) { DIR *dir; struct dirent *de; @@ -691,7 +691,7 @@ static void _xmltv_load_grabbers ( void ) } closedir(dir); } - tmp = strtok(NULL, ":"); + tmp = strtok_r(NULL, ":", &tmp2); } free(path); } diff --git a/src/filebundle.c b/src/filebundle.c index 82450a377..15a4d4c5f 100644 --- a/src/filebundle.c +++ b/src/filebundle.c @@ -214,12 +214,13 @@ fb_dir *fb_opendir ( const char *path ) /* Bundle */ #if ENABLE_BUNDLE - char *tmp1 = strdup(path); - char *tmp2 = strtok(tmp1, "/"); + char *tmp1, *tmp2, *tmp3; + *tmp1 = strdup(path); + *tmp2 = strtok_r(tmp1, "/", &tmp3); filebundle_entry_t *fb = filebundle_root; while (fb && tmp2) { if (fb->type == FB_DIR && !strcmp(fb->name, tmp2)) { - tmp2 = strtok(NULL, "/"); + tmp2 = strtok_r(NULL, "/", &tmp3); if (tmp2) fb = fb->d.child; } else { fb = fb->next; diff --git a/src/spawn.c b/src/spawn.c index 1ae748915..0cee4bdd5 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -53,13 +53,13 @@ find_exec ( const char *name, char *out, size_t len ) { int ret = 0; char bin[512]; - char *path, *tmp; + char *path, *tmp, *tmp2; DIR *dir; struct dirent *de; struct stat st; if (!(path = getenv("PATH"))) return 0; path = strdup(path); - tmp = strtok(path, ":"); + tmp = strtok_r(path, ":", &tmp2); while (tmp && !ret) { if ((dir = opendir(tmp))) { while ((de = readdir(dir))) { @@ -73,7 +73,7 @@ find_exec ( const char *name, char *out, size_t len ) } closedir(dir); } - tmp = strtok(NULL, ":"); + tmp = strtok_r(NULL, ":", &tmp2); } free(path); return ret; diff --git a/src/webui/extjs.c b/src/webui/extjs.c index fd12e1884..e27935afc 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -352,7 +352,7 @@ extjs_channels_update(htsmsg_t *in) if((s = htsmsg_get_str(c, "epggrabsrc")) != NULL) { char *tmp = strdup(s); - char *sptr = NULL; + char *sptr, *sptr2; char *modecid = strtok_r(tmp, ",", &sptr); char *modid, *ecid; epggrab_module_t *mod; @@ -377,8 +377,8 @@ extjs_channels_update(htsmsg_t *in) /* Add new */ while (modecid) { - modid = strtok(modecid, "|"); - ecid = strtok(NULL, "|"); + modid = strtok_r(modecid, "|", &sptr2); + ecid = strtok_r(NULL, "|", &sptr2); modecid = strtok_r(NULL, ",", &sptr); if (!(mod = epggrab_module_find_by_id(modid)))