Comments (7)
Thanks a lot for the error report. I'll check it out as soon as I get time.
from mpc.
Just dropping by to say that using gcc 4.9 on OS X 10.10, I can not reproduce the bug.
from mpc.
Hey,
Can you verify if this is fixed in 9481c65?
Definitely one of the more perculiar bugs I've come across.
I managed to reproduce something similar in Ubuntu using gcc
. It seems that the call to calloc
in mpcf_escape_new
was getting optimised away into something odd and making accessing the pointer cause some kind of address violation.
First I tried switching calloc
to malloc
and zeroing the memory manually. This appeared to fix the issue on my side. I then tried just switching the variable declaration order so that calloc
was called last - which also appeared to fix the issue.
It seems very weird that switching the variable declaration order would fix this problem (it shouldn't matter), so it may be an obscure bug in the compiler - because I couldn't spot anything obviously wrong with my code.
Thanks,
Dan
from mpc.
Hi Dan,
I'm afraid it doesn't seem to be fixed. However, I can't reproduce the bug with gcc, and valgrind doesn't find anything (regardless of whether I use gcc or clang) so it's quite possible this is a false positive on the part of clang's address sanitizer.
That said, I did a bit of primitive printf tracing and have found that the problem (if indeed it is a problem) occurs in a call to vsprintf
in mpc_err_string_cat
, to be specific:
void mpc_err_string_cat(char *buffer, int *pos, int *max, char const *fmt, ...) {
/* TODO: Error Checking on Length */
int left = ((*max) - (*pos));
va_list va;
va_start(va, fmt);
if (left < 0) { left = 0;}
(*pos) += vsprintf(buffer + (*pos), fmt, va); // Clang detects problem here
va_end(va);
}
At this point in the program, the argument fmt
has been produced by mpc_err_char_unescape
. Adding a null-terminator to this string prevents the address sanitizer from complaining:
static char char_unescape_buffer[4]; // Used to be [3]
static const char *mpc_err_char_unescape(char c) {
char_unescape_buffer[0] = '\'';
char_unescape_buffer[1] = ' ';
char_unescape_buffer[2] = '\'';
char_unescape_buffer[3] = '\0'; // Line added
switch (c) {
case '\a': return "bell";
case '\b': return "backspace";
case '\f': return "formfeed";
case '\r': return "carriage return";
case '\v': return "vertical tab";
case '\0': return "end of input";
case '\n': return "newline";
case '\t': return "tab";
case ' ' : return "space";
default:
char_unescape_buffer[1] = c;
return char_unescape_buffer;
}
}
I'm sorry that I have no idea whether this change breaks any other functionality in the library!
Cheers,
Simon
from mpc.
Oh that looks like a very real bug in the mpc_err_char_unescape
function! Nice catch.
I'll make the update and merge it in. My suspicion is that gcc
has some different vsprintf
implementation that doesn't rely on a null terminated format string but that maybe was screwing with some memory elsewhere due to no null terminator and causing the weird calloc
bug. I'll test it and see.
from mpc.
Please verify if this is fixed in d6347af and thanks again.
from mpc.
I can confirm that this is fixed in d6347af. Thanks, this discussion has been educational for me!
from mpc.
Related Issues (20)
- Implementation of `mpcf_all_free` not seen in mpc.c HOT 1
- In theory: Can MPC parse C? HOT 2
- scan coverity findings HOT 1
- Add support for arm64 architecture. HOT 4
- CMakeLists.txt suggestion HOT 6
- Release: GNU Guix
- Segmentation fault and timeout occur at mpca_lang_st() HOT 1
- Does the order of definitions matter in languages? HOT 2
- Mix parsers and AST HOT 3
- Greedy matching causes token matching issue HOT 2
- What about MPC now? HOT 1
- "-static" does not work on newer MacOS due to crt0
- make install does not work on newer MacOS (install command/folders)
- dependency errors issue HOT 9
- shared state and multi-threaded use HOT 2
- parser for """long string""" ? HOT 2
- Make include guards unique
- Completion of error handling
- memory leak in mpca_lang function
- Unicode and regexs etc HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mpc.