[sane-devel] Avision AV122 and reading the buttons gives I/O-Error

Ori Koren ori at paperact.com
Thu Jan 29 07:56:48 UTC 2009


On Fri, Jan 23, 2009 at 5:18 PM, Wilhelm Meier <wilhelm.meier at fh-kl.de> wrote:

>>Am Freitag 23 Januar 2009 schrieb Zudio Solutions:
>> Hi Wilhelm,
>>
>> I managed to get sanebuttonsd to sort-of work by looking at the
>> message options like suggested; however some things are still not
>> clear:
>>
>> 1. In one case the type of the option (not necessarily the message
>> option) was String, but the code that prints it caused a crash.
>which option?

It was happening with all options of type SANE_TYPE_STRING + at least
partly due to my fault..

The crash happened because (a modified) sanebuttond.c was calling:
sane_control_option (..., SANE_ACTION_GET_VALUE, &val, ..)
,where val was a SANE_INT, and then trying to print it as a string.

The "offending" code was inside a #ifdef TEST clause and after an
 "if (strncmp(opt->name, "button",6) continue;" statement - so it
was only triggered when I removed the "if" statement and #defined TEST.

In the latest sanebuttonsd.c (experimental tree, scanmonitord) the
code looks like this(val is a SANE_Int):
 for (  i = 0; i < num_dev_options; ++i ) {
		opt[idx] = sane_get_option_descriptor (device, i);
		...
			if ( (opt[idx]->name && !strncmp( opt[idx]->name, "button", 6))
				|| ... ) {

				status = sane_control_option (device, i,
					SANE_ACTION_GET_VALUE, &val, 0);
				...
                                switch (opt[idx]->type) {
				        ...
					case SANE_TYPE_STRING:
					case SANE_TYPE_BUTTON:
                                        ...
                                }

Even though this code doesn't try to print the string, it still seems
to have a problem:
if a backend ever has an option with name "button" and type SANE_TYPE_STRING,
and the string's length (+1) is bigger than sizeof(SANE_Int) - then the call to
sane_control_option(.. GET_VALUE ..) will cause a memory corruption.

<snipped>

>actually my avision scanner is gone, but I remember, that the
>message-option (I think it was of fixed size 129 Bytes ... look at
>the avision-backend sources) contains the string as I said in the
>previous mail.

After getting over the problem from above - I can see the string that
you described in your previous mail.


>> 3. Another problem - when I know that a button was pressed and want
>> to scan the document - I get an error. Closing the device
>>     (that was used by sanebuttonsd) before trying to scan solves
>> this. Is this how it is supposed to be done?

>As I remember (might be wrong), the sanebuttonsd does not immediately
>close the device while polling and calling the scan-script. So the
>called frontend (scanimage e.g.) can't open the device. Because I
>encountered several limitations in saneuttonsd I decided to write a
>new daemon (scanbd - http://sourceforge.net/projects/scanbd ).
>I use it to have the possibility to scan via the scanner-buttons
>(polling takes place) and using saned (the sane network daemon for
>remote scanner from desktops) at the same time. With sanebuttonsd
>this isn't possible! I found this a very flexible way. the scanbd can
>be configured to perform different action for all combinations of
>buttons and function-values and it scan manage arbitrary number of
>connected scanners.

Sure sounds like the way to go. I didn't have a chance to look at it too
much yet - but I sure will as soon as I can..

>>
>> Most appreciated.
>> Gil

Same here,
Ori



More information about the sane-devel mailing list