1
0
mirror of https://github.com/moparisthebest/curl synced 2025-02-28 09:21:50 -05:00

OS400: fix bugs in curl_*escape_ccsid() and reduce variables scope

This commit is contained in:
Patrick Monnerat 2014-10-14 15:43:25 +02:00
parent 473322ec66
commit e64bc7cde6
2 changed files with 21 additions and 29 deletions

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -167,7 +167,6 @@ dynconvert(int dccsid, const char * s, int slen, int sccsid)
char * cp; char * cp;
size_t dlen; size_t dlen;
int l; int l;
int l2;
static const char nullbyte = 0; static const char nullbyte = 0;
/* Like convert, but the destination is allocated and returned. */ /* Like convert, but the destination is allocated and returned. */
@ -191,7 +190,7 @@ dynconvert(int dccsid, const char * s, int slen, int sccsid)
Since destination code size is unknown, use a conversion to generate Since destination code size is unknown, use a conversion to generate
terminator. */ terminator. */
l2 = convert(d + l, dlen - l, dccsid, &nullbyte, -1, ASCII_CCSID); int l2 = convert(d + l, dlen - l, dccsid, &nullbyte, -1, ASCII_CCSID);
if(l2 < 0) { if(l2 < 0) {
free(d); free(d);
@ -217,10 +216,11 @@ slist_convert(int dccsid, struct curl_slist * from, int sccsid)
{ {
struct curl_slist * to = (struct curl_slist *) NULL; struct curl_slist * to = (struct curl_slist *) NULL;
char * cp;
for(; from; from = from->next) { for(; from; from = from->next) {
if(!(cp = dynconvert(dccsid, from->data, -1, sccsid))) { char * cp = dynconvert(dccsid, from->data, -1, sccsid);
if(!cp) {
curl_slist_free_all(to); curl_slist_free_all(to);
return (struct curl_slist *) NULL; return (struct curl_slist *) NULL;
} }
@ -269,7 +269,7 @@ curl_easy_escape_ccsid(CURL * handle, const char * string, int length,
return (char *) NULL; return (char *) NULL;
} }
s = dynconvert(ASCII_CCSID, s, length? length: -1, sccsid); s = dynconvert(ASCII_CCSID, string, length? length: -1, sccsid);
if(!s) if(!s)
return (char *) NULL; return (char *) NULL;
@ -300,7 +300,7 @@ curl_easy_unescape_ccsid(CURL * handle, const char * string, int length,
return (char *) NULL; return (char *) NULL;
} }
s = dynconvert(ASCII_CCSID, s, length? length: -1, sccsid); s = dynconvert(ASCII_CCSID, string, length? length: -1, sccsid);
if(!s) if(!s)
return (char *) NULL; return (char *) NULL;
@ -370,15 +370,13 @@ convert_version_info_string(const char * * stringp,
char * * bufp, int * left, unsigned int ccsid) char * * bufp, int * left, unsigned int ccsid)
{ {
int l;
/* Helper for curl_version_info_ccsid(): convert a string if defined. /* Helper for curl_version_info_ccsid(): convert a string if defined.
Result is stored in the `*left'-byte buffer at `*bufp'. Result is stored in the `*left'-byte buffer at `*bufp'.
`*bufp' and `*left' are updated accordingly. `*bufp' and `*left' are updated accordingly.
Return 0 if ok, else -1. */ Return 0 if ok, else -1. */
if(*stringp) { if(*stringp) {
l = convert(*bufp, *left, ccsid, *stringp, -1, ASCII_CCSID); int l = convert(*bufp, *left, ccsid, *stringp, -1, ASCII_CCSID);
if(l <= 0) if(l <= 0)
return -1; return -1;
@ -400,7 +398,6 @@ curl_version_info_ccsid(CURLversion stamp, unsigned int ccsid)
char * cp; char * cp;
int n; int n;
int nproto; int nproto;
int i;
curl_version_info_data * id; curl_version_info_data * id;
/* The assertion below is possible, because although the second operand /* The assertion below is possible, because although the second operand
@ -473,8 +470,9 @@ curl_version_info_ccsid(CURLversion stamp, unsigned int ccsid)
memcpy((char *) id, (char *) p, sizeof *p); memcpy((char *) id, (char *) p, sizeof *p);
if(id->protocols) { if(id->protocols) {
int i = nproto * sizeof id->protocols[0];
id->protocols = (const char * const *) cp; id->protocols = (const char * const *) cp;
i = nproto * sizeof id->protocols[0];
memcpy(cp, (char *) p->protocols, i); memcpy(cp, (char *) p->protocols, i);
cp += i; cp += i;
n -= i; n -= i;
@ -589,11 +587,11 @@ void
curl_certinfo_free_all(struct curl_certinfo *info) curl_certinfo_free_all(struct curl_certinfo *info)
{ {
int i;
/* Free all memory used by certificate info. */ /* Free all memory used by certificate info. */
if(info) { if(info) {
if(info->certinfo) { if(info->certinfo) {
int i;
for(i = 0; i < info->num_of_certs; i++) for(i = 0; i < info->num_of_certs; i++)
curl_slist_free_all(info->certinfo[i]); curl_slist_free_all(info->certinfo[i]);
free((char *) info->certinfo); free((char *) info->certinfo);
@ -612,13 +610,10 @@ curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...)
CURLcode ret; CURLcode ret;
unsigned int ccsid; unsigned int ccsid;
char * * cpp; char * * cpp;
char * s;
char * d;
struct SessionHandle * data; struct SessionHandle * data;
struct curl_slist * * slp; struct curl_slist * * slp;
struct curl_certinfo * cipf; struct curl_certinfo * cipf;
struct curl_certinfo * cipt; struct curl_certinfo * cipt;
int i;
/* WARNING: unlike curl_easy_get_info(), the strings returned by this /* WARNING: unlike curl_easy_get_info(), the strings returned by this
procedure have to be free'ed. */ procedure have to be free'ed. */
@ -634,13 +629,11 @@ curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...)
case CURLINFO_STRING: case CURLINFO_STRING:
ccsid = va_arg(arg, unsigned int); ccsid = va_arg(arg, unsigned int);
cpp = (char * *) paramp; cpp = (char * *) paramp;
s = *cpp;
if(s) { if(*cpp) {
d = dynconvert(ccsid, s, -1, ASCII_CCSID); *cpp = dynconvert(ccsid, *cpp, -1, ASCII_CCSID);
*cpp = d;
if(!d) if(!*cpp)
ret = CURLE_OUT_OF_MEMORY; ret = CURLE_OUT_OF_MEMORY;
} }
@ -661,6 +654,8 @@ curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...)
if(!cipt->certinfo) if(!cipt->certinfo)
ret = CURLE_OUT_OF_MEMORY; ret = CURLE_OUT_OF_MEMORY;
else { else {
int i;
cipt->num_of_certs = cipf->num_of_certs; cipt->num_of_certs = cipf->num_of_certs;
for(i = 0; i < cipf->num_of_certs; i++) for(i = 0; i < cipf->num_of_certs; i++)
if(cipf->certinfo[i]) if(cipf->certinfo[i])
@ -1107,7 +1102,6 @@ curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...)
char * s; char * s;
char * cp; char * cp;
unsigned int ccsid; unsigned int ccsid;
size_t len;
curl_off_t pfsize; curl_off_t pfsize;
static char testwarn = 1; static char testwarn = 1;
@ -1228,6 +1222,7 @@ curl_easy_setopt_ccsid(CURL * curl, CURLoption tag, ...)
} }
else { else {
/* Data length specified. */ /* Data length specified. */
size_t len;
if(pfsize < 0 || pfsize > SIZE_MAX) { if(pfsize < 0 || pfsize > SIZE_MAX) {
result = CURLE_OUT_OF_MEMORY; result = CURLE_OUT_OF_MEMORY;

View File

@ -94,11 +94,9 @@ static void
thdbufdestroy(void * private) thdbufdestroy(void * private)
{ {
localkey_t i;
buffer_t * p;
if(private) { if(private) {
p = (buffer_t *) private; buffer_t * p = (buffer_t *) private;
localkey_t i;
for(i = (localkey_t) 0; i < LK_LAST; i++) { for(i = (localkey_t) 0; i < LK_LAST; i++) {
if(p->buf) if(p->buf)
@ -1095,14 +1093,13 @@ struct berval * *
Curl_ldap_get_values_len_a(void * ld, LDAPMessage * entry, const char * attr) Curl_ldap_get_values_len_a(void * ld, LDAPMessage * entry, const char * attr)
{ {
int i;
char * cp; char * cp;
struct berval * * result; struct berval * * result;
cp = (char *) NULL; cp = (char *) NULL;
if(attr) { if(attr) {
i = strlen(attr); int i = strlen(attr);
if(!(cp = malloc(i + 1))) { if(!(cp = malloc(i + 1))) {
ldap_set_lderrno(ld, LDAP_NO_MEMORY, NULL, ldap_set_lderrno(ld, LDAP_NO_MEMORY, NULL,