From: Nikos Mavrogiannopoulos Date: Sat, 22 Nov 2008 22:13:31 +0000 (+0200) Subject: Converted non-C compliant code to standard C. The usage of X-Git-Tag: gnutls_2_7_3~37 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=df738bac045956ef407bc3bd056b7b10224dfed9;p=thirdparty%2Fgnutls.git Converted non-C compliant code to standard C. The usage of structures like: struct x { int el1; char str[1]; } and the trick of using a single allocation for str and the structure itself by allocating sizeof(x) + strlen()-1, are questionable. They were converted to: struct x { int el1; char *str; } and there is a single allocation of sizeof(x)+strlen() but then the str pointer is updated to point to the rest of the data. --- diff --git a/lib/opencdk/context.h b/lib/opencdk/context.h index 71595a907a..b695f0f45d 100644 --- a/lib/opencdk/context.h +++ b/lib/opencdk/context.h @@ -99,7 +99,7 @@ struct cdk_subpkt_s { struct cdk_subpkt_s * next; u32 size; byte type; - byte d[1]; + byte *d; }; struct cdk_keylist_s { @@ -121,7 +121,7 @@ struct cdk_dek_s { struct cdk_strlist_s { struct cdk_strlist_s * next; - char d[1]; + char *d; }; #endif /* CDK_CONTEXT_H */ diff --git a/lib/opencdk/literal.c b/lib/opencdk/literal.c index aee17eea23..fc4ee4fdc3 100644 --- a/lib/opencdk/literal.c +++ b/lib/opencdk/literal.c @@ -199,7 +199,8 @@ literal_encode (void *data, FILE * in, FILE * out) filelen = strlen (pfx->filename); cdk_pkt_new (&pkt); - pt = pkt->pkt.literal = cdk_calloc (1, sizeof *pt + filelen - 1); + pt = pkt->pkt.literal = cdk_calloc (1, sizeof *pt + filelen); + pt->name = pt + sizeof(*pt); if (!pt) { cdk_pkt_release (pkt); diff --git a/lib/opencdk/misc.c b/lib/opencdk/misc.c index bc407b2052..13e7fd5275 100644 --- a/lib/opencdk/misc.c +++ b/lib/opencdk/misc.c @@ -94,9 +94,10 @@ cdk_strlist_add (cdk_strlist_t * list, const char *string) if (!string) return NULL; - sl = cdk_calloc (1, sizeof *sl + strlen (string) + 1); + sl = cdk_calloc (1, sizeof *sl + strlen (string) + 2); if (!sl) return NULL; + sl->d = sl + sizeof(*sl); strcpy (sl->d, string); sl->next = *list; *list = sl; diff --git a/lib/opencdk/new-packet.c b/lib/opencdk/new-packet.c index 9e788cd939..501d65293f 100644 --- a/lib/opencdk/new-packet.c +++ b/lib/opencdk/new-packet.c @@ -290,6 +290,7 @@ cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype) pkt->pkt.user_id = cdk_calloc (1, sizeof pkt->pkt.user_id); if (!pkt->pkt.user_id) return CDK_Out_Of_Core; + pkt->pkt.user_id->name = NULL; break; case CDK_PKT_PUBLIC_KEY: @@ -338,6 +339,7 @@ cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype) pkt->pkt.literal = cdk_calloc (1, sizeof *pkt->pkt.literal); if (!pkt->pkt.literal) return CDK_Out_Of_Core; + pkt->pkt.literal->name = NULL; break; default: @@ -383,9 +385,11 @@ _cdk_copy_userid (cdk_pkt_userid_t * dst, cdk_pkt_userid_t src) return CDK_Inv_Value; *dst = NULL; - u = cdk_calloc (1, sizeof *u + strlen (src->name) + 1); + u = cdk_calloc (1, sizeof *u + strlen (src->name) + 2); if (!u) return CDK_Out_Of_Core; + u->name = (void*)u + sizeof(*u); + memcpy (u, src, sizeof *u); memcpy (u->name, src->name, strlen (src->name)); u->prefs = _cdk_copy_prefs (src->prefs); @@ -620,9 +624,11 @@ cdk_subpkt_new (size_t size) if (!size) return NULL; - s = cdk_calloc (1, sizeof *s + size + 1); + s = cdk_calloc (1, sizeof *s + size + 2); if (!s) return NULL; + s->d = (void*)s + sizeof(*s); + return s; } diff --git a/lib/opencdk/opencdk.h b/lib/opencdk/opencdk.h index 23c7bba9e8..0ba17af47a 100644 --- a/lib/opencdk/opencdk.h +++ b/lib/opencdk/opencdk.h @@ -430,7 +430,7 @@ struct cdk_pkt_userid_s unsigned char *attrib_img; /* Tag 17 if not null */ size_t attrib_len; cdk_pkt_signature_t selfsig; - char name[1]; + char *name; }; typedef struct cdk_pkt_userid_s *cdk_pkt_userid_t; @@ -538,7 +538,7 @@ struct cdk_pkt_literal_s int mode; unsigned int timestamp; int namelen; - char name[1]; + char *name; }; typedef struct cdk_pkt_literal_s *cdk_pkt_literal_t; diff --git a/lib/opencdk/read-packet.c b/lib/opencdk/read-packet.c index cc3c40f2ba..2869c2ce05 100644 --- a/lib/opencdk/read-packet.c +++ b/lib/opencdk/read-packet.c @@ -833,9 +833,10 @@ read_literal (cdk_stream_t inp, size_t pktlen, pt->namelen = cdk_stream_getc (inp); if (pt->namelen > 0) { - *ret_pt = pt = cdk_realloc (pt, sizeof *pt + pt->namelen + 1); + *ret_pt = pt = cdk_realloc (pt, sizeof *pt + pt->namelen + 2); if (!pt) return CDK_Out_Of_Core; + pt->name = (void*)pt + sizeof(*pt); rc = stream_read (inp, pt->name, pt->namelen, &nread); if (rc) return rc; @@ -997,15 +998,18 @@ cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt) + pkt->pktlen + 16 + 1); if (!pkt->pkt.user_id) return CDK_Out_Of_Core; + pkt->pkt.user_id->name = (void*)pkt->pkt.user_id + sizeof(*pkt->pkt.user_id); + rc = read_attribute (inp, pktlen, pkt->pkt.user_id); pkt->pkttype = CDK_PKT_ATTRIBUTE; break; case CDK_PKT_USER_ID: pkt->pkt.user_id = cdk_calloc (1, sizeof *pkt->pkt.user_id - + pkt->pktlen); + + pkt->pktlen + 1); if (!pkt->pkt.user_id) return CDK_Out_Of_Core; + pkt->pkt.user_id->name = (void*)pkt->pkt.user_id + sizeof(*pkt->pkt.user_id); rc = read_user_id (inp, pktlen, pkt->pkt.user_id); break;