Control: tags 268630 + upstream patch
Dear Maintainer, I just tried to have a look at 926554, but I think both are kind of the same. The issue here is, as far as I see, that in function middle_get_key a process "xbindkeys -k" gets started and its output is tried to be parsed. Unfortunately if the file .xbindkeysrc not yet exists, xbindkeys just outputs a message to stderr and nothing is written to stdout. Attached patch tries to check for zero length reads from stdout of the child process. And tries to make the checks for null, returned by strchr, work. Kind regards, Bernhard
>From 8d3caaefd5701b6697f161070d36339ce73c1e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?= <bernha...@mailbox.org> Date: Sat, 20 Apr 2019 01:28:23 +0200 Subject: [PATCH] Check for zero length reads and make checks for null pointer work. Debian-Bug: https://bugs.debian.org/268630 --- middle.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/middle.c b/middle.c index 605ab10..620e3f4 100644 --- a/middle.c +++ b/middle.c @@ -358,30 +358,37 @@ gboolean middle_get_key(GtkWidget *parent, void *data) /* printf("%s\n", buf ); */ + if (len <= 0) { + printf("erreur in get line, no output from command"); + return FALSE; + } /* find line beginning by " */ pl1=buf; while ( pl1[0]!='\"' ){ - pl1 = strchr (pl1, '\n')+1; + pl1 = strchr (pl1, '\n'); if(!pl1) { printf("erreur in get line \"NoCommand\""); return FALSE; /* error in get the line "NoCommand" */ } + pl1 += 1; }; /* pl1 is the next line */ - pl1 = strchr(pl1, '\n')+5; + pl1 = strchr(pl1, '\n'); if(!pl1) { printf("erreur in get line \"Pl1\""); return FALSE; /* error in get the line 3 */ } + pl1 += 5; /* pl2 is the next line */ - pl2 = strchr(pl1, '\n')+5; - if(!pl1) { + pl2 = strchr(pl1, '\n'); + if(!pl2) { printf("erreur in get line \"Pl2\""); return FALSE; /* error in get the line 4" */ } + pl2 += 5; /* change the \n to 0 */ -- 2.20.1
# Buster aarch qemu VM 2019-04-19 apt update apt dist-upgrade apt install dpkg-dev devscripts systemd-coredump net-tools psmisc mc gdb xserver-xorg lightdm openbox tigervnc-standalone-server xserver-xephyr xvfb x11vnc xbindkeys-config xbindkeys-dbgsym xbindkeys-config-dbgsym apt build-dep xbindkeys-config mkdir /home/benutzer/source/xbindkeys-config/orig -p cd /home/benutzer/source/xbindkeys-config/orig apt source xbindkeys-config cd ########### #xserver-xorg # VM has no graphic tigervncserver ssh -p2222 -L "127.0.0.1:5901:127.0.0.1:5901" benutzer@$LOCALIP xtigervncviewer 127.0.0.1:5901 # 923962 Xephyr # needs a xserver for output Xvfb :100 -ac export DISPLAY=:100 x-window-manager & x11vnc -rfbport 5901 & xtigervncviewer $LOCALIP:5901 export DISPLAY=:100 gdb -q --args xbindkeys-config set width 0 set pagination off directory /home/benutzer/source/xbindkeys-config/orig/xbindkeys-config-0.1.3 run # New # Get Key ########### # Without config: benutzer@debian:~$ gdb -q --args xbindkeys-config Reading symbols from xbindkeys-config...Reading symbols from /usr/lib/debug/.build-id/c8/2326ff345dd0d153d8a97b1f19b1f0be870c70.debug...done. done. (gdb) set width 0 (gdb) set pagination off (gdb) directory /home/benutzer/source/xbindkeys-config/orig/xbindkeys-config-0.1.3 Source directories searched: /home/benutzer/source/xbindkeys-config/orig/xbindkeys-config-0.1.3:$cdir:$cwd (gdb) run Starting program: /usr/bin/xbindkeys-config [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1". open file: No such file or directory [Detaching after fork from child process 25509] xbindkeys: no process found [Detaching after fork from child process 25511] Error : /home/benutzer/.xbindkeysrc not found or reading not allowed. please, create one with 'xbindkeys --defaults > /home/benutzer/.xbindkeysrc'. or, if you want scheme configuration style, with 'xbindkeys --defaults-guile > /home/benutzer/.xbindkeysrc.scm'. Program received signal SIGSEGV, Segmentation fault. middle_get_key (data=<optimized out>, parent=<optimized out>) at middle.c:364 warning: Source file is more recent than executable. 364 while ( pl1[0]!='\"' ){ (gdb) bt #0 middle_get_key (data=<optimized out>, parent=<optimized out>) at middle.c:364 #1 0x0000ffffbed3b9f0 in g_closure_invoke () from /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #2 0x0000ffffbed502c4 in ?? () from /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #3 0x0000ffffbed5860c in g_signal_emit_valist () from /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #4 0x0000ffffbed58b78 in g_signal_emit () from /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #5 0x0000ffffbf2f09e0 in ?? () from /lib/aarch64-linux-gnu/libgtk-x11-2.0.so.0 #6 0x0000ffffbf3a063c in ?? () from /lib/aarch64-linux-gnu/libgtk-x11-2.0.so.0 #7 0x0000ffffbed3b9f0 in g_closure_invoke () from /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #8 0x0000ffffbed4fb38 in ?? () from /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #9 0x0000ffffbed58030 in g_signal_emit_valist () from /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #10 0x0000ffffbed58b78 in g_signal_emit () from /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #11 0x0000ffffbf4c3ca0 in ?? () from /lib/aarch64-linux-gnu/libgtk-x11-2.0.so.0 #12 0x0000ffffbf39e53c in gtk_propagate_event () from /lib/aarch64-linux-gnu/libgtk-x11-2.0.so.0 #13 0x0000ffffbf39e9a4 in gtk_main_do_event () from /lib/aarch64-linux-gnu/libgtk-x11-2.0.so.0 #14 0x0000ffffbf1f759c in ?? () from /lib/aarch64-linux-gnu/libgdk-x11-2.0.so.0 #15 0x0000ffffbec46634 in g_main_context_dispatch () from /lib/aarch64-linux-gnu/libglib-2.0.so.0 #16 0x0000ffffbec468a8 in ?? () from /lib/aarch64-linux-gnu/libglib-2.0.so.0 #17 0x0000ffffbec46c40 in g_main_loop_run () from /lib/aarch64-linux-gnu/libglib-2.0.so.0 #18 0x0000ffffbf39d858 in gtk_main () from /lib/aarch64-linux-gnu/libgtk-x11-2.0.so.0 #19 0x0000aaaaaaaadba0 in main (argc=<optimized out>, argv=<optimized out>) at xbindkeys_config.c:107 Apr 20 00:37:13 debian systemd[1]: Started Process Core Dump (PID 25515/UID 0). Apr 20 00:37:15 debian systemd-coredump[25516]: Process 25506 (xbindkeys-confi) of user 1000 dumped core. Stack trace of thread 25506: #0 0x0000aaaaaaaaf4dc middle_get_key (xbindkeys-config) #1 0x0000ffffbed3b9f0 g_closure_invoke (libgobject-2.0.so.0) #2 0x0000ffffbed502c4 n/a (libgobject-2.0.so.0) #3 0x0000ffffbed5860c g_signal_emit_valist (libgobject-2.0.so.0) #4 0x0000ffffbed58b78 g_signal_emit (libgobject-2.0.so.0) #5 0x0000ffffbf2f09e0 n/a (libgtk-x11-2.0.so.0) #6 0x0000ffffbf3a063c n/a (libgtk-x11-2.0.so.0) #7 0x0000ffffbed3b9f0 g_closure_invoke (libgobject-2.0.so.0) #8 0x0000ffffbed4fb38 n/a (libgobject-2.0.so.0) #9 0x0000ffffbed58030 g_signal_emit_valist (libgobject-2.0.so.0) #10 0x0000ffffbed58b78 g_signal_emit (libgobject-2.0.so.0) #11 0x0000ffffbf4c3ca0 n/a (libgtk-x11-2.0.so.0) #12 0x0000ffffbf39e53c gtk_propagate_event (libgtk-x11-2.0.so.0) #13 0x0000ffffbf39e9a4 gtk_main_do_event (libgtk-x11-2.0.so.0) #14 0x0000ffffbf1f759c n/a (libgdk-x11-2.0.so.0) #15 0x0000ffffbec46634 g_main_context_dispatch (libglib-2.0.so.0) #16 0x0000ffffbec468a8 n/a (libglib-2.0.so.0) #17 0x0000ffffbec46c40 g_main_loop_run (libglib-2.0.so.0) #18 0x0000ffffbf39d858 gtk_main (libgtk-x11-2.0.so.0) #19 0x0000aaaaaaaadba0 main (xbindkeys-config) #20 0x0000ffffbe962d24 __libc_start_main (libc.so.6) #21 0x0000aaaaaaaadd54 $x (xbindkeys-config) #22 0x0000aaaaaaaadd54 $x (xbindkeys-config) (gdb) list middle.c:338,414 338 /*****************************************************************************/ 339 gboolean middle_get_key(GtkWidget *parent, void *data) 340 { 341 FILE *f; 342 343 /* pl1 et pl2 is the line of key (Bad rem)*/ 344 char buf[500], buf2[100], *pl1, *pl2; 345 char *buf3[50]; 346 int len, i; 347 348 if(ROW == -1) return FALSE; 349 350 system("killall -9 xbindkeys" ); 351 if(!(f = popen( XBINDKEYS_PATCH " -k", "r"))){ 352 perror("opening " XBINDKEYS_PATCH ); 353 return FALSE; 354 } 355 356 if(f){ 357 len= fread( buf, sizeof(char), 500, f ); 358 359 /* printf("%s\n", buf ); */ 360 361 362 /* find line beginning by " */ 363 pl1=buf; 364 while ( pl1[0]!='\"' ){ 365 pl1 = strchr (pl1, '\n')+1; 366 if(!pl1) { 367 printf("erreur in get line \"NoCommand\""); 368 return FALSE; /* error in get the line "NoCommand" */ 369 } 370 }; 371 372 /* pl1 is the next line */ 373 pl1 = strchr(pl1, '\n')+5; 374 if(!pl1) { 375 printf("erreur in get line \"Pl1\""); 376 return FALSE; /* error in get the line 3 */ 377 } 378 379 /* pl2 is the next line */ 380 pl2 = strchr(pl1, '\n')+5; 381 if(!pl1) { 382 printf("erreur in get line \"Pl2\""); 383 return FALSE; /* error in get the line 4" */ 384 } 385 386 387 /* change the \n to 0 */ 388 for(i=0; i<len; i++) 389 if(buf[i]=='\n') buf[i]=0; 390 391 /* update */ 392 sprintf( buf2, "%s | %s", pl2, pl1); 393 394 for(i=0; gtk_clist_get_text (GTK_CLIST(clist), i, 1, buf3); i++) 395 if(i!=ROW) 396 if(!strcmp(buf3[0], buf2)){ 397 sprintf( buf2, "Key Used"); 398 gtk_label_set_text (GTK_LABEL(label_warning), 399 "The line with\n\"Key Used\"\nis not Saved"); 400 } 401 402 gtk_entry_set_text (GTK_ENTRY(entry_key), buf2); 403 404 /* end */ 405 fclose(f); 406 restart_xbindkeys(); 407 return TRUE; 408 } 409 else{ 410 perror("middle_get_key:"); 411 return FALSE; 412 } 413 } 414 ####### Without config: benutzer@debian:~$ xbindkeys -k Error : /home/benutzer/.xbindkeysrc not found or reading not allowed. please, create one with 'xbindkeys --defaults > /home/benutzer/.xbindkeysrc'. or, if you want scheme configuration style, with 'xbindkeys --defaults-guile > /home/benutzer/.xbindkeysrc.scm'. ####### xbindkeys --defaults > /home/benutzer/.xbindkeysrc ####### dpkg -i /home/benutzer/source/xbindkeys-config/try1/xbindkeys-config{,-dbgsym}_0.1.3-2_arm64.deb