From 2345757725a3f25fd519c46be59ab3f9204ebaa3 Mon Sep 17 00:00:00 2001 From: thierry1970 Date: Thu, 5 Mar 2020 12:32:49 +0100 Subject: [PATCH] Fix parsing location. --- backend/escl/escl_newjob.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/backend/escl/escl_newjob.c b/backend/escl/escl_newjob.c index 279b9df8c..084431cc3 100644 --- a/backend/escl/escl_newjob.c +++ b/backend/escl/escl_newjob.c @@ -206,17 +206,23 @@ escl_newjob (capabilities_t *scanner, SANE_String_Const name, SANE_Status *statu } else { if (download->memory != NULL) { - if (strstr(download->memory, "Location:")) { - temporary = strrchr(download->memory, '/'); + char *tmp_location = strstr(download->memory, "Location:"); + if (tmp_location) { + temporary = strchr(tmp_location, '\r'); + if (temporary == NULL) + temporary = strchr(tmp_location, '\n'); if (temporary != NULL) { - location = strchr(temporary, '\r'); - if (location == NULL) - location = strchr(temporary, '\n'); - else { - *location = '\0'; - result = strdup(temporary); - } - DBG( 1, "Create NewJob : %s\n", result); + *temporary = '\0'; + location = strrchr(tmp_location,'/'); + if (location) { + result = strdup(location); + DBG( 1, "Create NewJob : %s\n", result); + *temporary = '\n'; + } + } + if (result == NULL) { + DBG( 1, "Error : Create NewJob, no location\n"); + *status = SANE_STATUS_INVAL; } free(download->memory); }