Ошибка stray 302 in program

I have a problem compiling the following 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 results in 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 (Lucid Lynx) and got the same result.

Peter Mortensen's user avatar

asked Oct 5, 2013 at 13:15

Ahmed Taher's user avatar

23

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

enter image description here

answered Oct 5, 2013 at 13:31

Yu Hao's user avatar

Yu HaoYu Hao

119k44 gold badges231 silver badges290 bronze badges

7

You have invalid characters in your source. If you don’t have any valid non-ASCII characters in your source, maybe in a double quoted string literal, you can simply convert your file back to ASCII with:

tr -cd '11121540-176' < old.c > new.c

The method with iconv will stop at wrong characters which makes no sense. The above command line is working with the example file.

Peter Mortensen's user avatar

answered Oct 5, 2013 at 13:45

Klaus's user avatar

KlausKlaus

24k7 gold badges57 silver badges112 bronze badges

0

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. Example: //: A²+B²=C²
  3. It could potentially damage obvious logic and 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 asterisk (*). Now “SOME_THING” looks like a #define (SOME_THING) and *SomeType is the wrong type (SomeType).

Two more surgical approaches to fixing the problem:

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

  2. Regular expression search all Unicode characters not part of 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 hexadecimal Unicode point in your code.

Peter Mortensen's user avatar

answered Jan 24, 2019 at 18:01

KANJICODER's user avatar

KANJICODERKANJICODER

3,58130 silver badges17 bronze badges

5

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

Encoder * st;

When compiled, it 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 (Unicode code point U+2217).

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

Peter Mortensen's user avatar

answered Jul 21, 2016 at 9:51

TheMagicCow's user avatar

3

Whenever the compiler found a special character, it gives these kind of compile errors. The error I found is as follows:

error: stray ‘302’ in program and error: stray ‘240’ in program

….

It is some piece of code I copied from a chat messenger. In Facebook Messenger, it was a special character only. After copying into the Vim editor it changed to the correct character only. But the compiler was giving the above error .. then .. that statement I wrote manually after .. it got resolved… :)

Peter Mortensen's user avatar

answered Aug 20, 2015 at 5:55

visu's user avatar

visuvisu

212 bronze badges

It’s perhaps because you copied code from the Internet (from a site which has perhaps not an ASCII encoded page, but a 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.

Peter Mortensen's user avatar

answered Feb 3, 2016 at 11:14

Agrim Gupta's user avatar

1

This problem comes when you have copied some text from an HTML page or you have done modification in a Windows environment and are trying to compile in a Unix/Solaris environment.

Please do «dos2unix» to remove the special characters from the file:

dos2unix fileName.ext fileName.ext

Peter Mortensen's user avatar

answered Aug 5, 2015 at 13:05

Saifu Khan's user avatar

Invalid character in your code.

It is a common copy-paste error, especially when code is copied from Microsoft Word documents or PDF files.

Peter Mortensen's user avatar

answered Apr 20, 2019 at 10:25

Victor Mwenda's user avatar

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

How to remove “smart” quotes from a text file

answered Nov 13, 2014 at 13:19

cokedude's user avatar

cokedudecokedude

3791 gold badge10 silver badges20 bronze badges

1

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

Peter Mortensen's user avatar

answered Apr 27, 2014 at 5:02

ravi's user avatar

raviravi

8602 gold badges6 silver badges14 bronze badges

With me, this error occurred when I copied and pasted code in text format to my editor (gedit).

The code was in a text document (.odt). I copied it and pasted it into gedit.

If you did the same, you have manually rewrite the code.

Peter Mortensen's user avatar

answered Jul 8, 2014 at 15:54

Lukasavicus's user avatar

1

I have a problem compiling the following 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 results in 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 (Lucid Lynx) and got the same result.

Peter Mortensen's user avatar

asked Oct 5, 2013 at 13:15

Ahmed Taher's user avatar

23

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

enter image description here

answered Oct 5, 2013 at 13:31

Yu Hao's user avatar

Yu HaoYu Hao

119k44 gold badges231 silver badges290 bronze badges

7

You have invalid characters in your source. If you don’t have any valid non-ASCII characters in your source, maybe in a double quoted string literal, you can simply convert your file back to ASCII with:

tr -cd '11121540-176' < old.c > new.c

The method with iconv will stop at wrong characters which makes no sense. The above command line is working with the example file.

Peter Mortensen's user avatar

answered Oct 5, 2013 at 13:45

Klaus's user avatar

KlausKlaus

24k7 gold badges57 silver badges112 bronze badges

0

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. Example: //: A²+B²=C²
  3. It could potentially damage obvious logic and 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 asterisk (*). Now “SOME_THING” looks like a #define (SOME_THING) and *SomeType is the wrong type (SomeType).

Two more surgical approaches to fixing the problem:

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

  2. Regular expression search all Unicode characters not part of 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 hexadecimal Unicode point in your code.

Peter Mortensen's user avatar

answered Jan 24, 2019 at 18:01

KANJICODER's user avatar

KANJICODERKANJICODER

3,58130 silver badges17 bronze badges

5

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

Encoder * st;

When compiled, it 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 (Unicode code point U+2217).

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

Peter Mortensen's user avatar

answered Jul 21, 2016 at 9:51

TheMagicCow's user avatar

3

Whenever the compiler found a special character, it gives these kind of compile errors. The error I found is as follows:

error: stray ‘302’ in program and error: stray ‘240’ in program

….

It is some piece of code I copied from a chat messenger. In Facebook Messenger, it was a special character only. After copying into the Vim editor it changed to the correct character only. But the compiler was giving the above error .. then .. that statement I wrote manually after .. it got resolved… :)

Peter Mortensen's user avatar

answered Aug 20, 2015 at 5:55

visu's user avatar

visuvisu

212 bronze badges

It’s perhaps because you copied code from the Internet (from a site which has perhaps not an ASCII encoded page, but a 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.

Peter Mortensen's user avatar

answered Feb 3, 2016 at 11:14

Agrim Gupta's user avatar

1

This problem comes when you have copied some text from an HTML page or you have done modification in a Windows environment and are trying to compile in a Unix/Solaris environment.

Please do «dos2unix» to remove the special characters from the file:

dos2unix fileName.ext fileName.ext

Peter Mortensen's user avatar

answered Aug 5, 2015 at 13:05

Saifu Khan's user avatar

Invalid character in your code.

It is a common copy-paste error, especially when code is copied from Microsoft Word documents or PDF files.

Peter Mortensen's user avatar

answered Apr 20, 2019 at 10:25

Victor Mwenda's user avatar

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

How to remove “smart” quotes from a text file

answered Nov 13, 2014 at 13:19

cokedude's user avatar

cokedudecokedude

3791 gold badge10 silver badges20 bronze badges

1

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

Peter Mortensen's user avatar

answered Apr 27, 2014 at 5:02

ravi's user avatar

raviravi

8602 gold badges6 silver badges14 bronze badges

With me, this error occurred when I copied and pasted code in text format to my editor (gedit).

The code was in a text document (.odt). I copied it and pasted it into gedit.

If you did the same, you have manually rewrite the code.

Peter Mortensen's user avatar

answered Jul 8, 2014 at 15:54

Lukasavicus's user avatar

1

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 😭

#include <U8g2lib.h>
#include <SPI.h>

//Pin definitions:

const int control_PWM = A3; //PWM output for the delay 

const int btn_1 = 1; //Button for mode 1
const int btn_2 = 4; //Button for mode 2
const int btn_3 = 5; //Button for mode 3

const int r_A = 2; //Rotary encoder A's data
const int r_B = 3; //Rotary encoder A's data
const int r_SW = 0; //Rotary encoder's button data

const int oled_CLK = 9; //SPI cloack
const int oled_MOSI = 8; //MOSI pin
const int oled_CS = 7; //Chip Select pin
const int oled_DC = 6; //OLED's D/C pin
U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

int mode = 1; //1: RGB, 2: HSL, 3: Distance control
int value_selection = 1; //Actual value selectrion
int value1 = 0; //red in mode 1; tint in mode 2
int value2 = 0; ////green in mode 1; saturation in mode 2
int value3 = 0; //blue in mode 1; luminosity in mode 2

volatile unsigned int encoderPos = 0;  // rotary encoder's current position
unsigned int lastReportedPos = 1;   // rotary encoder's previous position
static boolean rotating=false;      // is the encoder activity status

// interrupter variables
boolean A_set = false;              
boolean B_set = false;
boolean A_change = false;
boolean B_change= false;
void setup() {

}

void loop() {
}

Arduino Forum

Loading

Arduino Stray 302 In Program

How to fix Stray 302 in program On Arduino – This time I want to share about an error that I do not usually experience. When I’m making a program in the arduino IDE.

Then the program I created, I compile to get the results, but there is an error. The error shown here is unusual, I’ve never had an error like this.

The error message is stray 302 in program. Look at the picture below.

Stray 302 Arduino, How to Fix It?

After searching from various references, the error stray 302 in this program occurred because we copied and pasted the text from another data processor into our Arduino IDE.

Sure enough, I took the text from google translate and then I pasted it into the Arduino IDE. The reason is, when I paste, the ASCII code goes into the arduino IDE.

Some of the code that causes errors is usually spaces & quotes (” “).

Steps to fix

If Error by Spacing

Remove the spaces at the beginning and end of the error line, then in the Arduino IDE, select the Tools > Auto Format. Here my problem is solved.

If there are still errors that appear, check again that the spaces that may be in the middle of the sentence have not been removed.

If Error by Quotes

Replace the quotes from the copy and paste from a website like “ ” to ” “.

Tips

If you want to replace the entire error text, you can use the “Find and Replace” feature by pressing CTRL + F on the Arduino IDE, then enter the word you want to replace in the “Find” form and enter a new word that will replace the wrong word. on the “Replace with” form, then click the “Replace All” button.

Hopefully this article is useful.

  • Ошибка str object does not support item assignment
  • Ошибка store data structure corruption windows 10
  • Ошибка stopcode windows 10 что делать
  • Ошибка stopcode memory management
  • Ошибка stop vehicle рено сценик 3