Bug 5713 - strings: use '-0' as option will meet infinite loop
Summary: strings: use '-0' as option will meet infinite loop
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-02 02:42 UTC by chuli
Modified: 2008-02-18 01:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
After applying this patch, when use "strings -0 file", "invalid number 0" will be reported. (232 bytes, patch)
2008-02-02 02:46 UTC, chuli
Details | Diff
Improve handlign of -<number> command line option (847 bytes, patch)
2008-02-14 12:20 UTC, Nick Clifton
Details | Diff
Used for "-n num" when num is hexadecimal or octal (729 bytes, patch)
2008-02-15 09:44 UTC, chuli
Details | Diff
Revised patch which removes integer_arg() (1.55 KB, patch)
2008-02-15 10:23 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description chuli 2008-02-02 02:42:05 UTC
When I use the command "strings" like this: "strings -0 file" will trap in 
infinite loop. 
	The binutils version is 2.17.50.0.6. Has this bug been fixed?
	If not, here is my patch.
	Thank you.

Chu Li

Signed-off-by: Chu Li <chul@cn.fujitsu.com>
----------------------------------------------
diff --git a/strings.c b/strings.c
index 4c68ea8..8ee2783 100644
--- a/strings.c
+++ b/strings.c
@@ -274,6 +274,9 @@ main (int argc, char **argv)
        }
     }

+  if(string_min == 0)
+    fatal (_("invalid number %d"), string_min);
+
   if (string_min < 0)
     string_min = 4;
Comment 1 chuli 2008-02-02 02:46:45 UTC
Created attachment 2227 [details]
After applying this patch, when use "strings -0 file", "invalid number 0" will be reported.
Comment 2 H.J. Lu 2008-02-08 20:59:05 UTC
Fixed by

http://sourceware.org/ml/binutils/2008-02/msg00067.html
Comment 3 chuli 2008-02-13 00:52:31 UTC
(In reply to comment #2)
> Fixed by
> http://sourceware.org/ml/binutils/2008-02/msg00067.html
 
I found using "strings -n 0 file" or "strings --bytes=0 file", "invalid number 
0" will be reported. So "strings -0 file" should report "invalid number 0" not 
just use "4" as min-length.
I think my patch may be more appropriate.

Regards

Comment 4 Nick Clifton 2008-02-14 12:20:41 UTC
Created attachment 2262 [details]
Improve handlign of -<number> command line option
Comment 5 Nick Clifton 2008-02-14 12:22:36 UTC
Hi Chu,

  I agree, strings should be consistent with the error messages that it generates.
There is also another problem, in that currently:

  strings -1 -2 <file>

will print all the strings of 12 bytes of more in <file> rather than, as might
reasonably be assumed, all strings of 2 bytes or more.

  I have uploaded a patch to address both these points.  Please try it out and
let me know what you think.

Cheers
  Nick
Comment 6 chuli 2008-02-15 09:41:51 UTC
Hi,

  I have tried it out. It' Ok now. And I found if the "num" is the hex number 
in "-n num" option , the result is a little strange and 0xA can't be 
recognized.
  So I made a patch for it. Hope it is useful.
Regards
Chuli
Comment 7 chuli 2008-02-15 09:44:17 UTC
Created attachment 2268 [details]
Used for "-n num" when num is hexadecimal or octal
Comment 8 Nick Clifton 2008-02-15 10:23:02 UTC
Created attachment 2269 [details]
Revised patch which removes integer_arg()
Comment 9 Nick Clifton 2008-02-15 10:25:12 UTC
Hi Chu,

  Thanks for pointing that out.  In fact the integer_arg() function is
completely redundant as the C library function strtoul() does everything that is
needed.  So I have applied a revised version of the patch which removes the
function entirely.

  I hope that this resolves the issue for you.

Cheers
  Nick

binutils/ChangeLog
2008-02-15  Chu Li  <chul@cn.fujitsu.com>
	    Nick Clifton  <nickc@redhat.com>

	PR binutils/5713
	* strings.c (integer_arg): Delete function.
	(string_min): Initialise to 4.
	(main): Use strtoul to parse integer arguments.
	Move check for an invalid string length to after all the arguments
	have been parsed.
	(usage): Use indentation to indicate that -<n> is a another form
	of the --bytes= command line option.
Comment 10 chuli 2008-02-18 01:14:32 UTC
Hi,

   I think it's OK now.