可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am having problem compiling the followed exploit code:
http://downloads.securityfocus.com/vulnerabilities/exploits/59846-1.c
I am using: "gcc file.c" and "gcc -O2 file.c" but both of them gets the following errors:
sorbolinux-exec.c: In function ‘sc’:
sorbolinux-exec.c:76: error: stray ‘\302’ in program
sorbolinux-exec.c:76: error: stray ‘\244’ in program
sorbolinux-exec.c:76: error: ‘t’ undeclared (first use in this function)
sorbolinux-exec.c:76: error: (Each undeclared identifier is reported only once
sorbolinux-exec.c:76: error: for each function it appears in.)
I tried compiling them on both Kali linux and Ubuntu 10.04 and get the same result.
回答1:
You have an invalid character on that line. This is what I saw:
回答2:
You have invalid chars in your source. If you don't have any valid non ascii chars in your source, maybe in a double quoted string literal, you can simply convert your file back to ascii with:
tr -cd '\11\12\15\40-\176' < old.c > new.c
Edit: method with iconv will stop at wrong chars which makes no sense. The above command line is working with the example file. Good luck :-)
回答3:
I got the same with a character that visibly appeared as an asterisk, but was a UTF-8 sequence instead.
Encoder * st;
When compiled returned:
g.c:2:1: error: stray ‘\342’ in program
g.c:2:1: error: stray ‘\210’ in program
g.c:2:1: error: stray ‘\227’ in program
342 210 227 turns out to be UTF-8 for ASTERISK OPERATOR.
Deleting the '*' and typing it again fixed the problem.
回答4:
Whenever compiler found special character .. it gives these king of compile error .... what error i found is as following
error: stray '\302' in program and error: stray '\240' in program
....
Some piece of code i copied from chatting messanger. In messanger it was special character only.. after copiying into vim editor it changed to correct character only. But compiler was giving above error .. then .. that stamenet i wrote mannualy after .. it got resolve.. :)
回答5:
It's perhaps because you copied code from net ( from a site which has perhaps not an ASCII encoded page, but UTF-8 encoded page), so you can convert the code to ASCII from this site :
"http://www.percederberg.net/tools/text_converter.html"
There you can either detect errors manually by converting it back to UTF-8, or you can automatically convert it to ASCII and remove all the stray characters.
回答6:
Codo was exactly right on Oct. 5 that ¤t[i] is the intended text (with the currency symbol inadvertently introduced when the source was put into HTML (see original):
http://downloads.securityfocus.com/vulnerabilities/exploits/59846-1.c
Codo's change makes this exploit code compile without error. I did that and was able to use the exploit on Ubuntu 12.04 to escalate to root privilege.
回答7:
The explanations given here are correct. I just wanted to add that this problem might be because you copied the code from somewhere, from a website or a pdf file due to which there are some invalid characters in the code.
Try to find those invalid characters, or just retype the code if you can't. It will definitely compile then.
Source: stray error reason
回答8:
With me this error ocurred when I copied and pasted a code in text format to my editor (gedit).
The code was in a text document (.odt) and I copied it and pasted it into gedit.
If you did the same, you have manually rewrite the code.
回答9:
I noticed an issue in using the above tr command. The tr command COMPLETELY removes the "smart quotes". It would be better to replace the "smart quotes" with something like this.
This will give you a quick preview of what will be replaced.
sed s/[”“]/'"'/g File.txt
This will do the replacements and put the replacement in a new file called WithoutSmartQuotes.txt.
sed s/[”“]/'"'/g File.txt > WithoutSmartQuotes.txt
This will overwrite the original file.
sed -i ".bk" s/[”“]/'"'/g File.txt
http://developmentality.wordpress.com/2010/10/11/how-to-remove-smart-quotes-from-a-text-file/
回答10:
This problem comes when you have copied some text from html or you have done modification in windows environment and trying to compile in Unix/Solaris environment.
Please do "dos2unix" to remove the special characters from the file:
dos2unix fileName.ext fileName.ext
回答11:
Change the name of the file.c to some other file423.c. it may be because of the name conflict between c files.