From 58912f68c2489bcee787599837447e0d64dfd61a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 24 May 2017 21:03:56 +0200 Subject: New upstream version 1.0.27 --- backend/dll.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'backend/dll.c') diff --git a/backend/dll.c b/backend/dll.c index 5264f11..5eaa046 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -69,6 +69,26 @@ #if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H) # include + /* This works around a pedantic GCC compiler warning. The ISO C + standard says that the behaviour of converting an object pointer + like the void * returned by dlsym() to a function pointer like + void *(*)() is implementation defined. POSIX though guarantees + that this works fine. + + Workaround based on http://stackoverflow.com/a/36385690. Turns + off pedantic warnings for the duration of the definition only. + */ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +typedef void *(*func_ptr)(void); + +func_ptr +posix_dlsym (void *handle, const char *func) +{ + return dlsym (handle, func); +} +# pragma GCC diagnostic pop + /* Older versions of dlopen() don't define RTLD_NOW and RTLD_LAZY. They all seem to use a mode of 1 to indicate RTLD_NOW and some do not support RTLD_LAZY at all. Hence, unless defined, we define @@ -430,15 +450,17 @@ load (struct backend *be) if (path) { - src_len = strlen (path) + strlen (LIBDIR) + 1 + 1; + src_len = strlen (path) + strlen (DIR_SEP) + strlen(LIBDIR) + 1; src = malloc (src_len); if (!src) { DBG (1, "load: malloc failed: %s\n", strerror (errno)); return SANE_STATUS_NO_MEM; } + if (orig_src) + free (orig_src); orig_src = src; - snprintf (src, src_len, "%s:%s", path, LIBDIR); + snprintf (src, src_len, "%s%s%s", path, DIR_SEP, LIBDIR); } else { @@ -534,7 +556,7 @@ load (struct backend *be) /* First try looking up the symbol without a leading underscore. */ #ifdef HAVE_DLOPEN - op = (void *(*)(void)) dlsym (be->handle, funcname + 1); + op = posix_dlsym (be->handle, funcname + 1); #elif defined(HAVE_SHL_LOAD) shl_findsym ((shl_t *) & (be->handle), funcname + 1, TYPE_UNDEFINED, &op); @@ -559,7 +581,7 @@ load (struct backend *be) { /* Try again, with an underscore prepended. */ #ifdef HAVE_DLOPEN - op = (void *(*)(void)) dlsym (be->handle, funcname); + op = posix_dlsym (be->handle, funcname); #elif defined(HAVE_SHL_LOAD) shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op); #elif defined(HAVE_NSLINKMODULE) -- cgit v1.2.3 From 1687222e1b9e74c89cafbb5910e72d8ec7bfd40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 31 Jul 2019 16:59:49 +0200 Subject: New upstream version 1.0.28 --- backend/dll.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'backend/dll.c') diff --git a/backend/dll.c b/backend/dll.c index 5eaa046..8f0983d 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -42,7 +42,7 @@ allows managing an arbitrary number of SANE backends by using dynamic linking to load backends on demand. */ -/* Please increase version number with every change +/* Please increase version number with every change (don't forget to update dll.desc) */ #define DLL_VERSION "1.0.13" @@ -353,7 +353,7 @@ load (struct backend *be) image_id id = -1; int i, w; directory_which which[3] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, B_BEOS_ADDONS_DIRECTORY }; - + /* look for config files in SANE/conf */ for (w = 0; (w < 3) && (id < 0) && (find_directory(which[w],0,true,path,PATH_MAX) == 0); w++) { @@ -373,7 +373,7 @@ load (struct backend *be) continue; /* try next path */ } be->handle=(void *)id; - + for (i = 0; i < NUM_OPS; ++i) { void *(*op) (); @@ -492,7 +492,7 @@ load (struct backend *be) break; DBG (4, "load: couldn't open `%s' (%s)\n", libname, strerror (errno)); -#ifdef ALT_POSTFIX +#ifdef ALT_POSTFIX /* Some platforms have two ways of storing their libraries, try both postfixes */ snprintf (libname, sizeof (libname), "%s/" PREFIX "%s" ALT_POSTFIX, @@ -882,7 +882,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) char path[1024]; directory_which which[3] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, B_BEOS_ADDONS_DIRECTORY }; int i; -#endif +#endif DBG_INIT (); @@ -934,7 +934,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) } fclose (fp); -#else +#else /* no ugly config files, just get scanners from their ~/config/add-ons/SANE */ /* look for drivers */ for (i = 0; i < 3; i++) @@ -943,13 +943,13 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) continue; strcat(path,"/SANE/"); dir=opendir(path); - if(!dir) continue; + if(!dir) continue; while((dirent=readdir(dir))) { if((strcmp(dirent->d_name,".")==0) || (strcmp(dirent->d_name,"..")==0)) continue; if((strcmp(dirent->d_name,"dll")==0)) continue; - add_backend(dirent->d_name,0); + add_backend(dirent->d_name,0); } closedir(dir); } @@ -1155,7 +1155,8 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only) SANE_Status sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) { - const char *be_name, *dev_name; + char *be_name; + const char *dev_name; struct meta_scanner *s; SANE_Handle handle; struct backend *be; @@ -1178,16 +1179,7 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) dev_name = strchr (full_name, ':'); if (dev_name) { -#ifdef strndupa - be_name = strndupa (full_name, dev_name - full_name); -#else - char *tmp; - - tmp = alloca (dev_name - full_name + 1); - memcpy (tmp, full_name, dev_name - full_name); - tmp[dev_name - full_name] = '\0'; - be_name = tmp; -#endif + be_name = strndup(full_name, dev_name - full_name); ++dev_name; /* skip colon */ } else @@ -1195,10 +1187,13 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) /* if no colon interpret full_name as the backend name; an empty backend device name will cause us to open the first device of that backend. */ - be_name = full_name; + be_name = strdup(full_name); dev_name = ""; } + if (!be_name) + return SANE_STATUS_NO_MEM; + if (!be_name[0]) be = first_backend; else @@ -1210,8 +1205,12 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) { status = add_backend (be_name, &be); if (status != SANE_STATUS_GOOD) - return status; + { + free(be_name); + return status; + } } + free(be_name); if (!be->inited) { -- cgit v1.2.3 From ffa8801644a7d53cc1c785e3450f794c07a14eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 2 Feb 2020 17:13:01 +0100 Subject: New upstream version 1.0.29 --- backend/dll.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 9 deletions(-) (limited to 'backend/dll.c') diff --git a/backend/dll.c b/backend/dll.c index 8f0983d..73ffde4 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -89,6 +89,20 @@ posix_dlsym (void *handle, const char *func) } # pragma GCC diagnostic pop + /* Similar to the above, GCC also warns about conversion between + pointers to functions. The ISO C standard says that invoking a + converted pointer to a function whose type is not compatible with + the pointed-to type, the behavior is undefined. Although GCC is + correct to warn about this, the dll backend has been using these + conversions without issues for a very long time already. + + Rather than push/pop around every use, which would get very ugly + real fast, ignore this particular warning for the remainder of + the file. + */ +# pragma GCC diagnostic ignored "-Wpragmas" /* backward compatibility */ +# pragma GCC diagnostic ignored "-Wcast-function-type" + /* Older versions of dlopen() don't define RTLD_NOW and RTLD_LAZY. They all seem to use a mode of 1 to indicate RTLD_NOW and some do not support RTLD_LAZY at all. Hence, unless defined, we define @@ -139,6 +153,8 @@ posix_dlsym (void *handle, const char *func) #define DLL_CONFIG_FILE "dll.conf" #define DLL_ALIASES_FILE "dll.aliases" +#include "../include/sane/sanei_usb.h" + enum SANE_Ops { OP_INIT = 0, @@ -797,7 +813,8 @@ read_dlld (void) DIR *dlld; struct dirent *dllconf; struct stat st; - char conffile[PATH_MAX], dlldir[PATH_MAX]; + char dlldir[PATH_MAX]; + char conffile[PATH_MAX + strlen("/") + NAME_MAX]; size_t len, plen; const char *dir_list; char *copy, *next, *dir; @@ -849,7 +866,7 @@ read_dlld (void) || (dllconf->d_name[len-1] == '#')) continue; - snprintf (conffile, PATH_MAX, "%s/%s", dlldir, dllconf->d_name); + snprintf (conffile, sizeof(conffile), "%s/%s", dlldir, dllconf->d_name); DBG (5, "sane_init/read_dlld: considering %s\n", conffile); @@ -1177,18 +1194,73 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) } dev_name = strchr (full_name, ':'); + + int is_fakeusb = 0, is_fakeusbdev = 0, is_fakeusbout = 0; + if (dev_name) { - be_name = strndup(full_name, dev_name - full_name); - ++dev_name; /* skip colon */ + is_fakeusb = strncmp(full_name, "fakeusb", dev_name - full_name) == 0 && + dev_name - full_name == 7; + is_fakeusbdev = strncmp(full_name, "fakeusbdev", dev_name - full_name) == 0 && + dev_name - full_name == 10; + is_fakeusbout = strncmp(full_name, "fakeusbout", dev_name - full_name) == 0 && + dev_name - full_name == 10; + } + + if (is_fakeusb || is_fakeusbdev) + { + ++dev_name; // skip colon + status = sanei_usb_testing_enable_replay(dev_name, is_fakeusbdev); + if (status != SANE_STATUS_GOOD) + return status; + + be_name = sanei_usb_testing_get_backend(); + if (be_name == NULL) + { + DBG (0, "%s: unknown backend for testing\n", __func__); + return SANE_STATUS_ACCESS_DENIED; + } } else { - /* if no colon interpret full_name as the backend name; an empty - backend device name will cause us to open the first device of - that backend. */ - be_name = strdup(full_name); - dev_name = ""; + char* fakeusbout_path = NULL; + if (is_fakeusbout) + { + ++dev_name; // skip colon + + const char* path_end = strchr(dev_name, ':'); + if (path_end == NULL) + { + DBG (0, "%s: the device name does not contain path\n", __func__); + return SANE_STATUS_INVAL; + } + fakeusbout_path = strndup(dev_name, path_end - dev_name); + + full_name = path_end + 1; // skip colon + dev_name = strchr(full_name, ':'); + } + + if (dev_name) + { + be_name = strndup(full_name, dev_name - full_name); + ++dev_name; /* skip colon */ + } + else + { + /* if no colon interpret full_name as the backend name; an empty + backend device name will cause us to open the first device of + that backend. */ + be_name = strdup(full_name); + dev_name = ""; + } + + if (is_fakeusbout) + { + status = sanei_usb_testing_enable_record(fakeusbout_path, be_name); + free(fakeusbout_path); + if (status != SANE_STATUS_GOOD) + return status; + } } if (!be_name) -- cgit v1.2.3