From 51c41296bca9e06cfa2d53ce3a0837e1a8697b1c Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 13 Jul 2012 18:20:13 +0100 Subject: Ensure text downloaded is null terminated --- getabook.c | 6 +++--- getbnbook.c | 6 +++--- getgbook.c | 8 ++++---- util.c | 25 ++++++++++++++++--------- util.h | 6 +++--- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/getabook.c b/getabook.c index d923029..8892394 100644 --- a/getabook.c +++ b/getabook.c @@ -73,7 +73,7 @@ int getpagelist() snprintf(url, URLMAX, "/gp/search-inside/service-data?method=getBookData&asin=%s", bookid); - if(!get("www.amazon.com", url, NULL, NULL, &buf)) + if(!get("www.amazon.com", url, NULL, NULL, &buf, 1)) return 1; /* amazon have a canonical asin, which is needed to get all available pages */ @@ -114,7 +114,7 @@ int getpageurls(int pagenum) { strncpy(url, "/gp/search-inside/service-data", URLMAX); snprintf(query, URLMAX, "method=goToPage&asin=%s&page=%d", bookid, pagenum); - if(!post("www.amazon.com", url, NULL, NULL, query, &buf)) + if(!post("www.amazon.com", url, NULL, NULL, query, &buf, 1)) return 1; fillurls(buf); @@ -133,7 +133,7 @@ int getpage(Page *page) return 1; } - if(gettofile("sitb-images.amazon.com", page->url, NULL, NULL, path)) { + if(gettofile("sitb-images.amazon.com", page->url, NULL, NULL, path, 0)) { fprintf(stderr, "%d failed\n", page->num); return 1; } diff --git a/getbnbook.c b/getbnbook.c index d6f06b8..dba1856 100644 --- a/getbnbook.c +++ b/getbnbook.c @@ -39,7 +39,7 @@ int getpagelist() snprintf(url, URLMAX, "/DigBooks/viewer/bookviewmanager.aspx?op=getbookinfo&ean=%s", bookid); - if(!get("search2.barnesandnoble.com", url, cookies, NULL, &buf)) + if(!get("search2.barnesandnoble.com", url, cookies, NULL, &buf, 1)) return 1; /* find page url structure */ @@ -79,7 +79,7 @@ int getpage(int pagenum) s=strchr(urlpath+7, '/'); snprintf(pageurl, STRMAX, s, pagenum); - if(gettofile("search2.barnesandnoble.com", pageurl, cookies, NULL, path)) { + if(gettofile("search2.barnesandnoble.com", pageurl, cookies, NULL, path, 0)) { fprintf(stderr, "%d failed\n", pagenum); return 1; } @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) bookdir = argv[argc-1]; /* get cookie */ - if(get("www.barnesandnoble.com", "/", NULL, cookies, &tmp)) + if(get("www.barnesandnoble.com", "/", NULL, cookies, &tmp, 0)) free(tmp); if(getpagelist()) { diff --git a/getgbook.c b/getgbook.c index 2042a75..b869b7f 100644 --- a/getgbook.c +++ b/getgbook.c @@ -44,7 +44,7 @@ int getpagelist() snprintf(url, URLMAX, "/books?id=%s&printsec=frontcover&redir_esc=y", bookid); - if(!get("books.google.com", url, NULL, NULL, &buf)) + if(!get("books.google.com", url, NULL, NULL, &buf, 1)) return 1; if((s = strstr(buf, "_OC_Run({\"page\":[")) == NULL) @@ -83,7 +83,7 @@ int getpageurls(char *pagecode, char *cookie) snprintf(url, URLMAX, "/books?id=%s&pg=%s&jscmd=click3&q=subject:a&redir_esc=y", bookid, pagecode); - if(!get("books.google.com", url, cookie, NULL, &buf)) + if(!get("books.google.com", url, cookie, NULL, &buf, 1)) return 1; c = buf; @@ -133,7 +133,7 @@ int getpage(Page *page) return 1; } - if(gettofile("books.google.com", page->url, page->cookie, NULL, path)) { + if(gettofile("books.google.com", page->url, page->cookie, NULL, path, 0)) { fprintf(stderr, "%s failed\n", page->name); return 1; } @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) /* get cookies */ for(i=0;i