Bug 7483 - several files in .../lib/popt/ use non-standard alloca()
Summary: several files in .../lib/popt/ use non-standard alloca()
Status: RESOLVED INVALID
Alias: None
Product: Samba 3.6
Classification: Unclassified
Component: Build environment (show other bugs)
Version: 3.6.8
Hardware: Other Other
: P3 normal
Target Milestone: ---
Assignee: Stefan Metzmacher
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-01 08:08 UTC by Joachim Schmitz (mail address dead)
Modified: 2023-01-08 20:47 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Schmitz (mail address dead) 2010-06-01 08:08:07 UTC
.../lib/popt/findme.c, .../lib/popt/popt.c, .../lib/popt/poptconfig.c, .../lib/popt/popthelp.c and ./lib/popt/poptparse.c use alloca() unconditionally and as such even on platforms that don't provide this non-standard API.

Other OpenSource projects (e.g. bash) provide their implementaion of alloca() in these cases.

in .../source4/heimdal/lib/com_err/parse.c I found this:
#define alloca(x) malloc(x)

Not sure whether this might be the proper fix though.

Bye, Jojo
Comment 1 Simo Sorce 2010-06-01 08:19:18 UTC
(In reply to comment #0)
> in .../source4/heimdal/lib/com_err/parse.c I found this:
> #define alloca(x) malloc(x)
> 
> Not sure whether this might be the proper fix though.

It is proper only if you want memory leaks.
The reason people use alloca() is that memory is allocated on the stack and then automatically freed when the function returns. If you change it into a malloc() then memory will never be freed.
Comment 2 Joachim Schmitz (mail address dead) 2010-06-01 08:20:41 UTC
OK, then it is not the proper fix ;-)
Comment 3 Björn Jacke 2010-06-18 07:19:50 UTC
metze, when time permits, can you have a look how this can be solved?
Comment 4 Joachim Schmitz (mail address dead) 2011-03-01 06:21:17 UTC
We've found a working method now for HP NonStop

extern void *_alloca(unsigned short size);
#pragma intrinsic(_alloca)
#define alloca _alloca

A bit similar as AIX?

Maybe this can get added in the proper places?

Bye, Jojo
Comment 5 Joachim Schmitz (mail address dead) 2012-09-18 15:05:30 UTC
This issue is still valid
Comment 6 Volker Lendecke 2012-09-18 15:55:01 UTC
Is there a way to get a system popt for you? lib/popt is not really maintained here as almost all systems we build on have a system popt around. True, we should do more if we ship it, but the reality is that lib/popt shipped by Samba is a bit orphaned.

Also, in lib/popt/system.h there seems to be special handling for alloca, HP cc is even mentioned explicitly there.
Comment 7 Joachim Schmitz (mail address dead) 2012-09-18 15:57:13 UTC
(In reply to comment #6)
> Is there a way to get a system popt for you? lib/popt is not really maintained
> here as almost all systems we build on have a system popt around. True, we
> should do more if we ship it, but the reality is that lib/popt shipped by Samba
> is a bit orphaned.

No, dont have it on NonStop

> Also, in lib/popt/system.h there seems to be special handling for alloca, HP cc
> is even mentioned explicitly there.

For sure not HP NonStop, probably HP/UX
Comment 8 Joachim Schmitz (mail address dead) 2012-09-18 16:03:02 UTC
(In reply to comment #6)
> Also, in lib/popt/system.h there seems to be special handling for alloca, HP cc
> is even mentioned explicitly there.

This is the place where gnulib recently added support for HP NonStopÄs alloca
Comment 9 Volker Lendecke 2012-09-18 16:16:16 UTC
So, do you have this as a patch that works for you?

BTW, would it be possible that you put your tree that works for you to some public git repo?
Comment 10 Joachim Schmitz (mail address dead) 2012-09-18 16:31:47 UTC
(In reply to comment #9)
> So, do you have this as a patch that works for you?
> BTW, would it be possible that you put your tree that works for you to some
> public git repo?

I can did up the gnilib way of doing this and generate and send a patch base on git master. Is that what you mean or at least sufficient?
Comment 11 Joachim Schmitz (mail address dead) 2012-09-18 16:41:36 UTC
Gnulib has this in alloca.h

#ifndef alloca
# ifdef __GNUC__
#  define alloca __builtin_alloca
# elif defined _AIX
#  define alloca __alloca
# elif defined _MSC_VER
#  include <malloc.h>
#  define alloca _alloca
# elif defined __DECC && defined __VMS
#  define alloca __ALLOCA
# elif defined __TANDEM && defined _TNS_E_TARGET
#  ifdef  __cplusplus
extern "C"
#  endif
void *_alloca (unsigned short);
#  pragma intrinsic (_alloca)
#  define alloca _alloca
# else
#  include <stddef.h>
#  ifdef  __cplusplus
extern "C"
#  endif
void *alloca (size_t);
# endif
#endif


The "#elif defined __TANDEM && defined _TNS_E_TARGET" part got added quite recently
Comment 12 Jelmer Vernooij 2012-11-12 17:07:02 UTC
Since we're just bundling this library for convenience, would it be possible to submit a patch upstream? Upstream is at http://rpm5.org/files/popt/

We can then pull in the newer version of popt into Samba. At the moment we don't have any changes from upstream, it would be nice if we can keep it that way.
Comment 13 Volker Lendecke 2012-11-12 19:26:01 UTC
They would accept such modifications?
Comment 14 Jelmer Vernooij 2012-11-12 19:50:05 UTC
(In reply to comment #13)
> They would accept such modifications?
I would expect so - popt is supposed to be a generic option parsing library (not specific to RPM/Linux) and they have other portability support.
Comment 15 Björn Jacke 2023-01-08 20:47:55 UTC
closing this, as this is not a Samba bug. HPE or who else needs a fix here, should submit a patch to the popt project.