public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
@ 2014-07-03 21:45 sergey.churayev.76 at gmail dot com
2014-07-03 21:49 ` [Bug libc/17111] " sergey.churayev.76 at gmail dot com
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: sergey.churayev.76 at gmail dot com @ 2014-07-03 21:45 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Bug ID: 17111
Summary: STRTOL(3) unexpected behavior when use '`' before
number (i.e."```1") as argument of main ()
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
Assignee: unassigned at sourceware dot org
Reporter: sergey.churayev.76 at gmail dot com
CC: drepper.fsp at gmail dot com
Hi,
This is Linux Programmer's Manual STRTOL(3) here:
http://man7.org/linux/man-pages/man3/strtol.3.html
--------------------------------------------------------------------
Program source
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <errno.h>
int
main(int argc, char *argv[])
{
int base;
char *endptr, *str;
long val;
if (argc < 2) {
fprintf(stderr, "Usage: %s str [base]\n", argv[0]);
exit(EXIT_FAILURE);
}
str = argv[1];
base = (argc > 2) ? atoi(argv[2]) : 10;
errno = 0; /* To distinguish success/failure after call */
val = strtol(str, &endptr, base);
/* Check for various possible errors */
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
|| (errno != 0 && val == 0)) {
perror("strtol");
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No digits were found\n");
exit(EXIT_FAILURE);
}
/* If we got here, strtol() successfully parsed a number */
printf("strtol() returned %ld\n", val);
if (*endptr != '\0') /* Not necessarily an error... */
printf("Further characters after number: %s\n", endptr);
exit(EXIT_SUCCESS);
}
--------------------------------------------------------------------
I use name "strtol_test" to run and use "`````1" as argument of main.
I see next problem:
%% strtol_test ````1
Segmentation fault
Segmentation fault
No digits were found
%%
Any ideas?
Best regards,
Serg.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
@ 2014-07-03 21:49 ` sergey.churayev.76 at gmail dot com
2014-07-03 22:32 ` schwab@linux-m68k.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: sergey.churayev.76 at gmail dot com @ 2014-07-03 21:49 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
--- Comment #1 from Sergey Churayev <sergey.churayev.76 at gmail dot com> ---
Also:
-------------------------------------------------------------------
%% strtol_test ``````````
Usage: strtol_test str [base]
%% strtol_test ``````````1111
Segmentation fault
Segmentation fault
Segmentation fault
Segmentation fault
Segmentation fault
No digits were found
%% strtol_test `
Unmatched `.
-------------------------------------------------------------------
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
2014-07-03 21:49 ` [Bug libc/17111] " sergey.churayev.76 at gmail dot com
@ 2014-07-03 22:32 ` schwab@linux-m68k.org
2014-07-04 2:17 ` sergey.churayev.76 at gmail dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2014-07-03 22:32 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> ---
` is a shell meta character.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
2014-07-03 21:49 ` [Bug libc/17111] " sergey.churayev.76 at gmail dot com
2014-07-03 22:32 ` schwab@linux-m68k.org
@ 2014-07-04 2:17 ` sergey.churayev.76 at gmail dot com
2014-07-04 2:18 ` sergey.churayev.76 at gmail dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: sergey.churayev.76 at gmail dot com @ 2014-07-04 2:17 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
--- Comment #3 from Sergey Churayev <sergey.churayev.76 at gmail dot com> ---
Yes, I know, but what happens if shell will send wrong data to this lib
function.
The program will:
1. Crash (BAD)
2. Or send to the top some silly value (MUCH WORSE).
Then it is really difficult find the place where when and why it happens. So,
will be better check arguments inside of function to prevent bad situations.
Anyway the function should not crash program or return to the top some nothing
meaningful value when accepting wrong arguments.
It is just string to integer conversion. The function must inform me about
problem. Same design conception must dominate with similar functions in C
standard libraries.
(In reply to Andreas Schwab from comment #2)
> ` is a shell meta character.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
` (2 preceding siblings ...)
2014-07-04 2:17 ` sergey.churayev.76 at gmail dot com
@ 2014-07-04 2:18 ` sergey.churayev.76 at gmail dot com
2014-07-04 7:04 ` schwab@linux-m68k.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: sergey.churayev.76 at gmail dot com @ 2014-07-04 2:18 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Sergey Churayev <sergey.churayev.76 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |---
--- Comment #4 from Sergey Churayev <sergey.churayev.76 at gmail dot com> ---
Yes, I know, but what happens if shell will send wrong data to this lib
function.
The program will:
1. Crash (BAD)
2. Or send to the top some silly value (MUCH WORSE).
Then it is really difficult find the place where when and why it happens. So,
will be better check arguments inside of function to prevent bad situations.
Anyway the function should not crash program or return to the top some nothing
meaningful value when accepting wrong arguments.
It is just string to integer conversion. The function must inform me about
problem. Same design conception must dominate with similar functions in C
standard libraries.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
` (3 preceding siblings ...)
2014-07-04 2:18 ` sergey.churayev.76 at gmail dot com
@ 2014-07-04 7:04 ` schwab@linux-m68k.org
2014-07-05 2:27 ` sergey.churayev.76 at gmail dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2014-07-04 7:04 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution|--- |INVALID
--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> ---
This has nothing to do with glibc, you should file a bug with your shell.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
` (4 preceding siblings ...)
2014-07-04 7:04 ` schwab@linux-m68k.org
@ 2014-07-05 2:27 ` sergey.churayev.76 at gmail dot com
2014-07-05 7:03 ` schwab@linux-m68k.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: sergey.churayev.76 at gmail dot com @ 2014-07-05 2:27 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Sergey Churayev <sergey.churayev.76 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |---
--- Comment #6 from Sergey Churayev <sergey.churayev.76 at gmail dot com> ---
Ok,
The problem relates to transfer arguments in main (), not to strtol function.
But, how about this:
I have in my program this line
str = "0x0808"; And then try to convert it to long int.
Why I got this message?
strtol() returned 0
Further characters after number: x0808
According specification:
...
If base is zero or 16, the string may then include a "0x" prefix, and the
number will be read in base 16; otherwise, a zero base is taken as 10 (decimal)
unless the next character is '0', in which case it is taken as 8 (octal).
...
Best regards,
Serg.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
` (5 preceding siblings ...)
2014-07-05 2:27 ` sergey.churayev.76 at gmail dot com
@ 2014-07-05 7:03 ` schwab@linux-m68k.org
2014-07-05 7:57 ` sergey.churayev.76 at gmail dot com
2014-07-05 9:13 ` schwab@linux-m68k.org
8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2014-07-05 7:03 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution|--- |INVALID
--- Comment #7 from Andreas Schwab <schwab@linux-m68k.org> ---
You are using base = 10.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
` (6 preceding siblings ...)
2014-07-05 7:03 ` schwab@linux-m68k.org
@ 2014-07-05 7:57 ` sergey.churayev.76 at gmail dot com
2014-07-05 9:13 ` schwab@linux-m68k.org
8 siblings, 0 replies; 10+ messages in thread
From: sergey.churayev.76 at gmail dot com @ 2014-07-05 7:57 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Sergey Churayev <sergey.churayev.76 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |---
--- Comment #8 from Sergey Churayev <sergey.churayev.76 at gmail dot com> ---
How to use base = 16?
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libc/17111] STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main ()
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
` (7 preceding siblings ...)
2014-07-05 7:57 ` sergey.churayev.76 at gmail dot com
@ 2014-07-05 9:13 ` schwab@linux-m68k.org
8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2014-07-05 9:13 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=17111
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution|--- |INVALID
--- Comment #9 from Andreas Schwab <schwab@linux-m68k.org> ---
Bugzilla is not the place to ask beginner's questions.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-07-05 9:13 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-03 21:45 [Bug libc/17111] New: STRTOL(3) unexpected behavior when use '`' before number (i.e."```1") as argument of main () sergey.churayev.76 at gmail dot com
2014-07-03 21:49 ` [Bug libc/17111] " sergey.churayev.76 at gmail dot com
2014-07-03 22:32 ` schwab@linux-m68k.org
2014-07-04 2:17 ` sergey.churayev.76 at gmail dot com
2014-07-04 2:18 ` sergey.churayev.76 at gmail dot com
2014-07-04 7:04 ` schwab@linux-m68k.org
2014-07-05 2:27 ` sergey.churayev.76 at gmail dot com
2014-07-05 7:03 ` schwab@linux-m68k.org
2014-07-05 7:57 ` sergey.churayev.76 at gmail dot com
2014-07-05 9:13 ` schwab@linux-m68k.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).