From 8e9bc0edbbcea4af795f3a313741048cf2a9e897 Mon Sep 17 00:00:00 2001 From: K D Hedger Date: Thu, 20 Jul 2023 12:03:08 +0100 Subject: [PATCH] Fixed stack smashing errors --- .../LFSApplications/resources/startlfsdesktop | 52 ++++++++++++++----- .../LFSApplications/src/lfsmimeeditor.cpp | 11 ++-- .../LFSApplications/src/lfstkprefs.cpp | 3 +- LFSToolKit/ChangeLog | 1 + .../LFSToolKit/lfstk/LFSTKApplication.cpp | 2 +- .../LFSToolKit/lfstk/LFSTKFindClass.cpp | 6 ++- LFSToolKit/LFSToolKit/lfstk/LFSTKLib.cpp | 20 +++---- .../LFSToolKit/lfstk/LFSTKMultiLineEdit.cpp | 25 +++++---- LFSToolKit/examples/RunExamples.cpp | 2 +- xinitrc.sample | 2 - 10 files changed, 80 insertions(+), 44 deletions(-) diff --git a/LFSApplications/LFSApplications/resources/startlfsdesktop b/LFSApplications/LFSApplications/resources/startlfsdesktop index ae90067..e3101d2 100755 --- a/LFSApplications/LFSApplications/resources/startlfsdesktop +++ b/LFSApplications/LFSApplications/resources/startlfsdesktop @@ -29,23 +29,45 @@ if [ ! -e ~/.config/LFS ];then mkdir -vp ~/.config/LFS fi -if [ ! -e ~/.config/LFS/lfswmanager.rc ];then - cat > ~/.config/LFS/lfswmanager.rc < ~/.config/LFS/lfswm2.rc < ~/.config/LFS/lfswmanager.rc < ~/.config/LFS/lfspanel.rc <(p)->wc->LFSTK_hideWindow(); const char *label=static_cast(p)->LFSTK_getLabel(); @@ -227,6 +227,7 @@ bool menuCB(void *p,void* ud) themePath=strdup(prefs.LFSTK_getCString("themepath")); setPreviewData(); + free(buffer); return(true); } diff --git a/LFSToolKit/ChangeLog b/LFSToolKit/ChangeLog index 7315b8c..48c5593 100644 --- a/LFSToolKit/ChangeLog +++ b/LFSToolKit/ChangeLog @@ -1,4 +1,5 @@ 0.5.1 +Fixed stack smashing errors. Set exapander gadget to use window back colour. Install default colour scheme to ~/.config/LFS on first run of library. Added default colour scheme. diff --git a/LFSToolKit/LFSToolKit/lfstk/LFSTKApplication.cpp b/LFSToolKit/LFSToolKit/lfstk/LFSTKApplication.cpp index fb98331..709029f 100644 --- a/LFSToolKit/LFSToolKit/lfstk/LFSTKApplication.cpp +++ b/LFSToolKit/LFSToolKit/lfstk/LFSTKApplication.cpp @@ -92,7 +92,7 @@ LFSTK_applicationClass::LFSTK_applicationClass() this->userHome=getenv("HOME"); asprintf(&this->configDir,"%s/.config/LFS",this->userHome); - this->iconThemeName=this->globalLib->LFSTK_oneLiner("head '%s'/lfsdesktop.rc|grep -i icontheme|awk '{print $2}'",this->configDir); + this->iconThemeName=this->globalLib->LFSTK_oneLiner("cat '%s'/lfsdesktop.rc|grep -i icontheme|awk '{print $2}'",this->configDir); } /** diff --git a/LFSToolKit/LFSToolKit/lfstk/LFSTKFindClass.cpp b/LFSToolKit/LFSToolKit/lfstk/LFSTKFindClass.cpp index 07ba23d..6525d6e 100644 --- a/LFSToolKit/LFSToolKit/lfstk/LFSTKFindClass.cpp +++ b/LFSToolKit/LFSToolKit/lfstk/LFSTKFindClass.cpp @@ -352,12 +352,13 @@ void LFSTK_findClass::LFSTK_findFiles(const char *dir,bool multi) struct stat filestat; int retstat; dataStruct datas; - char *filepath; + char *filepath; fc=this; if(multi==false) this->deleteData(); - filepath=(char*)alloca(PATH_MAX); + + filepath=(char*)malloc(PATH_MAX); dirhandle=opendir(dir); if(dirhandle!=NULL) { @@ -435,5 +436,6 @@ void LFSTK_findClass::LFSTK_findFiles(const char *dir,bool multi) closedir(dirhandle); } this->dataCnt=this->data.size(); + free(filepath); } diff --git a/LFSToolKit/LFSToolKit/lfstk/LFSTKLib.cpp b/LFSToolKit/LFSToolKit/lfstk/LFSTKLib.cpp index 319b5f5..5c50bbc 100644 --- a/LFSToolKit/LFSToolKit/lfstk/LFSTKLib.cpp +++ b/LFSToolKit/LFSToolKit/lfstk/LFSTKLib.cpp @@ -587,9 +587,9 @@ breakReturn: */ std::string LFSTK_lib::LFSTK_oneLiner(const std::string fmt,...) { - FILE *fp; + FILE *fp; va_list ap; - char *buffer=(char*)alloca(MAXBUFFER); + char *buffer=(char*)malloc(MAXBUFFER); std::string str=""; va_start(ap, fmt); @@ -636,6 +636,7 @@ std::string LFSTK_lib::LFSTK_oneLiner(const std::string fmt,...) pclose(fp); str=buffer; } + free(buffer); return(str); } @@ -647,12 +648,12 @@ std::string LFSTK_lib::LFSTK_oneLiner(const std::string fmt,...) */ char* LFSTK_lib::LFSTK_oneLiner(const char* fmt,...) { - FILE *fp; + FILE *fp; va_list ap; - char *buffer,*subbuffer; + char *buffer,*subbuffer; - buffer=(char*)alloca(MAXBUFFER); - subbuffer=(char*)alloca(MAXBUFFER); + buffer=(char*)malloc(MAXBUFFER); + subbuffer=(char*)malloc(MAXBUFFER); buffer[0]=0; subbuffer[0]=0; @@ -697,8 +698,10 @@ char* LFSTK_lib::LFSTK_oneLiner(const char* fmt,...) buffer[strlen(buffer)-1]=0; } pclose(fp); + free(subbuffer); return(strdup(buffer)); } + free(subbuffer); return(NULL); } @@ -871,8 +874,7 @@ cairo_surface_t* LFSTK_lib::LFSTK_cairo_image_surface_create_from_jpeg(const cha const unsigned char *data; int infile; struct stat stat; - char magic[]="\xff\xd8\xff"; - + std::string magicstr="\xff\xd8\xff"; // open input file if((infile=open(filename,O_RDONLY))==-1) return(NULL); @@ -892,7 +894,7 @@ cairo_surface_t* LFSTK_lib::LFSTK_cairo_image_surface_create_from_jpeg(const cha char *ptr=(char*)data; bool flag=true; for(int j=0;j<3;j++) - if(ptr[j]!=magic[j]) + if(ptr[j]!=magicstr.at(j)) flag=false; close(infile); diff --git a/LFSToolKit/LFSToolKit/lfstk/LFSTKMultiLineEdit.cpp b/LFSToolKit/LFSToolKit/lfstk/LFSTKMultiLineEdit.cpp index 097c886..8183caf 100644 --- a/LFSToolKit/LFSToolKit/lfstk/LFSTKMultiLineEdit.cpp +++ b/LFSToolKit/LFSToolKit/lfstk/LFSTKMultiLineEdit.cpp @@ -234,7 +234,7 @@ void LFSTK_multiLineEditClass::drawText(void) cairo_text_extents_t partextents; cairo_text_extents_t charextents; int offline=0; - long maxlines=0; + long maxlines=0; int calcmax=0; int linewithcursor=0; @@ -284,21 +284,27 @@ void LFSTK_multiLineEditClass::drawText(void) if(lines.at(j)->cursorPos!=-1) { char *data; - char undercurs[2]; - char *aftercursor; + //char *undercurs[2]; + std::string undercursstr=" "; + char *aftercursor; asprintf(&data,"%s",lines.at(j)->line); - undercurs[0]=data[lines.at(j)->cursorPos]; - undercurs[1]=0; - if(undercurs[0]==0) - undercurs[0]=' '; + //undercurs[0]=data[lines.at(j)->cursorPos]; + undercursstr[0]=data[lines.at(j)->cursorPos]; + //undercurs[1]=0; + undercursstr[1]=0; + //if(undercurs[0]==0) + if(undercursstr.at(0)==0) + undercursstr[0]=' '; + //undercurs[0]=' '; data[lines.at(j)->cursorPos]=0; aftercursor=&data[lines.at(j)->cursorPos+1]; //1stbit cairo_show_text(this->cr,data); cairo_text_extents (this->cr,data,&partextents); - cairo_text_extents (this->cr,undercurs,&charextents); + //cairo_text_extents (this->cr,undercurs,&charextents); + cairo_text_extents (this->cr,undercursstr.c_str(),&charextents); cairo_set_source_rgba(this->cr,this->cursorColour.RGBAColour.r,this->cursorColour.RGBAColour.g,this->cursorColour.RGBAColour.b,this->cursorColour.RGBAColour.a); cairo_rectangle(this->cr,partextents.x_advance+0.5+this->pad,yoffset-this->fontExtents.ascent,charextents.x_advance-0.5,this->fontExtents.ascent+this->fontExtents.descent); @@ -306,7 +312,8 @@ void LFSTK_multiLineEditClass::drawText(void) //secondbit cairo_move_to(this->cr,partextents.x_advance+this->pad,yoffset); cairo_set_source_rgba(this->cr,1.0,1.0,1.0,1.0); - cairo_show_text(this->cr,undercurs); + //cairo_show_text(this->cr,undercurs); + cairo_show_text(this->cr,undercursstr.c_str()); //3rdbit cairo_set_source_rgba(this->cr,0.0,0.0,0.0,1.0); if(lines.at(j)->cursorPosline)) diff --git a/LFSToolKit/examples/RunExamples.cpp b/LFSToolKit/examples/RunExamples.cpp index 19d16ba..6870cc5 100755 --- a/LFSToolKit/examples/RunExamples.cpp +++ b/LFSToolKit/examples/RunExamples.cpp @@ -14,7 +14,7 @@ fi APPNAME=$(basename $0 .cpp) cd "$(dirname "$0")" -g++ "$0" -O0 -ggdb -I../LFSToolKit -L../LFSToolKit/app/.libs $(pkg-config --cflags --libs x11 xft cairo ) -llfstoolkit -lImlib2 -o $APPNAME||exit 1 +g++ -Wstack-protector -Werror -fstack-protector "$0" -O0 -ggdb -I../LFSToolKit -L../LFSToolKit/app/.libs $(pkg-config --cflags --libs x11 xft cairo ) -llfstoolkit -lImlib2 -Wstack-protector -Werror -fstack-protector -o $APPNAME||exit 1 LD_LIBRARY_PATH=../LFSToolKit/app/.libs $USEVALGRIND ./$APPNAME "$@" retval=$? rm $APPNAME diff --git a/xinitrc.sample b/xinitrc.sample index 9373866..a7fc9f3 100644 --- a/xinitrc.sample +++ b/xinitrc.sample @@ -26,8 +26,6 @@ sysmodmap=/etc/X11/app-defaults/.Xmodmap xcursorsfile=$HOME/xinits/XDefaults/XCursorsfile customcolours=$HOME/xinits/XDefaults/XDefaults -LFSVERSION="9.0" - # merge in defaults and keymaps if [ -f $xcursorsfile ]; then