Bug 12897

Summary: XGetIMValues doesn't return the name of the first argument that could not be obtained
Product: xorg Reporter: Yann Droneaud <yann>
Component: Lib/XlibAssignee: Xorg Project Team <xorg-team>
Status: RESOLVED FIXED QA Contact: Xorg Project Team <xorg-team>
Severity: normal    
Priority: medium CC: jeremyhu, jesserayadkins
Version: 7.5 (2009.10)Keywords: i18n, patch
Hardware: All   
OS: All   
Whiteboard: 2011BRB_Reviewed
i915 platform: i915 features:
Attachments:
Description Flags
Return p->name instead of p->value (untested)
none
Working test case for XGetIMValues() none

Description Yann Droneaud 2007-10-23 09:17:37 UTC
While trying to use XIM, I found that calling XGetIMValues 
with unknown names like:

err = XGetIMValues(im, "invalid", &arg, NULL);

return address of &arg, instead of the address of name "invalid" 
as stated in man page (XOpenIM) and Xlib documentation (chapter 13.5.3) : 

"otherwise, it returns the name of the first argument that could not
be obtained."

In modules/im/ximcp/imRm.c: _XimGetIMValueData() 
the function returns p->value instead of p->name .

And according to the code in imRm.c, _XimSetIMValueData() 
has the same problem.
Comment 1 Yann Droneaud 2007-10-23 09:20:20 UTC
Created attachment 12164 [details] [review]
Return p->name instead of p->value (untested)

Here is a little patch to change p->value to p->name in 
_XimSetIMValueData() and _XimGetIMValueData()
Comment 2 Yann Droneaud 2007-10-23 09:24:42 UTC
My original program does the following:

    char *name;

    static const char *invalid = "INVALID";

    void *arg = (void *) 0x004c754e; /* "NuL" on i386 arch */

    XIMValuesList *imvl = NULL;
    XIMStyles *ims = NULL;

    /* retrieve some values, and get an error */
    name = XGetIMValues(im, 
			XNQueryIMValuesList, &imvl, 
			XNQueryInputStyle, &ims,
			invalid, &arg, 
			NULL);
    if (name != NULL) {
      /* 
       * name should point to the name 
       * which was not retrieved, eg. "INVALID"
       */
      printf("XGetIMValues() returned: %p '%s'\n"
	     "invalid name: %p '%s'\n"
	     "invalid arg:  %p\n", 
	     name, name, 
	     invalid, invalid, 
	     &arg);
    }

And print:

XGetIMValues() returned: 0xbf8d1d34 'NuL'
invalid name: 0x8048adf 'INVALID'
invalid arg:  0xbf8d1d34


Comment 3 Jesse Adkins 2010-12-10 15:23:06 UTC
(In reply to comment #2)
This doesn't compile. Can you an example that compiles so I can check to see if this is still an issue?
Comment 4 Yann Droneaud 2010-12-19 09:13:59 UTC
Created attachment 41259 [details]
Working test case for XGetIMValues()

(In reply to comment #3)
> This doesn't compile. Can you an example that compiles so I can check to see if
> this is still an issue?

Here's a complete test case which demonstrate the problem:

  $ gcc -Wall -Wextra test-XGetIMValues.c -o test-XGetIMValues -lX11 
  $ ./test-XGetIMValues 
  XLib support current locale
  Current locale modifier '@im=none'
  XGetIMValues() returned: 0x7fff220d5628 'NuL'
        invalid name was : 0x400db8 'INVALID'
        invalid arg  was : 0x7fff220d5628
  ERROR: XGetIMValues() returned address of argument instead of its name
  ERROR: valid function return would be: 0x400db8 'INVALID'

As you can see XGetIMValues() returns the argument and not its name.

XGetIMValues() man page :

  The XGetIMValues function presents a variable argument list programming 
  interface for querying properties or features of the specified input method.  
  This function returns NULL if it succeeds; otherwise, it returns the name of 
  the first argument that could not be obtained.
Comment 5 Yann Droneaud 2010-12-19 09:17:58 UTC
(In reply to comment #4)

It was tested on Fedora Core 14 against libX11 1.3.4.
Comment 6 Jeremy Huddleston Sequoia 2011-10-08 19:39:53 UTC
Can you please send your patch to xorg-devel for review?

Thanks.
Comment 7 Jeremy Huddleston Sequoia 2011-10-11 09:59:33 UTC
Pushed the fix, thanks.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.