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 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
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
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
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.
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
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.
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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...
|
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
|
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...
|
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
| |
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
|
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,...
|
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();
|
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...
|
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
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
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
|
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...
| |