[tor-commits] [stegotorus/master] Making code compile under Ubuntu 11.10 by casting insigned integers and using fscanf return values

zwol at torproject.org zwol at torproject.org
Fri Jul 20 23:17:06 UTC 2012


commit 6dad11131b4d4dfbfe06f14ea2c235d80c403123
Author: Linda Briesemeister <linda.briesemeister at sri.com>
Date:   Fri Dec 16 20:31:43 2011 +0000

    Making code compile under Ubuntu 11.10 by casting insigned integers and using fscanf return values
    
    git-svn-id: svn+ssh://spartan.csl.sri.com/svn/private/DEFIANCE@183 a58ff0ac-194c-e011-a152-003048836090
---
 src/steg/cookies.cc  |    3 +--
 src/steg/embed.cc    |   19 ++++++++++++++-----
 src/steg/jsSteg.cc   |    6 +++---
 src/steg/payloads.cc |    6 +++---
 4 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/steg/cookies.cc b/src/steg/cookies.cc
index c773386..aa2d108 100644
--- a/src/steg/cookies.cc
+++ b/src/steg/cookies.cc
@@ -29,7 +29,7 @@ int unwrap_cookie(unsigned char* inbuf, unsigned char* outbuf, int buflen) {
 int gen_one_cookie(unsigned char* outbuf, int cookielen, unsigned char* data, int datalen) {
   int sofar = 0;
   unsigned char c;
-  int namelen, vlen;
+  int namelen;
   int data_consumed = 0;
 
   if (cookielen < 4)
@@ -42,7 +42,6 @@ int gen_one_cookie(unsigned char* outbuf, int cookielen, unsigned char* data, in
   else 
     namelen = rand() % (cookielen - 3) + 1;
 
-  vlen = cookielen - namelen;
 
 
 
diff --git a/src/steg/embed.cc b/src/steg/embed.cc
index 75562bc..447d4cf 100644
--- a/src/steg/embed.cc
+++ b/src/steg/embed.cc
@@ -51,18 +51,27 @@ int millis_since(struct timeval *last) {
 void init_embed_traces() {
   // read in traces to use for connections
   FILE *trace_file = fopen("traces/embed.txt", "r");
-  fscanf(trace_file, "%d", &embed_num_traces);
+  if (fscanf(trace_file, "%d", &embed_num_traces) < 1) {
+    log_abort("couldn't read number of traces to use -- exiting");
+    exit(1);
+  }    
   embed_traces = (trace_t *)xmalloc(sizeof(trace_t) * embed_num_traces);
   for (int i = 0; i < embed_num_traces; i++) {
     int num_pkt;
-    fscanf(trace_file, "%d", &num_pkt);
+    if (fscanf(trace_file, "%d", &num_pkt) < 1) {
+      log_abort("couldn't read number of packets to use -- exiting");
+      exit(1);
+    }
     embed_traces[i].num_pkt = num_pkt;
     embed_traces[i].pkt_sizes = (short *)xmalloc(sizeof(short) * num_pkt);
     embed_traces[i].pkt_times = (int *)xmalloc(sizeof(int) * num_pkt);
     for (int j = 0; j < embed_traces[i].num_pkt; j++) {
-      fscanf(trace_file, "%hd %d",
-	     &embed_traces[i].pkt_sizes[j],
-	     &embed_traces[i].pkt_times[j]);
+      if (fscanf(trace_file, "%hd %d",
+		 &embed_traces[i].pkt_sizes[j],
+		 &embed_traces[i].pkt_times[j]) < 1) {
+	log_abort("couldn't read numbers of packet size and times to use -- exiting");
+	exit(1);
+      }
     }
   }
   log_debug("read %d traces to use", embed_num_traces);
diff --git a/src/steg/jsSteg.cc b/src/steg/jsSteg.cc
index c02a7b0..8cbff87 100644
--- a/src/steg/jsSteg.cc
+++ b/src/steg/jsSteg.cc
@@ -887,7 +887,7 @@ http_server_JS_transmit (steg_t*, struct evbuffer *source, conn_t *conn, unsigne
 int
 http_handle_client_JS_receive(steg_t *, conn_t *conn, struct evbuffer *dest, struct evbuffer* source) {
   struct evbuffer_ptr s2;
-  unsigned int response_len = 0;
+  int response_len = 0;
   unsigned int content_len = 0;
   unsigned int hdrLen;
   char buf[10];
@@ -949,7 +949,7 @@ http_handle_client_JS_receive(steg_t *, conn_t *conn, struct evbuffer *dest, str
   
   response_len += content_len;
 
-  if (response_len > evbuffer_get_length(source))
+  if (response_len > (int) evbuffer_get_length(source))
     return RECV_INCOMPLETE;
  
   // read the entire HTTP resp
@@ -1060,7 +1060,7 @@ http_handle_client_JS_receive(steg_t *, conn_t *conn, struct evbuffer *dest, str
   evbuffer_free(scratch);
   
   
-  if (response_len <= evbuffer_get_length(source)) {
+  if (response_len <= (int) evbuffer_get_length(source)) {
     if (evbuffer_drain(source, response_len) == -1) {
       log_warn("CLIENT ERROR: Failed to drain source");
       return RECV_BAD;
diff --git a/src/steg/payloads.cc b/src/steg/payloads.cc
index 84bfd00..34c2963 100644
--- a/src/steg/payloads.cc
+++ b/src/steg/payloads.cc
@@ -916,7 +916,7 @@ strInBinary (const char *pattern, unsigned int patternLen,
   char *cp = (char *)blob;
 
   while (1) {
-    if (blob+blobLen-cp < patternLen) break;
+    if (blob+blobLen-cp < (int) patternLen) break;
     if (*cp == pattern[0]) {
       if (memcmp(cp, pattern, patternLen) == 0) {
         found = 1;
@@ -955,7 +955,7 @@ strInBinary (const char *pattern, unsigned int patternLen,
 int has_eligible_HTTP_content (char* buf, int len, int type) {
   char* ptr = buf;
   char* matchptr;
-  int tjFlag=0, thFlag=0, ceFlag=0, teFlag=0, http304Flag=0, clZeroFlag=0, pdfFlag=0, swfFlag=0, gzipFlag=0;
+  int tjFlag=0, thFlag=0, ceFlag=0, teFlag=0, http304Flag=0, clZeroFlag=0, pdfFlag=0, swfFlag=0; //, gzipFlag=0; // compiler under Ubuntu complains about unused vars, so commenting out until we need it
   char* end, *cp;
 
 #ifdef DEBUG
@@ -997,7 +997,7 @@ int has_eligible_HTTP_content (char* buf, int len, int type) {
       }
 
     } else if (!strncmp(ptr, "Content-Encoding: gzip", 22)) {
-      gzipFlag = 1;
+      //      gzipFlag = 1; // commented out as variable is set but never read and Ubuntu compiler complains
     } else if (!strncmp(ptr, "Content-Encoding:", 17)) { // Content-Encoding that is not gzip
       ceFlag = 1;
     } else if (!strncmp(ptr, "Transfer-Encoding:", 18)) {





More information about the tor-commits mailing list