Compilation error: stray ‘\302’ in program etc

后端 未结 13 2102
眼角桃花
眼角桃花 2020-12-01 14:03

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

相关标签:
13条回答
  • 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.

    0 讨论(0)
  • 2020-12-01 14:18

    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.. :)

    0 讨论(0)
  • 2020-12-01 14:20

    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 :-)

    0 讨论(0)
  • 2020-12-01 14:22

    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:

    1. Switch fonts to see the character. (It might be invisible in your current font)
    2. Regex search all unicode characters not part non-extended ascii. In notepad++ I can search up to FFFF, which hasn't failed me yet.

      [\x{80}-\x{FFFF}]

      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.

    0 讨论(0)
  • 2020-12-01 14:28

    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.

    0 讨论(0)
  • 2020-12-01 14:31

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

    enter image description here

    0 讨论(0)
提交回复
热议问题