Conrad Meyer fd64259
--- chntpw-110511.orig/ntreg.c	2011-05-11 12:33:56.000000000 -0700
Conrad Meyer 13bf89e
+++ chntpw-110511/ntreg.c	2011-12-18 17:09:06.290818997 -0800
Conrad Meyer 13bf89e
@@ -190,14 +190,18 @@
Conrad Meyer fd64259
 
Conrad Meyer fd64259
 int fmyinput(char *prmpt, char *ibuf, int maxlen)
Conrad Meyer fd64259
 {
Conrad Meyer fd64259
-   
Conrad Meyer fd64259
+   int len;
Conrad Meyer fd64259
    printf("%s",prmpt);
Conrad Meyer fd64259
    
Conrad Meyer fd64259
    fgets(ibuf,maxlen+1,stdin);
Conrad Meyer fd64259
+   len = strlen(ibuf);
Conrad Meyer fd64259
    
Conrad Meyer fd64259
-   ibuf[strlen(ibuf)-1] = 0;
Conrad Meyer 13bf89e
+   if (len) {
Conrad Meyer fd64259
+      ibuf[len-1] = 0;
Conrad Meyer 13bf89e
+      --len;
Conrad Meyer 13bf89e
+   }
Conrad Meyer fd64259
    
Conrad Meyer fd64259
-   return(strlen(ibuf));
Conrad Meyer fd64259
+   return len;
Conrad Meyer fd64259
 }
Conrad Meyer fd64259
 
Conrad Meyer fd64259
 /* Print len number of hexbytes */
Conrad Meyer 13bf89e
@@ -4119,6 +4123,14 @@
Conrad Meyer 13bf89e
     closeHive(hdesc);
Conrad Meyer fd64259
     return(NULL);
Conrad Meyer fd64259
   }
Conrad Meyer 13bf89e
+
Conrad Meyer fd64259
+  if (r < sizeof (*hdesc)) {
Conrad Meyer fd64259
+    fprintf(stderr,
Conrad Meyer fd64259
+	    "file is too small; got %d bytes while expecting %d or more\n",
Conrad Meyer fd64259
+	    r, sizeof (*hdesc));
Conrad Meyer fd64259
+    closeHive(hdesc);
Conrad Meyer fd64259
+    return(NULL);
Conrad Meyer fd64259
+  }
Conrad Meyer 13bf89e
 
Conrad Meyer fd64259
   /* Now run through file, tallying all pages */
Conrad Meyer fd64259
   /* NOTE/KLUDGE: Assume first page starts at offset 0x1000 */