chntpw-140201-fix-bogus-errno-use.patch 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. diff -u chntpw-140201.orig/ntreg.c chntpw-140201/ntreg.c
  2. --- chntpw-140201.orig/ntreg.c 2019-06-22 13:09:59.583717369 -0700
  3. +++ chntpw-140201/ntreg.c 2019-06-22 13:16:26.714726148 -0700
  4. @@ -4241,10 +4241,13 @@
  5. do { /* On some platforms read may not block, and read in chunks. handle that */
  6. r = read(hdesc->filedesc, hdesc->buffer + rt, hdesc->size - rt);
  7. rt += r;
  8. - } while ( !errno && (rt < hdesc->size) );
  9. + } while ( r > 0 && (rt < hdesc->size) );
  10. - if (errno) {
  11. - perror("openHive(): read error: ");
  12. + if (r <= 0) {
  13. + if (r < 0)
  14. + perror("openHive(): read error");
  15. + else
  16. + fprintf(stderr, "openHive(): read error: unexpected EOF\n");
  17. closeHive(hdesc);
  18. return(NULL);
  19. }
  20. @@ -4255,10 +4258,10 @@
  21. return(NULL);
  22. }
  23. - if (r < sizeof (*hdesc)) {
  24. + if (rt < sizeof (*hdesc)) {
  25. fprintf(stderr,
  26. - "file is too small; got %d bytes while expecting %d or more\n",
  27. - r, sizeof (*hdesc));
  28. + "file is too small; got %d bytes while expecting %zu or more\n",
  29. + rt, sizeof (*hdesc));
  30. closeHive(hdesc);
  31. return(NULL);
  32. }