Меню Закрыть

Error stray 320 in program

Содержание

I am having problem compiling the followed exploit code:

I am using: "gcc file.c" and "gcc -O2 file.c" but both of them gets the following errors:

I tried compiling them on both Kali linux and Ubuntu 10.04 and get the same result.

migrated from security.stackexchange.com Oct 5 ’13 at 13:26

This question came from our site for information security professionals.

13 Answers 13

You have an invalid character on that line. This is what I saw:

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:

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 🙂

I got the same with a character that visibly appeared as an asterisk, but was a UTF-8 sequence instead.

When compiled returned:

342 210 227 turns out to be UTF-8 for ASTERISK OPERATOR.

Deleting the ‘*’ and typing it again fixed the problem.

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.. 🙂

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 :

Читайте также:  Регулятор напряжения для тэна своими руками

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.

Codo was exactly right on Oct. 5 that &current[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.

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.

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.

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.

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

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

Sure, convert the file to ascii and blast all unicode characters away. It will probably work. BUT.

  1. You won’t know what you fixed.
  2. It will also destroy any unicode comments. Ex: //: A²+B²=C²
  3. It could potentially damage obvious logic, the code will still be broken, but the solution less obvious. For example: A string with "Smart-Quotes" (“ & ”) or a pointer with a full-width astrix ( * ). Now “SOME_THING” looks like a #define ( SOME_THING ) and *SomeType is the wrong type ( SomeType ).

Two more sugrical approaches to fixing the problem:

    Switch fonts to see the character. (It might be invisible in your current font)

Regex search all unicode characters not part non-extended ascii. In notepad++ I can search up to FFFF, which hasn’t failed me yet.

80 is hex for 128, the first extended ascii character.

After hitting "find next" and highlighting what appears to be empty space, you can close your search dialog and press CTRL+C to copy to clipboard.

Then paste the character into a unicode search tool. I usually use an online one. http://unicode.scarfboy.com/

Example: I had a bullet point (•) in my code somehow. The unicode value is 2022 (hex), but when read as ascii by the compiler you get 342 200 242 (3 octal values). It’s not as simple as converting each octal values to hex and smashing them together. So "E2 80 A2" is NOT the hex unicode point in your code.

For some weird reason, the following code doesn’t compile. I get a "stray ‘302’ in program" error around volatile unsigned int encoderPos = 0; , and I have no idea what the issue is. I’ve been trying to figure this out for over 40min, and nothing works. It doesn’t make any sense 😭

Читайте также:  Процессор перегружен на 100 что делать

2 Answers 2

0302 is 0xc2. Somewhere in your source you have one or more non-breaking spaces (0xa0) encoded in UTF-8 (0xc2 0xa0). Use od or a similar tool to find them, and then replace them with normal spaces. Since you have non-ASCII Latin-1 characters in your source, those characters are encoded as two bytes with the first being 0xc2 or 0xc3. Remove all non-ASCII characters before proceeding.

One cause of the /(302) error is copy and paste code from a word processor. You have ASCII codes copied that add spaces, etc to your code. Go through each identified line and remove any extra spaces at the beginning and end of any identified line. Then, (Arduino IDE) go to TOOLS, Auto Format. At least, this cleared up the problem for me.

protected by Community ♦ Jan 7 ’18 at 7:47

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

maccatalan

Registered

a source that compiled very well before now does not with the following error.

Here is the code :

When I let this "as it" I get compilation errors :

stray ‘320’ in program
stray ‘240’ in program

When I replace the draw-oval-in-rect instruction by :

then it works very well.

This problem depends only on the NSBezierPath instruction. I tried it on other projects, even empty projets and . nothing to do. Always the same two ununderstable errors.

Рекомендуем к прочтению

Добавить комментарий

Ваш адрес email не будет опубликован.