Debian Codegraph @

debian/patches/12_readonly_filesystem

raw
1 Description: Fix reading files in read-only filesystems
2
3 chntpw fails to read files from read-only filesystems, despite having some
4 logic to handle this:
5
6 # chntpw -e /c/Windows/System32/config/SOFTWARE
7 chntpw version 1.00 140201, (c) Petter N Hagen
8 openHive(/c/Windows/System32/config/SOFTWARE) failed: Read-only file system, trying read-only
9 openHive(): read error: : Read-only file system
10 chntpw: Unable to open/read a hive, exiting..
11 #
12
13 This is due to using errno as an error checking mechanism; it should only be
14 used when one knows a function has failed. This patch fixes this problem. It
15 also adds support for the non-fatal EINTR error, and fixes yet another bug
16 where the last read size is used in a check instead of the whole file size.
17
18 Author: Sam Hocevar <[email protected]>
19 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762508
20
21 Index: chntpw-1.0/ntreg.c
22 ===================================================================
23 --- chntpw-1.0.orig/ntreg.c
24 +++ chntpw-1.0/ntreg.c
25 @@ -4241,9 +4241,9 @@ struct hive *openHive(char *filename, in
26 do { /* On some platforms read may not block, and read in chunks. handle that */
27 r = read(hdesc->filedesc, hdesc->buffer + rt, hdesc->size - rt);
28 rt += r;
29 - } while ( !errno && (rt < hdesc->size) );
30 + } while ( (r > 0 || (r < 0 && errno == EINTR)) && (rt < hdesc->size) );
31
32 - if (errno) {
33 + if (r < 0) {
34 perror("openHive(): read error: ");
35 closeHive(hdesc);
36 return(NULL);
37 @@ -4255,10 +4255,10 @@ struct hive *openHive(char *filename, in
38 return(NULL);
39 }
40
41 - if (r < sizeof (*hdesc)) {
42 + if (rt < sizeof (*hdesc)) {
43 fprintf(stderr,
44 "file is too small; got %d bytes while expecting %d or more\n",
45 - r, sizeof (*hdesc));
46 + rt, sizeof (*hdesc));
47 closeHive(hdesc);
48 return(NULL);
49 }