From b5b83ab7b74877dec1ce0d42d0cfe50ef224a05f Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Tue, 24 Apr 2012 13:36:16 +0200 Subject: [PATCH] plugins.cpp localize.cpp: fix possible segfault Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/1fdb76af51eb2f0deeaf8929201c592456464931 Author: Jacek Jendrzej Date: 2012-04-24 (Tue, 24 Apr 2012) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/gui/plugins.cpp | 9 +++++++-- src/system/localize.cpp | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/gui/plugins.cpp b/src/gui/plugins.cpp index f190c620b..bbc553907 100644 --- a/src/gui/plugins.cpp +++ b/src/gui/plugins.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -325,12 +326,16 @@ void CPlugins::startScriptPlugin(int number) FILE *f = popen(script,"r"); if (f != NULL) { - char output[1024]; - while (fgets(output,1024,f)) + char *output=NULL; + size_t len = 0; + while (( getline(&output, &len, f)) != -1) + { scriptOutput += output; } pclose(f); + if(output) + free(output); } else { diff --git a/src/system/localize.cpp b/src/system/localize.cpp index 40f55c79c..dc924a4f6 100644 --- a/src/system/localize.cpp +++ b/src/system/localize.cpp @@ -149,13 +149,14 @@ CLocaleManager::loadLocale_ret_t CLocaleManager::loadLocale(const char * const l } } - char buf[1000]; + char *buf=NULL; + size_t len = 0; i = 1; while(!feof(fd)) { - if(fgets(buf,sizeof(buf),fd)!=NULL) + if(getline(&buf, &len, fd)!=-1) { char * val = NULL; char * tmpptr = buf; @@ -203,6 +204,9 @@ CLocaleManager::loadLocale_ret_t CLocaleManager::loadLocale(const char * const l } } fclose(fd); + if(buf) + free(buf); + for (unsigned j = 1; j < (sizeof(locale_real_names)/sizeof(const char *)); j++) if (loadData[j] == locale_real_names[j]) {