-
Notifications
You must be signed in to change notification settings - Fork 924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests/example segfaults on add user #228
Comments
|
Hm. Can't reproduce on RHEL5 or Mac OSX. It would be useful to see (1) a transcript of exactly what you entered (e.g. if it wasn't Oh, and if changing the buffer size from |
|
Quuxplusone,
I can post the complete output tomorrow. I suspect that is something
simple. But I thought that it would be good to know that it doesn't behave
'right out of the box' on a major platform.
And no, it isn't specific to 'Gertrude'. The first few times I tried 'Joe'
'bob' and 'Dave'. I thought that might be too short, therefore 'Gertrude'
Dave
…On Tue, Mar 9, 2021 at 8:31 PM Quuxplusone ***@***.***> wrote:
Hm. Can't reproduce on RHEL5 or Mac OSX. It would be useful to see (1) a
transcript of exactly what you entered (e.g. if it wasn't Gertrude but
maybe Gertrude-followed-by-several-space-characters?), and/or (2) a stack
trace. Obviously example.c isn't "safe," in the sense that it does a gets
into a 10-byte buffer, so if you overflow the buffer all bets are off.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#228 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACSMISAFNLXFW2RLAEBBSDTC3DWDANCNFSM4Y4Z2EAA>
.
|
|
Quuxplusone,
OK, this is all really about the use of gets() in example.c. Nothing about
uthash itself.
I had forgotten gets() even exists. Just as well:
https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used
Dave
On Tue, Mar 9, 2021 at 10:08 PM David Witten ***@***.***> wrote:
Quuxplusone,
I can post the complete output tomorrow. I suspect that is something
simple. But I thought that it would be good to know that it doesn't behave
'right out of the box' on a major platform.
And no, it isn't specific to 'Gertrude'. The first few times I tried
'Joe' 'bob' and 'Dave'. I thought that might be too short, therefore
'Gertrude'
Dave
On Tue, Mar 9, 2021 at 8:31 PM Quuxplusone ***@***.***>
wrote:
> Hm. Can't reproduce on RHEL5 or Mac OSX. It would be useful to see (1) a
> transcript of exactly what you entered (e.g. if it wasn't Gertrude but
> maybe Gertrude-followed-by-several-space-characters?), and/or (2) a
> stack trace. Obviously example.c isn't "safe," in the sense that it does
> a gets into a 10-byte buffer, so if you overflow the buffer all bets are
> off.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#228 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AACSMISAFNLXFW2RLAEBBSDTC3DWDANCNFSM4Y4Z2EAA>
> .
>
$ make example
cc -I../src -g -Wall -o example example.c
example.c: In function ‘main’:
example.c:98:9: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
gets(in);
^~~~
fgets
example.c:102:32: warning: passing argument 2 of ‘add_user’ makes pointer from integer without a cast [-Wint-conversion]
add_user(id++, gets(in));
^~~~
example.c:14:6: note: expected ‘char *’ but argument is of type ‘int’
void add_user(int user_id, char *name)
^~~~~~~~
example.c:109:30: warning: passing argument 2 of ‘add_user’ makes pointer from integer without a cast [-Wint-conversion]
add_user(id, gets(in));
^~~~
example.c:14:6: note: expected ‘char *’ but argument is of type ‘int’
void add_user(int user_id, char *name)
^~~~~~~~
example.c:113:36: warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast [-Wint-conversion]
s = find_user(atoi(gets(in)));
^~~~
In file included from example.c:2:0:
/usr/include/stdlib.h:104:12: note: expected ‘const char *’ but argument is of type ‘int’
extern int atoi (const char *__nptr)
^~~~
example.c:118:36: warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast [-Wint-conversion]
s = find_user(atoi(gets(in)));
^~~~
In file included from example.c:2:0:
/usr/include/stdlib.h:104:12: note: expected ‘const char *’ but argument is of type ‘int’
extern int atoi (const char *__nptr)
^~~~
/tmp/cc6zxO7k.o: In function `main':
/mnt/2de4d611-1c1b-4c79-9d67-9d8283763f42/Projects/git/uthash/tests/example.c:98: warning: the `gets' function is dangerous and should not be used.
|
|
Hi @Quuxplusone are you interested in a pull request for this? gets() is not recommended, so it could be useful to fix this. I am using uthash since a few weeks and find it very useful, so I would be willing to propose something according to your criteria. |
|
@pdebuyl: Sure, if you want to make a PR, I'll look at it. No promises, though. I wouldn't like to complicate the example code too much; I agree it's really bad that it currently relies on It might even be better to throw out the example code and write a completely different example program without |
|
Fixed by a109c6b ! |
On Ubuntu 18.04 example segfaults on option 1 or 2
$ git clone
$ cd uthash/tests
$ make
all tests pass
$ make clean
$ make example
cc -I../src -g -Wall -o example example.c
(warnings concerning gets, add_user, atoi...)
1
name?
Gertrude
Segmentation fault (core dumped)
Option 2 behaves similarly.
The text was updated successfully, but these errors were encountered: