author | erik <erik> | 2007-01-24 19:54:07 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 19:54:07 (UTC) |
commit | 89e81059e832ff77c2f0ac8b9db12f80eafa03fc (patch) (side-by-side diff) | |
tree | 99a130fc643d2aeefdecab452f644e7b61a5f50e /noncore/todayplugins/stockticker/libstocks/http.c | |
parent | 035bbc5bf689839c8d8e7be37f347b0dd900fccf (diff) | |
download | opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.zip opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.gz opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.bz2 |
Each file in this commit has an instance where a pointer is checked at
one point in the code and then not checked in another point in the code.
If it needed to be checked once, it needs to be checked the other time. If not
the application could segfault.
Diffstat (limited to 'noncore/todayplugins/stockticker/libstocks/http.c') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/http.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/http.c b/noncore/todayplugins/stockticker/libstocks/http.c index 2f38f8a..cc78ab7 100644 --- a/noncore/todayplugins/stockticker/libstocks/http.c +++ b/noncore/todayplugins/stockticker/libstocks/http.c @@ -117,187 +117,187 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) #elif __WINDOWS__ closesocket(s); #endif return ERRCONN; } /* create header */ if (http_proxy_server) { sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012", http_server, http_file); } else { sprintf(header,"GET %s HTTP/1.0\015\012\015\012",http_file); } hlg=strlen(header); /* send header */ #ifdef __UNIX__ if (write(s,header,hlg)!=hlg) #elif __WINDOWS__ if (send(s,header,hlg, 0)!=hlg) #endif { #ifdef DEBUG printf(" send header : NOK\n"); #endif return ERRWHEA; } data_lgr = 0; r=1; while(r) { /* Clear Buffer */ memset(buf,0,BUF_SIZE+1); #ifdef __UNIX__ r=read(s,buf,BUF_SIZE); #elif __WINDOWS__ r=recv(s,buf,BUF_SIZE,0); #endif if (r) { if(!data_lgr) { if((data = malloc(r+1))==NULL) { fprintf(stderr,"Memory allocating error (%s line %d)\n" ,__FILE__, __LINE__); exit(1); } memcpy(data,buf,r); data_lgr = r; data[r]=0; } else { if((temp = malloc(r+data_lgr+1))==NULL) { fprintf(stderr,"Memory allocating error (%s line %d)\n" ,__FILE__, __LINE__); exit(1); } memcpy(temp, data, data_lgr); memcpy(temp+data_lgr, buf, r); temp[r+data_lgr]=0; data_lgr += r; free(data); data = temp; } } } /* close socket */ #ifdef __UNIX__ close(s); #elif __WINDOWS__ closesocket(s); #endif #ifdef DEBUG printf("%s\n", data); #endif /* get headers to test status line */ /* and to split headers and content */ temp = data; header_founded = 0; while( !header_founded ) { - if (*temp==0) return ERRRHEA; + if (!temp || *temp==0) return ERRRHEA; if( *temp==0x0A ) { /* test if it is the header end */ temp ++; if (*temp == 0x0D) temp++; if (*temp == 0x0A) header_founded = 1; } else temp++; } *temp = 0; temp++; sscanf(data,"HTTP/1.%*d %03d",&error_code); if (error_code != 200) { #ifdef DEBUG printf(" HTTP error code : %d\n", error_code); #endif free(data); return ERRPAHD; } if ((csv_ptr = malloc(strlen(temp)+1))==NULL) { free(data); fprintf(stderr,"Memory allocating error (%s line %d)\n" ,__FILE__, __LINE__); exit(1); } memcpy(csv_ptr, temp, strlen(temp)+1); free(data); #ifdef DEBUG printf(" CSV\n"); printf("%s,\n", csv_ptr); #endif *pdata = csv_ptr; return 0; } /******************************************************************************/ /* Set the proxy server to use */ /******************************************************************************/ libstocks_return_code set_proxy(char *proxy) { char *ptr; char c; #ifdef DEBUG printf("*set_proxy\n"); #endif /* Parse the proxy URL - It must start with http:// */ #ifdef __UNIX__ if (strncasecmp("http://",proxy,7)) return ERRPROX; #elif __WINDOWS__ if (_mbsnbicmp("http://",proxy,7)) return ERRPROX; #endif proxy+=7; /* find ":" in the proxy url */ ptr = proxy; for (c=*ptr; (c && c!=':');) c=*ptr++; /* ptr points just after the ":" or at the end of proxy if : not founded */ *(ptr-1)=0; /* clear the ":" */ http_proxy_server=strdup(proxy); #ifdef DEBUG printf("http_proxy_server : %s\n", http_proxy_server); #endif /* get the port number of the url */ if (sscanf(ptr,"%d",&http_proxy_port)!=1) return ERRPROX; #ifdef DEBUG printf("http_proxy_port : %d\n", http_proxy_port); #endif return 0; } |