From: Mimi Zohar <zohar@linux.vnet.ibm.com>
To: David Howells <dhowells@redhat.com>
Cc: keyrings@linux-nfs.org, mcgrof@gmail.com, kyle@kernel.org,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, dwmw2@infradead.org
Subject: Re: [PATCH 02/27] ASN.1: Copy string names to tokens in ASN.1 compiler [ver #7]
Date: Wed, 05 Aug 2015 14:13:04 -0400 [thread overview]
Message-ID: <1438798384.2489.6.camel@linux.vnet.ibm.com> (raw)
In-Reply-To: <20150805134345.9984.84254.stgit@warthog.procyon.org.uk>
Hi David,
This patch isn't applying properly against linux-security/next. The
rest seem to be fine.
Mimi
On Wed, 2015-08-05 at 14:43 +0100, David Howells wrote:
> Copy string names to tokens in ASN.1 compiler rather than storing a pointer
> into the source text. This means we don't have to use "%*.*s" all over the
> place.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> Reviewed-by: David Woodhouse <David.Woodhouse@intel.com>
> ---
>
> scripts/asn1_compiler.c | 155 ++++++++++++++++++++++-------------------------
> 1 file changed, 73 insertions(+), 82 deletions(-)
>
> diff --git a/scripts/asn1_compiler.c b/scripts/asn1_compiler.c
> index 6e4ba992a51f..e000f44e37b8 100644
> --- a/scripts/asn1_compiler.c
> +++ b/scripts/asn1_compiler.c
> @@ -294,8 +294,8 @@ static const char *const directives[NR__DIRECTIVES] = {
>
> struct action {
> struct action *next;
> + char *name;
> unsigned char index;
> - char name[];
> };
>
> static struct action *action_list;
> @@ -306,7 +306,7 @@ struct token {
> enum token_type token_type : 8;
> unsigned char size;
> struct action *action;
> - const char *value;
> + char *content;
> struct type *type;
> };
>
> @@ -328,11 +328,9 @@ static int directive_compare(const void *_key, const void *_pdir)
> dlen = strlen(dir);
> clen = (dlen < token->size) ? dlen : token->size;
>
> - //debug("cmp(%*.*s,%s) = ",
> - // (int)token->size, (int)token->size, token->value,
> - // dir);
> + //debug("cmp(%s,%s) = ", token->content, dir);
>
> - val = memcmp(token->value, dir, clen);
> + val = memcmp(token->content, dir, clen);
> if (val != 0) {
> //debug("%d [cmp]\n", val);
> return val;
> @@ -352,7 +350,7 @@ static int directive_compare(const void *_key, const void *_pdir)
> static void tokenise(char *buffer, char *end)
> {
> struct token *tokens;
> - char *line, *nl, *p, *q;
> + char *line, *nl, *start, *p, *q;
> unsigned tix, lineno;
>
> /* Assume we're going to have half as many tokens as we have
> @@ -411,11 +409,11 @@ static void tokenise(char *buffer, char *end)
> break;
>
> tokens[tix].line = lineno;
> - tokens[tix].value = p;
> + start = p;
>
> /* Handle string tokens */
> if (isalpha(*p)) {
> - const char **dir;
> + const char **dir, *start = p;
>
> /* Can be a directive, type name or element
> * name. Find the end of the name.
> @@ -426,10 +424,18 @@ static void tokenise(char *buffer, char *end)
> tokens[tix].size = q - p;
> p = q;
>
> + tokens[tix].content = malloc(tokens[tix].size + 1);
> + if (!tokens[tix].content) {
> + perror(NULL);
> + exit(1);
> + }
> + memcpy(tokens[tix].content, start, tokens[tix].size);
> + tokens[tix].content[tokens[tix].size] = 0;
> +
> /* If it begins with a lowercase letter then
> * it's an element name
> */
> - if (islower(tokens[tix].value[0])) {
> + if (islower(tokens[tix].content[0])) {
> tokens[tix++].token_type = TOKEN_ELEMENT_NAME;
> continue;
> }
> @@ -458,6 +464,13 @@ static void tokenise(char *buffer, char *end)
> q++;
> tokens[tix].size = q - p;
> p = q;
> + tokens[tix].content = malloc(tokens[tix].size + 1);
> + if (!tokens[tix].content) {
> + perror(NULL);
> + exit(1);
> + }
> + memcpy(tokens[tix].content, start, tokens[tix].size);
> + tokens[tix].content[tokens[tix].size] = 0;
> tokens[tix++].token_type = TOKEN_NUMBER;
> continue;
> }
> @@ -466,6 +479,7 @@ static void tokenise(char *buffer, char *end)
> if (memcmp(p, "::=", 3) == 0) {
> p += 3;
> tokens[tix].size = 3;
> + tokens[tix].content = "::=";
> tokens[tix++].token_type = TOKEN_ASSIGNMENT;
> continue;
> }
> @@ -475,12 +489,14 @@ static void tokenise(char *buffer, char *end)
> if (memcmp(p, "({", 2) == 0) {
> p += 2;
> tokens[tix].size = 2;
> + tokens[tix].content = "({";
> tokens[tix++].token_type = TOKEN_OPEN_ACTION;
> continue;
> }
> if (memcmp(p, "})", 2) == 0) {
> p += 2;
> tokens[tix].size = 2;
> + tokens[tix].content = "})";
> tokens[tix++].token_type = TOKEN_CLOSE_ACTION;
> continue;
> }
> @@ -491,22 +507,27 @@ static void tokenise(char *buffer, char *end)
> switch (*p) {
> case '{':
> p += 1;
> + tokens[tix].content = "{";
> tokens[tix++].token_type = TOKEN_OPEN_CURLY;
> continue;
> case '}':
> p += 1;
> + tokens[tix].content = "}";
> tokens[tix++].token_type = TOKEN_CLOSE_CURLY;
> continue;
> case '[':
> p += 1;
> + tokens[tix].content = "[";
> tokens[tix++].token_type = TOKEN_OPEN_SQUARE;
> continue;
> case ']':
> p += 1;
> + tokens[tix].content = "]";
> tokens[tix++].token_type = TOKEN_CLOSE_SQUARE;
> continue;
> case ',':
> p += 1;
> + tokens[tix].content = ",";
> tokens[tix++].token_type = TOKEN_COMMA;
> continue;
> default:
> @@ -527,10 +548,7 @@ static void tokenise(char *buffer, char *end)
> {
> int n;
> for (n = 0; n < nr_tokens; n++)
> - debug("Token %3u: '%*.*s'\n",
> - n,
> - (int)token_list[n].size, (int)token_list[n].size,
> - token_list[n].value);
> + debug("Token %3u: '%s'\n", n, token_list[n].content);
> }
> #endif
> }
> @@ -709,7 +727,7 @@ static int type_index_compare(const void *_a, const void *_b)
> if ((*a)->name->size != (*b)->name->size)
> return (*a)->name->size - (*b)->name->size;
> else
> - return memcmp((*a)->name->value, (*b)->name->value,
> + return memcmp((*a)->name->content, (*b)->name->content,
> (*a)->name->size);
> }
>
> @@ -722,7 +740,7 @@ static int type_finder(const void *_key, const void *_ti)
> if (token->size != type->name->size)
> return token->size - type->name->size;
> else
> - return memcmp(token->value, type->name->value,
> + return memcmp(token->content, type->name->content,
> token->size);
> }
>
> @@ -776,10 +794,7 @@ static void build_type_list(void)
> #if 0
> for (n = 0; n < nr_types; n++) {
> struct type *type = type_index[n];
> - debug("- %*.*s\n",
> - (int)type->name->size,
> - (int)type->name->size,
> - type->name->value);
> + debug("- %*.*s\n", type->name->content);
> }
> #endif
> }
> @@ -809,9 +824,8 @@ static void parse(void)
> type->element->type_def = type;
>
> if (cursor != type[1].name) {
> - fprintf(stderr, "%s:%d: Parse error at token '%*.*s'\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Parse error at token '%s'\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
>
> @@ -878,34 +892,31 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
> cursor++;
> break;
> default:
> - fprintf(stderr, "%s:%d: Unrecognised tag class token '%*.*s'\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Unrecognised tag class token '%s'\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
>
> if (cursor >= end)
> goto overrun_error;
> if (cursor->token_type != TOKEN_NUMBER) {
> - fprintf(stderr, "%s:%d: Missing tag number '%*.*s'\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Missing tag number '%s'\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
>
> element->tag &= ~0x1f;
> - element->tag |= strtoul(cursor->value, &p, 10);
> + element->tag |= strtoul(cursor->content, &p, 10);
> element->flags |= ELEMENT_TAG_SPECIFIED;
> - if (p - cursor->value != cursor->size)
> + if (p - cursor->content != cursor->size)
> abort();
> cursor++;
>
> if (cursor >= end)
> goto overrun_error;
> if (cursor->token_type != TOKEN_CLOSE_SQUARE) {
> - fprintf(stderr, "%s:%d: Missing closing square bracket '%*.*s'\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Missing closing square bracket '%s'\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
> cursor++;
> @@ -1005,9 +1016,8 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
> ref = bsearch(cursor, type_index, nr_types, sizeof(type_index[0]),
> type_finder);
> if (!ref) {
> - fprintf(stderr, "%s:%d: Type '%*.*s' undefined\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Type '%s' undefined\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
> cursor->type = *ref;
> @@ -1056,9 +1066,8 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
> break;
>
> default:
> - fprintf(stderr, "%s:%d: Token '%*.*s' does not introduce a type\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Token '%s' does not introduce a type\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
>
> @@ -1075,20 +1084,18 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
> if (cursor >= end)
> goto overrun_error;
> if (cursor->token_type != TOKEN_ELEMENT_NAME) {
> - fprintf(stderr, "%s:%d: Token '%*.*s' is not an action function name\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Token '%s' is not an action function name\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
>
> - action = malloc(sizeof(struct action) + cursor->size + 1);
> + action = malloc(sizeof(struct action));
> if (!action) {
> perror(NULL);
> exit(1);
> }
> action->index = 0;
> - memcpy(action->name, cursor->value, cursor->size);
> - action->name[cursor->size] = 0;
> + action->name = cursor->content;
>
> for (ppaction = &action_list;
> *ppaction;
> @@ -1118,9 +1125,8 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
> if (cursor >= end)
> goto overrun_error;
> if (cursor->token_type != TOKEN_CLOSE_ACTION) {
> - fprintf(stderr, "%s:%d: Missing close action, got '%*.*s'\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Missing close action, got '%s'\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
> cursor++;
> @@ -1130,9 +1136,8 @@ static struct element *parse_type(struct token **_cursor, struct token *end,
> return top;
>
> parse_error:
> - fprintf(stderr, "%s:%d: Unexpected token '%*.*s'\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Unexpected token '%s'\n",
> + filename, cursor->line, cursor->content);
> exit(1);
>
> overrun_error:
> @@ -1150,9 +1155,8 @@ static struct element *parse_compound(struct token **_cursor, struct token *end,
> struct token *cursor = *_cursor, *name;
>
> if (cursor->token_type != TOKEN_OPEN_CURLY) {
> - fprintf(stderr, "%s:%d: Expected compound to start with brace not '%*.*s'\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Expected compound to start with brace not '%s'\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
> cursor++;
> @@ -1193,9 +1197,8 @@ static struct element *parse_compound(struct token **_cursor, struct token *end,
> children->flags &= ~ELEMENT_CONDITIONAL;
>
> if (cursor->token_type != TOKEN_CLOSE_CURLY) {
> - fprintf(stderr, "%s:%d: Expected compound closure, got '%*.*s'\n",
> - filename, cursor->line,
> - (int)cursor->size, (int)cursor->size, cursor->value);
> + fprintf(stderr, "%s:%d: Expected compound closure, got '%s'\n",
> + filename, cursor->line, cursor->content);
> exit(1);
> }
> cursor++;
> @@ -1212,10 +1215,8 @@ static void dump_element(const struct element *e, int level)
> {
> const struct element *c;
> const struct type *t = e->type_def;
> - const char *name = e->name ? e->name->value : ".";
> - int nsize = e->name ? e->name->size : 1;
> - const char *tname = t && t->name ? t->name->value : ".";
> - int tnsize = t && t->name ? t->name->size : 1;
> + const char *name = e->name ? e->name->content : ".";
> + const char *tname = t && t->name ? t->name->content : ".";
> char tag[32];
>
> if (e->class == 0 && e->method == 0 && e->tag == 0)
> @@ -1231,7 +1232,7 @@ static void dump_element(const struct element *e, int level)
> asn1_methods[e->method],
> e->tag);
>
> - printf("%c%c%c%c%c %c %*s[*] \e[33m%s\e[m %*.*s %*.*s \e[35m%s\e[m\n",
> + printf("%c%c%c%c%c %c %*s[*] \e[33m%s\e[m %s %s \e[35m%s\e[m\n",
> e->flags & ELEMENT_IMPLICIT ? 'I' : '-',
> e->flags & ELEMENT_EXPLICIT ? 'E' : '-',
> e->flags & ELEMENT_TAG_SPECIFIED ? 'T' : '-',
> @@ -1240,8 +1241,8 @@ static void dump_element(const struct element *e, int level)
> "-tTqQcaro"[e->compound],
> level, "",
> tag,
> - tnsize, tnsize, tname,
> - nsize, nsize, name,
> + tname,
> + name,
> e->action ? e->action->name : "");
> if (e->compound == TYPE_REF)
> dump_element(e->type->type->element, level + 3);
> @@ -1454,9 +1455,7 @@ static void render_element(FILE *out, struct element *e, struct element *tag)
> outofline = 1;
>
> if (e->type_def && out) {
> - render_more(out, "\t// %*.*s\n",
> - (int)e->type_def->name->size, (int)e->type_def->name->size,
> - e->type_def->name->value);
> + render_more(out, "\t// %s\n", e->type_def->name->content);
> }
>
> /* Render the operation */
> @@ -1468,9 +1467,7 @@ static void render_element(FILE *out, struct element *e, struct element *tag)
> render_opcode(out, "ASN1_OP_%sMATCH_ANY%s%s,",
> cond, act, skippable ? "_OR_SKIP" : "");
> if (e->name)
> - render_more(out, "\t\t// %*.*s",
> - (int)e->name->size, (int)e->name->size,
> - e->name->value);
> + render_more(out, "\t\t// %s", e->name->content);
> render_more(out, "\n");
> goto dont_render_tag;
>
> @@ -1503,9 +1500,7 @@ static void render_element(FILE *out, struct element *e, struct element *tag)
>
> x = tag ?: e;
> if (x->name)
> - render_more(out, "\t\t// %*.*s",
> - (int)x->name->size, (int)x->name->size,
> - x->name->value);
> + render_more(out, "\t\t// %s", x->name->content);
> render_more(out, "\n");
>
> /* Render the tag */
> @@ -1543,10 +1538,8 @@ dont_render_tag:
> * skipability */
> render_opcode(out, "_jump_target(%u),", e->entry_index);
> if (e->type_def && e->type_def->name)
> - render_more(out, "\t\t// --> %*.*s",
> - (int)e->type_def->name->size,
> - (int)e->type_def->name->size,
> - e->type_def->name->value);
> + render_more(out, "\t\t// --> %s",
> + e->type_def->name->content);
> render_more(out, "\n");
> if (!(e->flags & ELEMENT_RENDERED)) {
> e->flags |= ELEMENT_RENDERED;
> @@ -1571,10 +1564,8 @@ dont_render_tag:
> * skipability */
> render_opcode(out, "_jump_target(%u),", e->entry_index);
> if (e->type_def && e->type_def->name)
> - render_more(out, "\t\t// --> %*.*s",
> - (int)e->type_def->name->size,
> - (int)e->type_def->name->size,
> - e->type_def->name->value);
> + render_more(out, "\t\t// --> %s",
> + e->type_def->name->content);
> render_more(out, "\n");
> if (!(e->flags & ELEMENT_RENDERED)) {
> e->flags |= ELEMENT_RENDERED;
>
next prev parent reply other threads:[~2015-08-05 18:13 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-05 13:43 [PATCH 00/27] MODSIGN: Use PKCS#7 for module signatures [ver #7] David Howells
2015-08-05 13:43 ` [PATCH 01/27] ASN.1: Add an ASN.1 compiler option to dump the element tree " David Howells
2015-08-05 13:43 ` [PATCH 02/27] ASN.1: Copy string names to tokens in ASN.1 compiler " David Howells
2015-08-05 18:13 ` Mimi Zohar [this message]
2015-08-05 18:26 ` David Howells
2015-08-05 18:56 ` Mimi Zohar
2015-08-05 13:43 ` [PATCH 03/27] X.509: Extract both parts of the AuthorityKeyIdentifier " David Howells
2015-08-05 13:44 ` [PATCH 04/27] X.509: Support X.509 lookup by Issuer+Serial form " David Howells
2015-08-05 13:44 ` [PATCH 05/27] PKCS#7: Allow detached data to be supplied for signature checking purposes " David Howells
2015-08-05 13:44 ` [PATCH 06/27] MODSIGN: Provide a utility to append a PKCS#7 signature to a module " David Howells
2015-08-05 13:44 ` [PATCH 07/27] MODSIGN: Use PKCS#7 messages as module signatures " David Howells
2015-08-05 13:44 ` [PATCH 08/27] sign-file: Add option to only create signature file " David Howells
2015-08-05 13:44 ` [PATCH 09/27] system_keyring.c doesn't need to #include module-internal.h " David Howells
2015-08-05 13:45 ` [PATCH 10/27] MODSIGN: Extract the blob PKCS#7 signature verifier from module signing " David Howells
2015-08-05 13:45 ` [PATCH 11/27] modsign: Abort modules_install when signing fails " David Howells
2015-08-05 13:45 ` [PATCH 12/27] modsign: Allow password to be specified for signing key " David Howells
2015-08-05 13:45 ` [PATCH 13/27] modsign: Allow signing key to be PKCS#11 " David Howells
2015-08-05 13:45 ` [PATCH 14/27] modsign: Allow external signing key to be specified " David Howells
2015-08-05 13:45 ` [PATCH 15/27] modsign: Extract signing cert from CONFIG_MODULE_SIG_KEY if needed " David Howells
2015-08-05 13:46 ` [PATCH 16/27] modsign: Use single PEM file for autogenerated key " David Howells
2015-08-05 13:46 ` [PATCH 17/27] modsign: Add explicit CONFIG_SYSTEM_TRUSTED_KEYS option " David Howells
2015-08-05 13:46 ` [PATCH 18/27] PKCS#7: Check content type and versions " David Howells
2015-08-05 13:46 ` [PATCH 19/27] X.509: Change recorded SKID & AKID to not include Subject or Issuer " David Howells
2015-08-05 13:46 ` [PATCH 20/27] PKCS#7: Support CMS messages also [RFC5652] " David Howells
2015-08-05 13:47 ` [PATCH 21/27] sign-file: Generate CMS message as signature instead of PKCS#7 " David Howells
2015-08-05 13:47 ` [PATCH 22/27] extract-cert: Cope with multiple X.509 certificates in a single file " David Howells
2015-08-05 13:47 ` [PATCH 23/27] modsign: Use extract-cert to process CONFIG_SYSTEM_TRUSTED_KEYS " David Howells
2015-08-05 13:47 ` [PATCH 24/27] PKCS#7: Improve and export the X.509 ASN.1 time object decoder " David Howells
2015-08-05 13:47 ` [PATCH 25/27] PKCS#7: Appropriately require or forbid authenticated attributes " David Howells
2015-08-05 14:27 ` David Howells
2015-08-05 13:47 ` [PATCH 26/27] KEYS: Add a name for PKEY_ID_PKCS7 " David Howells
2015-08-05 13:48 ` [PATCH 27/27] PKCS#7: Restrict content type and authenticated attributes by purpose " David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438798384.2489.6.camel@linux.vnet.ibm.com \
--to=zohar@linux.vnet.ibm.com \
--cc=dhowells@redhat.com \
--cc=dwmw2@infradead.org \
--cc=keyrings@linux-nfs.org \
--cc=kyle@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mcgrof@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox