snarf-fix-off-by-ones.diff 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. diff -ruNp snarf-7.0.orig/ftp.c snarf-7.0/ftp.c
  2. --- snarf-7.0.orig/ftp.c 2000-08-09 00:27:24.000000000 +0100
  3. +++ snarf-7.0/ftp.c 2007-03-30 20:47:46.046783664 +0100
  4. @@ -89,7 +89,7 @@ get_line(UrlResource *rsrc, int control)
  5. char *end;
  6. char buf[BUFSIZE+1];
  7. - while( (bytes_read = read(control, buf, BUFSIZE)) ) {
  8. + while( (bytes_read = read(control, buf, BUFSIZE)) > 0 ) {
  9. if( rsrc->options & OPT_VERBOSE )
  10. fwrite(buf, 1, bytes_read, stderr);
  11. diff -ruNp snarf-7.0.orig/http.c snarf-7.0/http.c
  12. --- snarf-7.0.orig/http.c 2007-03-30 20:46:21.176685880 +0100
  13. +++ snarf-7.0/http.c 2007-03-30 20:47:46.205759496 +0100
  14. @@ -365,7 +365,7 @@ http_transfer(UrlResource *rsrc)
  15. bytes_read = read(sock, buf, 8);
  16. - if( bytes_read == 0 ) {
  17. + if( bytes_read <= 0 ) {
  18. close(sock);
  19. return 0;
  20. }
  21. diff -ruNp snarf-7.0.orig/url.c snarf-7.0/url.c
  22. --- snarf-7.0.orig/url.c 1998-11-16 01:29:44.000000000 +0000
  23. +++ snarf-7.0/url.c 2007-03-30 20:47:46.205759496 +0100
  24. @@ -96,7 +96,7 @@ get_username(char *string, Url *u)
  25. return string;
  26. }
  27. - username = malloc(i);
  28. + username = malloc(i+1);
  29. memcpy(username, string, i + 1);
  30. username[i] = '\0';
  31. @@ -135,7 +135,7 @@ get_password(char *string, Url *u)
  32. for(i = 0 ; string[i] != '@'; i++);
  33. - password = malloc(i);
  34. + password = malloc(i+1);
  35. /* and finally, get the password portion */
  36. memcpy(password, string, i);