Sponsored Content
Full Discussion: c++ overflow problem
Top Forums Programming c++ overflow problem Post 302256213 by mshindo on Saturday 8th of November 2008 07:29:07 PM
Old 11-08-2008
c++ overflow problem

I have come accross a rather strange problem with two buffers that seem to be overriding each other.

Code:
bool killSession(const Session &session){
//Get user
	FILE* fp = fopen("conf/sessions.current", "rt");
	char line[1024]; char user[1024]; int x = 0; int leaseTime;
	printf("key: %s \n" , session.macAddress);

	while(fgets(line, 1024, fp) != NULL){
			x++;	
			int id; char addr[1024];
			sscanf(line, "%i %s %s %i", &id, addr, user, &leaseTime);
			addr[17] = '\0';
			
			printf("key: %s \naddr: %s \n", session.macAddress, addr);
			
			if(strcmp(addr, session.macAddress) != 0){
				printf("mac address found in file: %s \n", line);
				int gid =  getGroupId(user);
				char* accessType =  checkAccessType(gid);
				//modifyFirewall(accessType, session.macAddress, 0);
				break;
			}
		}
	//Finally remove session from session.current
	deleteLine("conf/sessions.current", x);
	fclose(fp);
return true;
}

gives the output:

Code:
key: 00:13:A9:A5:5D:EF 
key: 00:10 fakesessionthat michael 1999999999
 
addr: fakesessionthat 
mac address found in file: 0 fakesessionthat michael 1999999999

From that output it would seem that in the while loop that reads the session file session.macAddress is getting replaced by a part of the line variable. Have I actually managed to buffer overflow my own program.

Can someone please explain how ive gone wrong.

Thankyou

Cheers
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Printer buffer overflow

I have an Oki-Page 14ex with 4MB of RAM. Whenever I print large documents or a several small documents, I get a buffer overflow. Can anyone help? Thanks. If there is any additional information you need, please feel free to ask. Tim (3 Replies)
Discussion started by: AltatemTC
3 Replies

2. UNIX for Dummies Questions & Answers

Line overflow??

Hi everybody, I have a problem. I'm trying to ftp a file to a remote system. my shell that wrote is look for a data in a area and when it there its starting the ftp.:) At this point it works. Then it does cd $quelle ftp -n test <<EUF user anonymous test image put W* EUF and so... (12 Replies)
Discussion started by: Peterh
12 Replies

3. Programming

warning: integer overflow in expression

I have the following expression: #define GB (1024 * 1024 * 1024) #define TB (1024 * GB) #define MAX_SIZE (3 * TB) off_t current_size; And then the expression... if (current_size > MAX_SIZE) { ... (1 Reply)
Discussion started by: tantric
1 Replies

4. HP-UX

Problem with stack overflow

Hi, I get a problem with stack overflow on HP-UX, when running a C program. Pid 28737 received a SIGSEGV for stack growth failure. Possible causes: insufficient memory or swap space, or stack size exceeded maxssiz. The possible cause i found, was that the definition of a structure had... (0 Replies)
Discussion started by: karthikb23
0 Replies

5. Shell Programming and Scripting

How not to let field overflow ?

Hi All I ahve a basic script with a screen. Is there anyway that I can make it possible for the user not to type over the ] ie I would like the inpu to be only with the brakcets? Any suggestions welcome. :b: eg DB name: function get_fdb { while ] do tput cup 9 41 ... (1 Reply)
Discussion started by: WhitesinHolland
1 Replies

6. Ubuntu

Stack overflow i guess while insmod

I have built kernel 2.6.35 on my Ubuntu system with some specific requirement. I also built some app defined module with the same kernel. I booted up the built version and I find it did not work properly as there is some gui and other modules missing problem. But the system booted up and I did... (0 Replies)
Discussion started by: sunilsukumar4u
0 Replies

7. UNIX for Dummies Questions & Answers

perform stack overflow

Help! I have an AIX system that has a power outage. When I logged in as root and got the system up and running it all looked ok. But.....when a user tries to log in they receive the error: The perform stack has overflowed OP=2117 PC=2124 E=46 in emmcshflif icrun is finished How can I fix... (1 Reply)
Discussion started by: dlegnar
1 Replies

8. UNIX for Advanced & Expert Users

neighbor table overflow

hi folks, Do you have any idea why this error occurs ? My server is hp blade in c7000 frames running RHEL 4 update 4. # uname -a Linux xxx 3 2.6.9-55.0.12.ELsmp #1 SMP Wed Oct 17 08:15:59 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux Applications running are jboss or java applications: #... (4 Replies)
Discussion started by: linuxgeek
4 Replies
sb2-session(1)						       sb2-session man page						    sb2-session(1)

NAME
sb2-session - manage scratchbox2 sessions SYNOPSIS
sb2-session [COMMAND [PARAMS]] DESCRIPTION
sb2-session is used to create attachable scratchbox2 sessions. You can save session even when you haven't done '-S session' during sb2 startup. Note that you can give parameters to attach command which are passed verbatim to sb2. If there is only one session to attach, it is selected automatically. If no command is given, help text is printed. COMMANDS
help shows help text save saves current session list lists detached sb2 sessions delete SESSION deletes given session attach [SESSION [PARAMS]] attaches to a given session setenv VARIABLE VALUE store a value for an environment variable showenv show stored environment variables EXAMPLES
Basic usage is: [SB2 .. ] $ sb2-session save # save session [SB2 .. ] $ ^D # exit Later we can then attach to this session: % sb2-session attach If there are more than one saved session, then: % sb2-session list session.XXXX TARGET_ARM My Comment session.YYYY TARGET_ARM My Comment 2 session.ZZZZ TARGET_MIPS % sb2-session attach session.YYYY Here we pass '-eR' to sb2 and we only have one saved session: % sb2-session attach -- -eR '--' marks end of parameter list for sb2-session. setenv VARIABLE VALUE can be used to add environment variables, that will become active when a saved session is later taken into use (either by sb2-session attach or by sb2 -J). setenv VARIABLE VALUE does not change environment of sessions that are already active. showenv lists environment variable settings which have been stored with this tool. It does not show environment variables from other sources. SEE ALSO
sb2(1) AUTHOR
Mika Westerberg 2.2 21 December 2010 sb2-session(1)
All times are GMT -4. The time now is 12:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy