1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
Description: Fix issues in code
The first two were spotted via inspection by Fedora team,
the third one was added to address an error found using valgrind:
$ : > j && valgrind ./reged -e j
~/w/co/chntpw:
==16084== by 0x4011E3: main (reged.c:103)
get_abs_path: Not a 'nk' node!
* ntreg.c (fmyinput): Don't clobber ibuf[-1] upon NUL input.
* ntreg.c (convert_string): Don't segfault upon low memory.
* ntreg.c (openHive): Don't read uninitialized when file is too small.
Author: Jim Meyering <meyering@redhat.com>
Date: Mon, 20 Jul 2009 17:31:40 +0200
Forwarded: no
--- a/ntreg.c
+++ b/ntreg.c
@@ -227,14 +227,18 @@
int fmyinput(char *prmpt, char *ibuf, int maxlen)
{
-
+ int len;
printf("%s",prmpt);
fgets(ibuf,maxlen+1,stdin);
+ len = strlen(ibuf);
- ibuf[strlen(ibuf)-1] = 0;
-
- return(strlen(ibuf));
+ if (len) {
+ ibuf[len-1] = 0;
+ --len;
+ }
+
+ return len;
}
/* Print len number of hexbytes */
@@ -4250,6 +4254,14 @@
closeHive(hdesc);
return(NULL);
}
+
+ if (r < sizeof (*hdesc)) {
+ fprintf(stderr,
+ "file is too small; got %d bytes while expecting %d or more\n",
+ r, sizeof (*hdesc));
+ closeHive(hdesc);
+ return(NULL);
+ }
/* Now run through file, tallying all pages */
/* NOTE/KLUDGE: Assume first page starts at offset 0x1000 */
|