[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] SYS_NMLN



Hi,

Frank Naumann wrote:
Hello!


Brief check gave me that this constan represents length of the
entries of the utsname structure defined in sys/utsname.h.

Correct.


This constant should be also defined in sys/utsname.h and should
be at least 256, so adding

No, 256 is a quite large value.  It is not a required minimum.


#define SYS_NMLN       256

seems resonable.

Can the library mainainer(s) express their opinion about it?

I'm the ex-maintainer...

After looking at it it's not POSIX (POSIX explicitly state that the length

The macro comes from SVID (System V Interface Description).

Since it is not ANSI C, it should not be defined unconditionally, but rather like this:

    #ifdef __USE_SVID
    # define SYS_NMLN 9
    #endif

But you should not define that macro at all for the MiNTLib because the definition of that constant suggests that all members of "struct utsname" have a constant length, which is _not_ the case with the MiNTLib. Defining it to a wrong value, may lead to a buffer overflow. The only "safe" definition would be the minimum value 9.

So, what's the use of the macro? If it is used as the *constant* size of the structure members, you have to re-write the sources anyhow, since this assumption is wrong for MiNT. If it is used to retrieve the size of a particular member, you can just as well use the sizeof operator.

As long as "struct utsname" uses these small sizes, I would rather not define SYS_NMLN at all. This will intentionally provoke compile-time errors, that are easy to fix.

Ciao

Guido
--
Imperia AG, Development
Leyboldstr. 10 - D-50354 Hürth - http://www.imperia.net/