All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit fdf5cd29 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

allocating space for char* in identifier rule, to fix use after free bug

parent b1e7c7fd
......@@ -30,7 +30,7 @@ void HeaderVisitor::visit(Rpc* r)
printf("%d\n", rt->num());
rt->accept(this); // this seems unnecessary in this case
const char* name = r->name();
fprintf(this->out_f_, " %s ", name);
fprintf(this->out_f_, " %s(", name);
for(std::vector<Parameter*>::iterator it = r->parameters()->begin(); it != r->parameters()->end(); it++)
{
......@@ -46,7 +46,7 @@ void HeaderVisitor::visit(Parameter* p)
{
p->type()->accept(this);
// print p->name_
fprintf(this->out_f_, "%s", p->name());
fprintf(this->out_f_, " %s", p->name());
}
void HeaderVisitor::visit(ProjectionType* p)
......
start-symbol: File
options: debug9
include: {{ #include "../include/lcd_ast.h"
include: {{ #include "lcd_ast.h"
#include <vector>
#include <stdlib.h>
#include <string>
......@@ -38,7 +38,7 @@ code: {{
return val;
}
void insertType(char * sym, Type * val) // should this be void?
void insertType(const char * sym, Type * val) // should this be void?
{
FileScope *fs = current_file_scope();
int ret = fs->insert_symbol(sym, val);
......@@ -62,7 +62,9 @@ Identifier = i1:IdentStart i2:IdentCont* {{
total << letter;
}
std::string str = total.str();
value = &str[0]; }}
printf("identifier is: %s\n", str.c_str());
value.value = malloc(str.length()+1);
strncpy((char*)value.value, str.c_str(), str.length()+1); }}
IdentStart = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
......@@ -135,7 +137,7 @@ String = <ascii 34> l:any_letter+ <ascii 34> {{
total << letter;
}
std::string str = total.str();
value = &str[0]; }}
value = str.c_str(); }}
any_letter = [_.,/?<>'; =:%`!@#$^&*()-+{}|\\ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]
......@@ -145,19 +147,21 @@ Include = "#include" Space+ "<" Spacing f:Identifier Spacing ">" Spacing {{
std::ostringstream total;
total << "#include <" << (char *) f.getValue() << ">";
std::string str = total.str();
value = &str[0]; }}
value = str.c_str(); }}
| "#include" Space+ s:String Spacing {{
std::ostringstream total;
total << "#include " << (char *) s.getValue();
std::string str = total.str();
value = &str[0]; }}
value = str.c_str(); }}
FirstParam = t:Type_form id:Identifier Spacing COMMA Spacing {{
printf("first param: id is %s\n", (char*) id.getValue());
value = new Parameter((Type *) t.getValue(), (char *) id.getValue()); }}
LastParam = t:Type_form id:Identifier Spacing {{
printf("last param: id is %s\n", (char*) id.getValue());
value = new Parameter((Type *) t.getValue(), (char *) id.getValue()); }}
Parameters = f:FirstParam* l:LastParam {{
......@@ -171,8 +175,9 @@ Parameters = f:FirstParam* l:LastParam {{
params->push_back((Parameter* ) l.getValue());
value = params; }}
Rpc = "rpc" Space+ t:Type_form id:Identifier Spacing OPEN p:Parameters CLOSE SEMI Spacing {{
value = new Rpc((Type *) t.getValue(), (char *) id.getValue(), (std::vector<Parameter *> *) p.getValue()); }}
Rpc = "rpc" Space+ t:Type_form id1:Identifier Spacing OPEN p:Parameters CLOSE SEMI Spacing {{
printf("rpc value of id is: %s\n", (char *) id1.getValue());
value = new Rpc((Type *) t.getValue(), (char *) id1.getValue(), (std::vector<Parameter *> *) p.getValue()); }}
......
rpc int foo(int a, int c, int b);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment