Bug 237740 - dd(1) always report false error about lseek(2) after read(2) error with 'conv=noerror' / dd(1) wrongly lseek(2)ed input file on read(2) error with 'conv=noerror'
Summary: dd(1) always report false error about lseek(2) after read(2) error with 'conv...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2019-05-04 03:41 UTC by WHR
Modified: 2019-05-21 17:53 UTC (History)
1 user (show)

See Also:


Attachments
fix-dd-noerror-lseek.diff (811 bytes, patch)
2019-05-04 03:41 UTC, WHR
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description WHR 2019-05-04 03:41:23 UTC
Created attachment 204204 [details]
fix-dd-noerror-lseek.diff

Reporting 2 bugs in the same place.

In the latest revision 341257 of 'dd.c', at https://svnweb.freebsd.org/base/head/bin/dd/dd.c?view=log , line 420, the error condition should be 'lseek(...) == -1'. The code:
                        if (in.flags & ISSEEK &&
                            lseek(in.fd, (off_t)in.dbsz, SEEK_CUR))
should be:
                        if (in.flags & ISSEEK &&
                            lseek(in.fd, (off_t)in.dbsz, SEEK_CUR) == -1)


Another bug is, when a read(2) error occurred, read(2) may actually read something and change the file position then returning -1; when this happens the later lseek(2) call will over seeking the current position, skipping data that unrelated to the first read(2) error.

The attached patch fix both bug.