Re: Portability: common-src/ammessage.c

Jean-Louis Martineau <[email protected]>
Newsgroups gmane.comp.archivers.amanda.devel
Message-ID <[email protected]>
We don't care if they are defined by gnulib or not, what is important is the array size, the check should be like:

#if defined(EBADMSG) && EBADMSG<500

A constant should be use instead of harcoding 500, we could increase it to 2500

#define MAX_ERRCODE 500
char *errcode[MAX_ERRCODE];

#if defined(EBADMSG) && EBADMSG<MAX_ERRCODE

All use of errode[] must also be checked for the value <MAX_ERRCODE

Jean-Louis

On 02/01/17 02:41 PM, Eric Schnoebelen wrote:
> common-src/ammessage.c attempts to build an strerror() type
> interface (kinda), allocating an array of 500 elements, which
> are filled in with text versions of the errno values.
>
> The issue?  gnulib's version of errno.h creates additional
> values in the 2000 range if the E* values it wants to use aren't
> already defined.  And then ammessage.c tries to use the 2000+
> valued errno values in an array of size 500.. Nice coredump at
> runtime!
>
> Fix:  Verify that the errno values weren't defined by gnulib
> before attempting to use them to populate the array.
>
> patch both inline and as an attachment..
>
>
> $NetBSD$
>
> Make sure the E* macros aren't GNULIB macros, as those are defined in
> the 2000+ space.
>
> --- common-src/ammessage.c.orig	2016-11-23 16:11:16.000000000 +0000
> +++ common-src/ammessage.c
> @@ -76,7 +76,7 @@ init_errcode(void)
>   #ifdef EBADFD
>     errcode[EBADFD] = "EBADFD";
>   #endif
> -#ifdef EBADMSG
> +#if defined(EBADMSG) && !defined(GNULIB_defined_EBADMSG)
>     errcode[EBADMSG] = "EBADMSG";
>   #endif
>   #ifdef EBADR
> @@ -91,7 +91,7 @@ init_errcode(void)
>   #ifdef EBUSY
>     errcode[EBUSY] = "EBUSY";
>   #endif
> -#ifdef ECANCELED
> +#if defined(ECANCELED) && !defined(GNULIB_defined_ECANCELED)
>     errcode[ECANCELED] = "ECANCELED";
>   #endif
>   #ifdef ECHILD
> @@ -103,7 +103,7 @@ init_errcode(void)
>   #ifdef ECOMM
>     errcode[ECOMM] = "ECOMM";
>   #endif
> -#ifdef ECONNABORTED
> +#if defined(ECONNABORTED) && !defined(GNULIB_defined_ECONABORTED)
>     errcode[ECONNABORTED] = "ECONNABORTED";
>   #endif
>   #ifdef ECONNREFUSED
> @@ -126,7 +126,7 @@ init_errcode(void)
>   #ifdef EDOM
>     errcode[EDOM] = "EDOM";
>   #endif
> -#ifdef EDQUOT
> +#if defined(EDQUOT) && !defined(GNULIB_defined_EDQUOT)
>     errcode[EDQUOT] = "EDQUOT";
>   #endif
>   #ifdef EEXIST
> @@ -147,7 +147,7 @@ init_errcode(void)
>   #ifdef EIDRM
>     errcode[EIDRM] = "EIDRM";
>   #endif
> -#ifdef EILSEQ
> +#if defined(EILSEQ) && !defined(GNULIB_defined_EILSEQ)
>     errcode[EILSEQ] = "EILSEQ";
>   #endif
>   #ifdef EINPROGRESS
> @@ -222,7 +222,7 @@ init_errcode(void)
>   #ifdef EMSGSIZE
>     errcode[EMSGSIZE] = "EMSGSIZE";
>   #endif
> -#ifdef EMULTIHOP
> +#if defined(EMULTIHOP) && !defined(GNULIB_defined_EMULTIHOP)
>     errcode[EMULTIHOP] = "EMULTIHOP";
>   #endif
>   #ifdef ENAMETOOLONG
> @@ -231,7 +231,7 @@ init_errcode(void)
>   #ifdef ENETDOWN
>     errcode[ENETDOWN] = "ENETDOWN";
>   #endif
> -#ifdef ENETRESET
> +#if defined(ENETRESET) && !defined(GNULIB_defined_ENETRESET)
>     errcode[ENETRESET] = "ENETRESET";
>   #endif
>   #ifdef ENETUNREACH
> @@ -261,7 +261,7 @@ init_errcode(void)
>   #ifdef ENOLCK
>     errcode[ENOLCK] = "ENOLCK";
>   #endif
> -#ifdef ENOLINK
> +#if defined(ENOLINK) && !defined(GNULIB_defined_ENOLINK)
>     errcode[ENOLINK] = "ENOLINK";
>   #endif
>   #ifdef ENOMEDIUM
> @@ -270,7 +270,7 @@ init_errcode(void)
>   #ifdef ENOMEM
>     errcode[ENOMEM] = "ENOMEM";
>   #endif
> -#ifdef ENOMSG
> +#if defined(ENOMSG) && !defined(GNULIB_defined_ENOMSG)
>     errcode[ENOMSG] = "ENOMSG";
>   #endif
>   #ifdef ENONET
> @@ -309,7 +309,7 @@ init_errcode(void)
>   #ifdef ENOTSOCK
>     errcode[ENOTSOCK] = "ENOTSOCK";
>   #endif
> -#ifdef ENOTSUP
> +#if defined(ENOTSUP) && !defined(GNULIB_defined_ENOTSUP)
>     errcode[ENOTSUP] = "ENOTSUP";
>   #endif
>   #ifdef ENOTTY
> @@ -324,7 +324,7 @@ init_errcode(void)
>   #ifdef EOPNOTSUPP
>     errcode[EOPNOTSUPP] = "EOPNOTSUPP";
>   #endif
> -#ifdef EOVERFLOW
> +#if defined(EOVERFLOW) && !defined(GNULIB_defined_EOVERFLOW)
>     errcode[EOVERFLOW] = "EOVERFLOW";
>   #endif
>   #ifdef EPERM
> @@ -336,7 +336,7 @@ init_errcode(void)
>   #ifdef EPIPE
>     errcode[EPIPE] = "EPIPE";
>   #endif
> -#ifdef EPROTO
> +#if defined(EPROTO) && !defined(GNULIB_defined_EPROTO)
>     errcode[EPROTO] = "EPROTO";
>   #endif
>   #ifdef EPROTONOSUPPORT
> @@ -375,7 +375,7 @@ init_errcode(void)
>   #ifdef ESRCH
>     errcode[ESRCH] = "ESRCH";
>   #endif
> -#ifdef ESTALE
> +#if defined(ESTALE) && !defined(GNULIB_defined_ESTALE)
>     errcode[ESTALE] = "ESTALE";
>   #endif
>   #ifdef ESTRPIPE
> @@ -408,10 +408,10 @@ init_errcode(void)
>   #ifdef EXFULL
>     errcode[EXFULL] = "EXFULL";
>   #endif
> -#ifdef EOWNERDEAD
> +#if defined(EOWNERDEAD) && !defined(GNULIB_defined_EOWNERDEAD)
>     errcode[EOWNERDEAD] = "EOWNERDEAD";
>   #endif
> -#ifdef ENOTRECOVERABLE
> +#if defined(ENOTRECOVERABLE) && !defined(GNULIB_defined_ENOTRECOVERABLE)
>     errcode[ENOTRECOVERABLE] = "ENOTRECOVERABLE";
>   #endif
>   #ifdef ERFKILL
>

Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business. Providing a safer and more useful place for your human generated data. Specializing in; Security, archiving and compliance. To find out more visit the Mimecast website.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.