From: skeezix Date: Tue, 7 Jun 2011 16:02:20 +0000 (-0400) Subject: Bloody off-by-1 error for a malloc, leading to ever-so-slight memory corruption.... X-Git-Tag: sz_beta3~44^2~1 X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-libraries.git;a=commitdiff_plain;h=024df2cc01d5771f27146f71950f2c5a50beb12c Bloody off-by-1 error for a malloc, leading to ever-so-slight memory corruption. (caused 'arg' argument to randomly show up in 'info links' .desktop's) --- diff --git a/lib/pnd_desktop.c b/lib/pnd_desktop.c index 3abf62d..349056d 100644 --- a/lib/pnd_desktop.c +++ b/lib/pnd_desktop.c @@ -298,7 +298,8 @@ unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p // exec line char args [ 1001 ]; char *pargs = args; - if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) { + char *viewerargs = pnd_conf_get_as_char ( desktoph, "info.viewer_args" ); + if ( viewerargs && viewerargs [ 0 ] ) { snprintf ( pargs, 1001, "%s %s", pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename ); } else { diff --git a/lib/pnd_pxml.c b/lib/pnd_pxml.c index 4b743d4..934c75c 100644 --- a/lib/pnd_pxml.c +++ b/lib/pnd_pxml.c @@ -29,7 +29,11 @@ pnd_pxml_handle *pnd_pxml_fetch ( char *fullpath ) { fseek ( f, 0, SEEK_SET ); - b = (char*) malloc ( len ); + if ( ! len ) { + return ( NULL ); + } + + b = (char*) malloc ( len + 1 ); if ( ! b ) { fclose ( f ); diff --git a/test/conftest.c b/test/conftest.c index 43aef1a..4a65550 100644 --- a/test/conftest.c +++ b/test/conftest.c @@ -1,12 +1,29 @@ #include /* for printf, NULL */ #include /* for free */ +#include /* for strlen */ #include "pnd_conf.h" #include "pnd_container.h" #include "pnd_apps.h" -int main ( void ) { +int main ( int argc, char *argv[] ) { + + // if an argument specified, try to load that one instead + if ( argc > 1 ) { + pnd_conf_handle h; + h = pnd_conf_fetch_by_path ( argv [ 1 ] ); + char *i = pnd_box_get_head ( h ); + printf ( "%s -> %s [%p:%d]\n", pnd_box_get_key ( i ), i, i, strlen ( i ) ); + while ( ( i = pnd_box_get_next ( i ) ) ) { + printf ( "%s -> %s [%p:%d]\n", pnd_box_get_key ( i ), i, i, strlen ( i ) ); + } + + char *poop = pnd_conf_get_as_char ( h, "info.viewer_args" ); + printf ( "info.viewer_args test: %s [%p:%d]\n", poop, poop, strlen ( poop ) ); + + exit ( 0 ); + } // attempt to fetch a sensible default searchpath for configs char *configpath = pnd_conf_query_searchpath(); diff --git a/testdata/conf/desktop b/testdata/conf/desktop index eceec57..c3c8863 100644 --- a/testdata/conf/desktop +++ b/testdata/conf/desktop @@ -19,5 +19,5 @@ hupscript pnd_hup.sh emit_info 1 # 0->no info .desktop; !0->yes to info .desktop dotdesktoppath ./testdata/menu # path for pndnotifyd to spit .desktop files into viewer links # sh-script or prog to run. Use wrapper sh if needed. -viewer_args -a # args. <- plus filename will be passed. ie: "-a filename.html" +viewer_args # args. <- plus filename will be passed. ie: "-a filename.html" category Documentation # freedesktop standard category to use