Skip to content

Commit

Permalink
Bloody off-by-1 error for a malloc, leading to ever-so-slight memory …
Browse files Browse the repository at this point in the history
…corruption. (caused 'arg' argument to randomly show up in 'info links' .desktop's)
  • Loading branch information
skeezix committed Jun 7, 2011
1 parent 379be69 commit 024df2c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/pnd_desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion lib/pnd_pxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
19 changes: 18 additions & 1 deletion test/conftest.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@

#include <stdio.h> /* for printf, NULL */
#include <stdlib.h> /* for free */
#include <string.h> /* 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();
Expand Down
2 changes: 1 addition & 1 deletion testdata/conf/desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 024df2c

Please sign in to comment.