kopia lustrzana https://gitlab.com/sane-project/backends
epson2: fixed network transport for new scanners
increased command buffer due memory overrun, and always read receive status, even for zero length on network scanenrs, should fix #315552merge-requests/1/head
rodzic
6ffeb90973
commit
5b10b0b635
|
@ -113,23 +113,27 @@ ssize_t
|
||||||
e2_recv(Epson_Scanner *s, void *buf, ssize_t buf_size,
|
e2_recv(Epson_Scanner *s, void *buf, ssize_t buf_size,
|
||||||
SANE_Status *status)
|
SANE_Status *status)
|
||||||
{
|
{
|
||||||
ssize_t n = 0;
|
ssize_t n = buf_size; /* network interface needs to read header back even data is 0.*/
|
||||||
|
|
||||||
DBG(15, "%s: size = %ld, buf = %p\n", __func__, (long) buf_size, buf);
|
DBG(15, "%s: size = %ld, buf = %p\n", __func__, (long) buf_size, buf);
|
||||||
|
|
||||||
|
*status = SANE_STATUS_GOOD;
|
||||||
if (s->hw->connection == SANE_EPSON_NET) {
|
if (s->hw->connection == SANE_EPSON_NET) {
|
||||||
n = sanei_epson_net_read(s, buf, buf_size, status);
|
n = sanei_epson_net_read(s, buf, buf_size, status);
|
||||||
} else if (s->hw->connection == SANE_EPSON_SCSI) {
|
} else if (s->hw->connection == SANE_EPSON_SCSI) {
|
||||||
|
if (buf_size)
|
||||||
n = sanei_epson2_scsi_read(s->fd, buf, buf_size, status);
|
n = sanei_epson2_scsi_read(s->fd, buf, buf_size, status);
|
||||||
} else if (s->hw->connection == SANE_EPSON_PIO) {
|
} else if (s->hw->connection == SANE_EPSON_PIO) {
|
||||||
|
if (buf_size) {
|
||||||
if (buf_size ==
|
if (buf_size ==
|
||||||
(n = sanei_pio_read(s->fd, buf, (size_t) buf_size)))
|
(n = sanei_pio_read(s->fd, buf, (size_t) buf_size)))
|
||||||
*status = SANE_STATUS_GOOD;
|
*status = SANE_STATUS_GOOD;
|
||||||
else
|
else
|
||||||
*status = SANE_STATUS_INVAL;
|
*status = SANE_STATUS_INVAL;
|
||||||
|
}
|
||||||
} else if (s->hw->connection == SANE_EPSON_USB) {
|
} else if (s->hw->connection == SANE_EPSON_USB) {
|
||||||
/* !!! only report an error if we don't read anything */
|
/* !!! only report an error if we don't read anything */
|
||||||
n = buf_size; /* buf_size gets overwritten */
|
if (n) {
|
||||||
*status =
|
*status =
|
||||||
sanei_usb_read_bulk(s->fd, (SANE_Byte *) buf,
|
sanei_usb_read_bulk(s->fd, (SANE_Byte *) buf,
|
||||||
(size_t *) & n);
|
(size_t *) & n);
|
||||||
|
@ -140,6 +144,7 @@ e2_recv(Epson_Scanner *s, void *buf, ssize_t buf_size,
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
*status = SANE_STATUS_GOOD;
|
*status = SANE_STATUS_GOOD;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (n < buf_size) {
|
if (n < buf_size) {
|
||||||
DBG(1, "%s: expected = %lu, got = %ld, canceling: %d\n", __func__,
|
DBG(1, "%s: expected = %lu, got = %ld, canceling: %d\n", __func__,
|
||||||
|
@ -170,18 +175,23 @@ e2_txrx(Epson_Scanner * s, unsigned char *txbuf, size_t txlen,
|
||||||
unsigned char *rxbuf, size_t rxlen)
|
unsigned char *rxbuf, size_t rxlen)
|
||||||
{
|
{
|
||||||
SANE_Status status;
|
SANE_Status status;
|
||||||
|
size_t done;
|
||||||
|
|
||||||
e2_send(s, txbuf, txlen, rxlen, &status);
|
done = e2_send(s, txbuf, txlen, rxlen, &status);
|
||||||
if (status != SANE_STATUS_GOOD) {
|
if (status != SANE_STATUS_GOOD) {
|
||||||
DBG(1, "%s: tx err, %s\n", __func__, sane_strstatus(status));
|
DBG(1, "%s: tx err, %s\n", __func__, sane_strstatus(status));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
if (done != txlen) {
|
||||||
|
DBG(1, "%s: tx err, short write\n", __func__);
|
||||||
|
return SANE_STATUS_IO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
e2_recv(s, rxbuf, rxlen, &status);
|
e2_recv(s, rxbuf, rxlen, &status);
|
||||||
if (status != SANE_STATUS_GOOD) {
|
if (status != SANE_STATUS_GOOD) {
|
||||||
DBG(1, "%s: rx err, %s\n", __func__, sane_strstatus(status));
|
DBG(1, "%s: rx err, %s\n", __func__, sane_strstatus(status));
|
||||||
}
|
}
|
||||||
|
DBG(1, "%s: eds_recv status, %s\n", __func__, sane_strstatus(status));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ static SANE_Status esci2_cmd(epsonds_scanner* s,
|
||||||
{
|
{
|
||||||
SANE_Status status;
|
SANE_Status status;
|
||||||
unsigned int more;
|
unsigned int more;
|
||||||
char header[12], rbuf[64];
|
char header[13], rbuf[64]; /* add one more byte for header buffer to correct buffer overflow issue,*/
|
||||||
|
|
||||||
DBG(8, "%s: %4s len %lu, payload len: %lu\n", __func__, cmd, len, plen);
|
DBG(8, "%s: %4s len %lu, payload len: %lu\n", __func__, cmd, len, plen);
|
||||||
|
|
||||||
|
|
|
@ -65,22 +65,24 @@ size_t eds_send(epsonds_scanner *s, void *buf, size_t length, SANE_Status *statu
|
||||||
|
|
||||||
size_t eds_recv(epsonds_scanner *s, void *buf, size_t length, SANE_Status *status)
|
size_t eds_recv(epsonds_scanner *s, void *buf, size_t length, SANE_Status *status)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = length; /* network interface needs to read header back even data is 0.*/
|
||||||
|
|
||||||
DBG(30, "%s: size = %ld, buf = %p\n", __func__, (long) length, buf);
|
DBG(30, "%s: size = %ld, buf = %p\n", __func__, (long) length, buf);
|
||||||
|
|
||||||
|
*status = SANE_STATUS_GOOD;
|
||||||
|
|
||||||
if (s->hw->connection == SANE_EPSONDS_NET) {
|
if (s->hw->connection == SANE_EPSONDS_NET) {
|
||||||
n = epsonds_net_read(s, buf, length, status);
|
n = epsonds_net_read(s, buf, length, status);
|
||||||
} else if (s->hw->connection == SANE_EPSONDS_USB) {
|
} else if (s->hw->connection == SANE_EPSONDS_USB) {
|
||||||
|
|
||||||
/* !!! only report an error if we don't read anything */
|
/* !!! only report an error if we don't read anything */
|
||||||
|
if (n) {
|
||||||
n = length;
|
|
||||||
*status = sanei_usb_read_bulk(s->fd, (SANE_Byte *)buf,
|
*status = sanei_usb_read_bulk(s->fd, (SANE_Byte *)buf,
|
||||||
(size_t *) &n);
|
(size_t *) &n);
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
*status = SANE_STATUS_GOOD;
|
*status = SANE_STATUS_GOOD;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (n < length) {
|
if (n < length) {
|
||||||
DBG(1, "%s: expected = %lu, got = %ld, canceling: %d\n", __func__,
|
DBG(1, "%s: expected = %lu, got = %ld, canceling: %d\n", __func__,
|
||||||
|
@ -111,10 +113,6 @@ SANE_Status eds_txrx(epsonds_scanner* s, char *txbuf, size_t txlen,
|
||||||
return SANE_STATUS_IO_ERROR;
|
return SANE_STATUS_IO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rxlen == 0) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
done = eds_recv(s, rxbuf, rxlen, &status);
|
done = eds_recv(s, rxbuf, rxlen, &status);
|
||||||
if (status != SANE_STATUS_GOOD) {
|
if (status != SANE_STATUS_GOOD) {
|
||||||
DBG(1, "%s: rx err, %s\n", __func__, sane_strstatus(status));
|
DBG(1, "%s: rx err, %s\n", __func__, sane_strstatus(status));
|
||||||
|
|
|
@ -1178,7 +1178,7 @@ SANE_Status
|
||||||
sane_start(SANE_Handle handle)
|
sane_start(SANE_Handle handle)
|
||||||
{
|
{
|
||||||
epsonds_scanner *s = (epsonds_scanner *)handle;
|
epsonds_scanner *s = (epsonds_scanner *)handle;
|
||||||
char buf[64];
|
char buf[65]; /* add one more byte to correct buffer overflow issue */
|
||||||
char cmd[100]; /* take care not to overflow */
|
char cmd[100]; /* take care not to overflow */
|
||||||
SANE_Status status = 0;
|
SANE_Status status = 0;
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue