mirror of
https://github.com/Orc/discount.git
synced 2026-09-25 04:10:00 +03:00
change amalloc so it fills malloc()ed memory with a nun-null pattern, which found a WHOLE BUNCH of places where I was not null-terminating strings but instead was taking advantage of amalloc always zeroing new allocations.
This commit is contained in:
@@ -63,7 +63,13 @@ acalloc(int count, int size)
|
|||||||
void*
|
void*
|
||||||
amalloc(int size)
|
amalloc(int size)
|
||||||
{
|
{
|
||||||
return acalloc(size,1);
|
void *ret = acalloc(1, size);
|
||||||
|
|
||||||
|
if ( ret ) {
|
||||||
|
/* explicitally fill the mallocated memory with a nonzero character */
|
||||||
|
memset(ret, 0x8f, size);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ mkd_css(Document *d, char **res)
|
|||||||
/* null-terminate, then strdup() into a free()able memory
|
/* null-terminate, then strdup() into a free()able memory
|
||||||
* chunk
|
* chunk
|
||||||
*/
|
*/
|
||||||
EXPAND(f) = 0;
|
COMPLETE(f);
|
||||||
*res = strdup(T(f));
|
*res = strdup(T(f));
|
||||||
}
|
}
|
||||||
DELETE(f);
|
DELETE(f);
|
||||||
|
|||||||
@@ -69,6 +69,8 @@
|
|||||||
|
|
||||||
typedef STRING(char) Cstring;
|
typedef STRING(char) Cstring;
|
||||||
|
|
||||||
|
#define COMPLETE(t) (EXPAND(t) = 0),(S(t)--)
|
||||||
|
|
||||||
extern void Csputc(int, Cstring *);
|
extern void Csputc(int, Cstring *);
|
||||||
extern int Csprintf(Cstring *, char *, ...);
|
extern int Csprintf(Cstring *, char *, ...);
|
||||||
extern int Cswrite(Cstring *, char *, int);
|
extern int Cswrite(Cstring *, char *, int);
|
||||||
|
|||||||
+4
-3
@@ -408,6 +408,7 @@ linkysize(MMIOT *f, Footnote *ref)
|
|||||||
EXPAND(width) = c;
|
EXPAND(width) = c;
|
||||||
c = pull(f);
|
c = pull(f);
|
||||||
}
|
}
|
||||||
|
COMPLETE(width);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pull(f);
|
pull(f);
|
||||||
@@ -424,6 +425,7 @@ linkysize(MMIOT *f, Footnote *ref)
|
|||||||
EXPAND(height) = c;
|
EXPAND(height) = c;
|
||||||
c = pull(f);
|
c = pull(f);
|
||||||
}
|
}
|
||||||
|
COMPLETE(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isspace(c) )
|
if ( isspace(c) )
|
||||||
@@ -502,7 +504,7 @@ linky_extended_attributes(MMIOT *f, struct footnote *p, int start)
|
|||||||
|
|
||||||
while ( (c = pull(f)) != '}' )
|
while ( (c = pull(f)) != '}' )
|
||||||
EXPAND(p->extended_attr) = c;
|
EXPAND(p->extended_attr) = c;
|
||||||
EXPAND(p->extended_attr) = 0;
|
COMPLETE(p->extended_attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2151,8 +2153,7 @@ mkd_document(Document *p, char **res)
|
|||||||
/* Add a null byte at the end of the generated html,
|
/* Add a null byte at the end of the generated html,
|
||||||
* but pretend it doesn't exist.
|
* but pretend it doesn't exist.
|
||||||
*/
|
*/
|
||||||
EXPAND(p->ctx->out) = 0;
|
COMPLETE(p->ctx->out);
|
||||||
--S(p->ctx->out);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-10
@@ -169,8 +169,7 @@ splitline(Line *t, int cutpoint)
|
|||||||
t->next = tmp;
|
t->next = tmp;
|
||||||
|
|
||||||
SUFFIX(tmp->text, T(t->text)+cutpoint, S(t->text)-cutpoint);
|
SUFFIX(tmp->text, T(t->text)+cutpoint, S(t->text)-cutpoint);
|
||||||
EXPAND(tmp->text) = 0;
|
COMPLETE(tmp->text);
|
||||||
S(tmp->text)--;
|
|
||||||
|
|
||||||
S(t->text) = cutpoint;
|
S(t->text) = cutpoint;
|
||||||
}
|
}
|
||||||
@@ -1091,7 +1090,7 @@ footnote_height_and_width(char *s, struct footnote *foot)
|
|||||||
/* specialcase for % width */
|
/* specialcase for % width */
|
||||||
if ( s[i] == '%' )
|
if ( s[i] == '%' )
|
||||||
EXPAND(foot->width) = '%';
|
EXPAND(foot->width) = '%';
|
||||||
EXPAND(foot->width) = 0;
|
COMPLETE(foot->width);
|
||||||
}
|
}
|
||||||
if ( s[i] == 'x' ) {
|
if ( s[i] == 'x' ) {
|
||||||
i++;
|
i++;
|
||||||
@@ -1099,7 +1098,7 @@ footnote_height_and_width(char *s, struct footnote *foot)
|
|||||||
EXPAND(foot->height) = s[i++];
|
EXPAND(foot->height) = s[i++];
|
||||||
if ( s[i] == '%' )
|
if ( s[i] == '%' )
|
||||||
EXPAND(foot->height) = '%';
|
EXPAND(foot->height) = '%';
|
||||||
EXPAND(foot->height) = 0;
|
COMPLETE(foot->height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1129,8 +1128,7 @@ addfootnote(Line *p, MMIOT* f)
|
|||||||
/* keep the footnote label */
|
/* keep the footnote label */
|
||||||
for (j=i=p->dle+1; T(p->text)[j] != ']'; j++)
|
for (j=i=p->dle+1; T(p->text)[j] != ']'; j++)
|
||||||
EXPAND(foot->tag) = T(p->text)[j];
|
EXPAND(foot->tag) = T(p->text)[j];
|
||||||
EXPAND(foot->tag) = 0;
|
COMPLETE(foot->tag);
|
||||||
S(foot->tag)--;
|
|
||||||
|
|
||||||
/* consume the closing ]: */
|
/* consume the closing ]: */
|
||||||
j = nextnonblank(p, j+2);
|
j = nextnonblank(p, j+2);
|
||||||
@@ -1154,8 +1152,7 @@ addfootnote(Line *p, MMIOT* f)
|
|||||||
|
|
||||||
while ( (j < S(p->text)) && !isspace(T(p->text)[j]) )
|
while ( (j < S(p->text)) && !isspace(T(p->text)[j]) )
|
||||||
EXPAND(foot->link) = T(p->text)[j++];
|
EXPAND(foot->link) = T(p->text)[j++];
|
||||||
EXPAND(foot->link) = 0;
|
COMPLETE(foot->link);
|
||||||
S(foot->link)--;
|
|
||||||
j = nextnonblank(p,j);
|
j = nextnonblank(p,j);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -1172,6 +1169,7 @@ addfootnote(Line *p, MMIOT* f)
|
|||||||
if ( T(p->text)[i] == '}' ) {
|
if ( T(p->text)[i] == '}' ) {
|
||||||
for ( j++; j < i; j++ )
|
for ( j++; j < i; j++ )
|
||||||
EXPAND(foot->extended_attr) = T(p->text)[j];
|
EXPAND(foot->extended_attr) = T(p->text)[j];
|
||||||
|
COMPLETE(foot->extended_attr);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1198,8 +1196,7 @@ addfootnote(Line *p, MMIOT* f)
|
|||||||
--S(foot->title);
|
--S(foot->title);
|
||||||
if ( S(foot->title) ) /* skip trailing quote */
|
if ( S(foot->title) ) /* skip trailing quote */
|
||||||
--S(foot->title);
|
--S(foot->title);
|
||||||
EXPAND(foot->title) = 0;
|
COMPLETE(foot->title);
|
||||||
--S(foot->title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
___mkd_freeLine(p);
|
___mkd_freeLine(p);
|
||||||
|
|||||||
@@ -69,8 +69,7 @@ __mkd_enqueue(Document* a, Cstring *line)
|
|||||||
++xp;
|
++xp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EXPAND(p->text) = 0;
|
COMPLETE(p->text);
|
||||||
S(p->text)--;
|
|
||||||
p->dle = mkd_firstnonblank(p);
|
p->dle = mkd_firstnonblank(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +336,7 @@ mkd_line(char *bfr, int size, char **res, mkd_flag_t* flags)
|
|||||||
mkd_parse_line(bfr, size, &f, flags);
|
mkd_parse_line(bfr, size, &f, flags);
|
||||||
|
|
||||||
if ( len = S(f.out) ) {
|
if ( len = S(f.out) ) {
|
||||||
EXPAND(f.out) = 0;
|
COMPLETE(f.out);
|
||||||
/* strdup() doesn't use amalloc(), so in an amalloc()ed
|
/* strdup() doesn't use amalloc(), so in an amalloc()ed
|
||||||
* build this copies the string safely out of our memory
|
* build this copies the string safely out of our memory
|
||||||
* paranoia arena. In a non-amalloc world, it's a spurious
|
* paranoia arena. In a non-amalloc world, it's a spurious
|
||||||
|
|||||||
@@ -294,8 +294,7 @@ finclude(MMIOT *doc, FILE *out, mkd_flag_t *flags, int whence)
|
|||||||
EXPAND(include) = c;
|
EXPAND(include) = c;
|
||||||
|
|
||||||
if ( c != EOF ) {
|
if ( c != EOF ) {
|
||||||
EXPAND(include) = 0;
|
COMPLETE(include);
|
||||||
S(include)--;
|
|
||||||
|
|
||||||
if (( f = fopen(T(include), "r") )) {
|
if (( f = fopen(T(include), "r") )) {
|
||||||
while ( (c = getc(f)) != EOF )
|
while ( (c = getc(f)) != EOF )
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ mkd_toc(Document *p, char **doc)
|
|||||||
if ( (size = S(res)) > 0 ) {
|
if ( (size = S(res)) > 0 ) {
|
||||||
/* null-terminate & strdup into a free()able memory chunk
|
/* null-terminate & strdup into a free()able memory chunk
|
||||||
*/
|
*/
|
||||||
EXPAND(res) = 0;
|
COMPLETE(res);
|
||||||
*doc = strdup(T(res));
|
*doc = strdup(T(res));
|
||||||
}
|
}
|
||||||
DELETE(res);
|
DELETE(res);
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ mkd_xml(char *p, int size, char **res)
|
|||||||
/* null terminate, strdup() into a free()able memory block,
|
/* null terminate, strdup() into a free()able memory block,
|
||||||
* and return the size of everything except the null terminator
|
* and return the size of everything except the null terminator
|
||||||
*/
|
*/
|
||||||
EXPAND(f) = 0;
|
COMPLETE(f);
|
||||||
*res = strdup(T(f));
|
*res = strdup(T(f));
|
||||||
size = S(f)-1;
|
size = S(f);
|
||||||
DELETE(f);
|
DELETE(f);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user