473,796 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with application on Windows x64

P
Hi all,

I have compiled a C application (japach:
http://www.jikos.cz/jikos/japach/) under cygwin on Windows NT. It
works fine on all versions of win32. When I ran it on Windows x64, it
hangs on the following line:

strncpy(buffer2 , client.host_nam e, MAXLINE - strlen(buffer2) );

The problem is client.host_nam e, which is a string. This line is
reached after a few nested calls to different functions. In main,
where client.host_nam e is set, I could output it just fine. When it
gets to this function, it just hangs there.

Shouldn't this work on Windows x64? Winx64 has WOW that allows 32-bit
applications to be run. Is there something I'm not aware of?

Thanks.

Patrick

Nov 10 '06 #1
11 1652
P wrote:
Hi all,

I have compiled a C application (japach:
http://www.jikos.cz/jikos/japach/) under cygwin on Windows NT. It
works fine on all versions of win32. When I ran it on Windows x64, it
hangs on the following line:

strncpy(buffer2 , client.host_nam e, MAXLINE - strlen(buffer2) );

The problem is client.host_nam e, which is a string. This line is
reached after a few nested calls to different functions. In main,
where client.host_nam e is set, I could output it just fine. When it
gets to this function, it just hangs there.
Dunno about the 32 vs 64 bit issue.

As "C" that line looks very odd to me. Why does what you are copying
to it depend on the strlen of the current contents?!? Often the target
of a strcpy/strncpy has garbage in it. Consider if that garbage has no
NUL characters for MAXLINE bytes.... You get a very large number.
And strncpy is the wrong tool for almost any task.

-David

Nov 10 '06 #2
In article <11************ *********@m73g2 000cwd.googlegr oups.com>,
P <sp************ @yahoo.comwrote :
>strncpy(buffer 2, client.host_nam e, MAXLINE - strlen(buffer2) );
strncpy() would normally be used to write into its first argument,
buffer2 in this case.

Has buffer2 been initialized at that point? If it has not been,
then when you take strlen(buffer2) in the third parameter, you
could get just about anything for the length as strlen() will keep
looking past the end of buffer2 until it happens to find a '\0'.

If buffer2 has indeed been initialized at that point, then
what is the point of making the maximum copying length dependant
on its current contents, when you are overwriting those contents?
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Nov 10 '06 #3
P

Walter Roberson wrote:
In article <11************ *********@m73g2 000cwd.googlegr oups.com>,
P <sp************ @yahoo.comwrote :
strncpy(buffer2 , client.host_nam e, MAXLINE - strlen(buffer2) );

strncpy() would normally be used to write into its first argument,
buffer2 in this case.

Has buffer2 been initialized at that point? If it has not been,
then when you take strlen(buffer2) in the third parameter, you
could get just about anything for the length as strlen() will keep
looking past the end of buffer2 until it happens to find a '\0'.

If buffer2 has indeed been initialized at that point, then
what is the point of making the maximum copying length dependant
on its current contents, when you are overwriting those contents?
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
I'm not sure what the intend of the developer was. A few lines above
that, there's this:

strcpy(buffer2, "");

So strlen(buffer2) is 0 when it gets to that statement where it hangs.
This shouldn't cause the app to hang, should it?

Patrick

Nov 10 '06 #4
P said:
>P <sp************ @yahoo.comwrote :
>strncpy(buffer 2, client.host_nam e, MAXLINE - strlen(buffer2) );
<snip>
>
I'm not sure what the intend of the developer was. A few lines above
that, there's this:

strcpy(buffer2, "");

So strlen(buffer2) is 0 when it gets to that statement where it hangs.
This shouldn't cause the app to hang, should it?
It depends on how large an array buffer2 represents. If buffer2 has fewer
than MAXLINE characters available, the buffer will be overrun, and that
could certainly cause the program to exhibit serious problems, which may
well include "hanging".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 10 '06 #5

P wrote:
Walter Roberson wrote:
In article <11************ *********@m73g2 000cwd.googlegr oups.com>,
P <sp************ @yahoo.comwrote :
>strncpy(buffer 2, client.host_nam e, MAXLINE - strlen(buffer2) );
strncpy() would normally be used to write into its first argument,
buffer2 in this case.

Has buffer2 been initialized at that point? If it has not been,
then when you take strlen(buffer2) in the third parameter, you
could get just about anything for the length as strlen() will keep
looking past the end of buffer2 until it happens to find a '\0'.

If buffer2 has indeed been initialized at that point, then
what is the point of making the maximum copying length dependant
on its current contents, when you are overwriting those contents?
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton

I'm not sure what the intend of the developer was. A few lines above
that, there's this:

strcpy(buffer2, "");

So strlen(buffer2) is 0 when it gets to that statement where it hangs.
This shouldn't cause the app to hang, should it?
No. strncpy is still a dodgy thing here, because if MAXLINE characters
are copied it will result in a non-NUL-terminated string. Having
peeked at the source, MAXLINE is 2048. Even if MAXLINE characters are
not copied, it is wasteful -- it means for a 48 character hostname
there is a side effect of a 2000 byte memset. Which is legal, just
silly.

I suspect the client.host_nam e contents. The code where I see that
assigned is this:

if (NULL !=
(hostentry =
gethostbyaddr(( char *) &cli_addr.sin_a ddr,
sizeof(cli_addr .sin_addr),
AF_INET)))
client.host_nam e = hostentry->h_name;
else
client.host_nam e =
inet_ntoa(cli_a ddr.sin_addr)

Forgetting the (off topic) platform specific details of what the above
POSIX/BSD functions do, I'd guess that this might be fixed by copying
the values placed in the host_name field (and handling the memory
management, or having it be a character array in the struct). Just a
guess though...

-David

Nov 10 '06 #6
2006-11-10 <11************ **********@e3g2 000cwe.googlegr oups.com>,
David Resnick wrote:
P wrote:
>Hi all,

I have compiled a C application (japach:
http://www.jikos.cz/jikos/japach/) under cygwin on Windows NT. It
works fine on all versions of win32. When I ran it on Windows x64, it
hangs on the following line:

strncpy(buffer 2, client.host_nam e, MAXLINE - strlen(buffer2) );

The problem is client.host_nam e, which is a string. This line is
reached after a few nested calls to different functions. In main,
where client.host_nam e is set, I could output it just fine. When it
gets to this function, it just hangs there.

Dunno about the 32 vs 64 bit issue.

As "C" that line looks very odd to me. Why does what you are copying
to it depend on the strlen of the current contents?!? Often the target
of a strcpy/strncpy has garbage in it. Consider if that garbage has no
NUL characters for MAXLINE bytes.... You get a very large number.
And strncpy is the wrong tool for almost any task.
It looks like he wants strcat.
Nov 10 '06 #7
P

David Resnick wrote:
P wrote:
Walter Roberson wrote:
In article <11************ *********@m73g2 000cwd.googlegr oups.com>,
P <sp************ @yahoo.comwrote :
>
strncpy(buffer2 , client.host_nam e, MAXLINE - strlen(buffer2) );
>
strncpy() would normally be used to write into its first argument,
buffer2 in this case.
>
Has buffer2 been initialized at that point? If it has not been,
then when you take strlen(buffer2) in the third parameter, you
could get just about anything for the length as strlen() will keep
looking past the end of buffer2 until it happens to find a '\0'.
>
If buffer2 has indeed been initialized at that point, then
what is the point of making the maximum copying length dependant
on its current contents, when you are overwriting those contents?
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
I'm not sure what the intend of the developer was. A few lines above
that, there's this:

strcpy(buffer2, "");

So strlen(buffer2) is 0 when it gets to that statement where it hangs.
This shouldn't cause the app to hang, should it?

No. strncpy is still a dodgy thing here, because if MAXLINE characters
are copied it will result in a non-NUL-terminated string. Having
peeked at the source, MAXLINE is 2048. Even if MAXLINE characters are
not copied, it is wasteful -- it means for a 48 character hostname
there is a side effect of a 2000 byte memset. Which is legal, just
silly.

I suspect the client.host_nam e contents. The code where I see that
assigned is this:

if (NULL !=
(hostentry =
gethostbyaddr(( char *) &cli_addr.sin_a ddr,
sizeof(cli_addr .sin_addr),
AF_INET)))
client.host_nam e = hostentry->h_name;
else
client.host_nam e =
inet_ntoa(cli_a ddr.sin_addr)

Forgetting the (off topic) platform specific details of what the above
POSIX/BSD functions do, I'd guess that this might be fixed by copying
the values placed in the host_name field (and handling the memory
management, or having it be a character array in the struct). Just a
guess though...

-David
David,

Thanks! That fixed it. But I'm not sure why it works. Could you
explain it to me?

This is what I've changed:

- in client struct (japach.h), from char *host_name; to char
host_name[MAXLINE];
- in japach.c:

if (NULL !=
(hostentry =
gethostbyaddr(( char *) &cli_addr.sin_a ddr,
sizeof(cli_addr .sin_addr),
AF_INET)))
//client.host_nam e = hostentry->h_name;
strcpy(client.h ost_name,
hostentry->h_name);
else
//client.host_nam e =
// inet_ntoa(cli_a ddr.sin_addr)
strcpy(client.h ost_name,
inet_ntoa(cli_a ddr.sin_addr) );

Thanks again!

Patrick

Nov 10 '06 #8

P wrote:
David Resnick wrote:
Forgetting the (off topic) platform specific details of what the above
POSIX/BSD functions do, I'd guess that this might be fixed by copying
the values placed in the host_name field (and handling the memory
management, or having it be a character array in the struct). Just a
guess though...

-David

David,

Thanks! That fixed it. But I'm not sure why it works. Could you
explain it to me?

This is what I've changed:

- in client struct (japach.h), from char *host_name; to char
host_name[MAXLINE];
- in japach.c:

if (NULL !=
(hostentry =
gethostbyaddr(( char *) &cli_addr.sin_a ddr,
sizeof(cli_addr .sin_addr),
AF_INET)))
//client.host_nam e = hostentry->h_name;
strcpy(client.h ost_name,
hostentry->h_name);
else
//client.host_nam e =
// inet_ntoa(cli_a ddr.sin_addr)
strcpy(client.h ost_name,
inet_ntoa(cli_a ddr.sin_addr) );
As a general rule, it is a bad idea to keep a pointer to a string which
is not guaranteed to be unchanged if that is what one needs. Rather it
is better to copy the string into something one owns. <OT>Both
gethostbyaddr and inet_ntoa return a pointer to static storage that can
be overwritten. Good idea is to use safer versions of these functions
or to copy the result.</OT>

-David

Nov 11 '06 #9
P
As a general rule, it is a bad idea to keep a pointer to a string which
is not guaranteed to be unchanged if that is what one needs. Rather it
is better to copy the string into something one owns. <OT>Both
gethostbyaddr and inet_ntoa return a pointer to static storage that can
be overwritten. Good idea is to use safer versions of these functions
or to copy the result.</OT>

-David
David,

What are the safer versions of gethostbyaddr and inet_ntoa?

Patrick

Nov 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2027
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be returned as DataSet. Now, here's the problem. On .NET Framework 1.1, if any rows in the dataset returned contain errors (marked by calling the SetColumnError() method or
1
2393
by: Marino | last post by:
Hi all, I have a Windows 2003 server, which is also a terminal server for application, with sql 2000 installed. My company has developed an application that uses SQL 2000 as its database. The application is a client/server one. In each client computer there's a link to the application on the server. There is no problem with Windows 98, Windows 2000 pro, Windows xp pro clients, but the windows 95 ones cannot log in to the database. The...
9
2825
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am facing. Please please help me to solve this as soon as possible. So here we go ... I am not able to take the screen shot of the windows form based "Smart
3
1581
by: pnp | last post by:
Hi all, I have developed an app in C# and I have used some of the Infragistics components in it. The problem is that while one is playing with the windows within the mdi container exceptions occur that are not being handled by any Exception handler. I have also placed one after the application run method so if any exception occurs this "sink" will catch it. But instead an error occurs from an unhandled exception and the application...
36
2488
by: AussieRules | last post by:
Hi, I want to use the user color scheme to set the color of my forms. I now I have to use the. System.Drawing.SystemColors, but which color is the color of a form background as used in other applications. In the end all I want to do is form1.backcolor = system.whatever.color
0
1887
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all of my base classes including my base MDI Container form and my base MDI child form the mdi container has a singleton which returns an
2
2568
by: Sin Jeong-hun | last post by:
I created a windows form application. It has a Threading.Timer and when the timer ticks it does some work and show a popup window. The problem is that while this program is running if the user tries to shutdown Windows, my application doesn't quit and neither does Windows. Of course, if the user first click of my application and then tries to shutdown, there is no problem. To solve this problem, I overrode WndProc of the main form,...
5
2007
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: *************************************************************************************************************** { ........................... PrintTimeSpanProblem(); device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); PrintTimeSpanProblem();
3
5324
by: Gerrit | last post by:
Hi, I try to learn programming in c# with databinding controls. Now I have a problem with a ComboBox with the advanced properties for databinding, I want to set the DataSourceUpdateMode to OnPropertyChanged, but then the combobox does not display the right displaymember. Below is my sample code (it is working, when you paste it in a new windowsapplication, in a form and delete some generated code, but it is not a useful program but...
6
4500
by: Scott Gravenhorst | last post by:
Windows XP SP3 My application is set to open a SaveFile dialog when an exit is requested. When I click the app's close button, the save dialog opens, but when I click to change the folder, the exception occurs pointing to FileSaveDialog1.ShowDialog(). The exception also indicates some problem with system.drawing.dll. The exception text is: "Attempted to read or write protected memory. This is often an
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10006
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.