[comp.windows.x] XrmParseCommand

jmsellens@watdragon.waterloo.edu (11/15/88)

From: "John M. Sellens" <jmsellens>

			  X Window System Bug Report
			    xbugs@expo.lcs.mit.edu




VERSION:
    R3

CLIENT MACHINE and OPERATING SYSTEM:
    Any

DISPLAY:
    Any

WINDOW MANAGER:
    Any

AREA:
    Xlib

SYNOPSIS:
    XrmParseCommand() doesn't parse well, and has null pointer problems.

DESCRIPTION:
    If XrmParseCommand() is called with a command line with the last
    argument "missing" (e.g. the last arg is "-geometry") it doesn't
    notice, and it indirects through various null pointers.  This code
    doesn't check to see that there is actually a folling argument, and
    the PutCommandResource() macro is called with NULL, and then calls
    XrmQPutStringResource() which does strlen(0) among other things.
    Similarly for XrmPutLineResource().

		case XrmoptionSepArg:
		    --(*argc);
		    ++argv; --myargc; --(*argc);
		    PutCommandResource(*argv);
		    break;
		
		case XrmoptionResArg:
		    ++argv; --myargc; --(*argc); --(*argc);
		    XrmPutLineResource(pdb, *argv);
		    break;

REPEAT BY:
    Try it on a Sun and watch the core dump:
	xclock -geometry
    (Under R2 for sure, but I haven't installed R3 on our Suns yet, but
    it should do the same thing.)

SAMPLE FIX:
    ??  There is no way for XrmParseCommand() to indicate errors to its
    caller.  One alternative is to leave the offending argument in the
    argument list (in this case, the "-geometry"), but this is not good
    because then the caller will complain about "-geometry" being invalid
    or bad syntax or something, when the real error is that it requires
    a following argument which wasn't there.  XrmParseCommand() could
    print an error message, but not elegantly, because it does not know
    that name of the caller, so it can't print a reasonable message.
    There is something in lib/X/ParseCmd.c to print an error message, but
    it is meant to handle internal programming errors, rather than a
    user's command line error.  There is no error handler available
    for handling this kind of error.