Re: [patch] uvm_mmap / little change proposal

2018-08-21 Thread David CARLIER
I knew it was not documented for a reason but why is it ? Just curious
... but it s ok if we drop this change ...
On Tue, 21 Aug 2018 at 16:38, Mark Kettenis  wrote:
>
> > From: "Todd C. Miller" 
> > Date: Tue, 21 Aug 2018 09:19:05 -0600
> >
> > On Tue, 21 Aug 2018 08:57:06 +0100, David CARLIER wrote:
> >
> > > For portability sake and to make it more "visible" I changed the
> > > __MAP_NOREPLACE to MAP_EXCL, documented it in the man page and also
> > > changed the errno to EEXIST instead (I thought it would reflect
> > > better the error in case the addressed mapped already exists but
> > > can be changed back in case ...).
> >
> > Does anyone other than FreeBSD define MAP_EXCL?  A quick google
> > search didn't turn up any other systems with it.
>
> The symbol starts with a double underscore for a reason.  We really
> didn't want this to be used outside of the very specific code in base
> that needs this.



Re: [patch] uvm_mmap / little change proposal

2018-08-21 Thread David CARLIER
No one else .. Linux has MAP_FIXED_NOREPLACE which is
MAP_FIXED|MAP_EXCL equivalent...
On Tue, 21 Aug 2018 at 16:19, Todd C. Miller  wrote:
>
> On Tue, 21 Aug 2018 08:57:06 +0100, David CARLIER wrote:
>
> > For portability sake and to make it more "visible" I changed the
> > __MAP_NOREPLACE to MAP_EXCL, documented it in the man page and also
> > changed the errno to EEXIST instead (I thought it would reflect
> > better the error in case the addressed mapped already exists but
> > can be changed back in case ...).
>
> Does anyone other than FreeBSD define MAP_EXCL?  A quick google
> search didn't turn up any other systems with it.
>
>  - todd



[patch] uvm_mmap / little change proposal

2018-08-21 Thread David CARLIER
Hi,

For portability sake and to make it more "visible" I changed the
__MAP_NOREPLACE to MAP_EXCL, documented it in the man page and also changed the
errno to EEXIST instead (I thought it would reflect better the error
in case the addressed mapped already exists but can be changed back in
case ...).

Thanks.

Regards.


uvm_mmap.diff
Description: Binary data


Re: [update] base zlib

2018-07-14 Thread David CARLIER
Ah right if it relates to lib 1.2.8 that might do ...
On Sat, 14 Jul 2018 at 19:41, Bryan Steele  wrote:
>
> On Sat, Jul 14, 2018 at 07:32:23PM +0100, Stuart Henderson wrote:
> > There have been several diffs to update this already, they have been
> > rejected (upstream using some things that were not wanted iirc).
> >
> > --
> > Sent from a phone, apologies for poor formatting.
>
> IIRC Jonas Termansen's https://sortix.org/libz/ was once proposed as a
> substitute.
>
> -Bryan.
>



[patch] xargs - few allocation size fixes

2018-06-12 Thread David CARLIER
Hi,

here a little patch proposal for xargs command line.

Thanks.

Kind regards.
Index: xargs.c
===
RCS file: /cvs/src/usr.bin/xargs/xargs.c,v
retrieving revision 1.33
diff -u -p -r1.33 xargs.c
--- xargs.c	16 Oct 2017 13:10:50 -	1.33
+++ xargs.c	11 Jun 2018 10:05:23 -
@@ -198,7 +198,7 @@ main(int argc, char *argv[])
 	 * NULL.
 	 */
 	linelen = 1 + argc + nargs + 1;
-	if ((av = bxp = calloc(linelen, sizeof(char **))) == NULL)
+	if ((av = bxp = calloc(linelen, sizeof(char *))) == NULL)
 		err(1, NULL);
 
 	/*
@@ -438,7 +438,7 @@ prerun(int argc, char *argv[])
 	 * Allocate memory to hold the argument list, and
 	 * a NULL at the tail.
 	 */
-	tmp = calloc(argc + 1, sizeof(char**));
+	tmp = calloc(argc + 1, sizeof(char *));
 	if (tmp == NULL)
 		err(1, NULL);
 	tmp2 = tmp;


Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Sure thing, here an updated diff. Regards.

On 18 July 2017 at 16:22, Ted Unangst <t...@tedunangst.com> wrote:

> David CARLIER wrote:
> > Hi.
> >
> > I sent a diff originally to a smaller audience but finally decided to
> post
> > it in the mailing list.
> > So it is to introduce the pthread_set_name_np's counterpart so
> > pthread_get_name_np.
> > Some softwares use it (NSPR for example) and anyway internally in my
> > workplace we have multiplatform needing this feature would be nice having
> > this for OpenBSD as well :-)
> >
> > Let me know what you think.
>
> this is fine, it makes sense to have a get function if there's a set
> function. you can combine the man pages, however. no need for two. just
> add a
> sentence to the existing one.
>
Index: lib/libpthread/include/pthread_np.h
===
RCS file: /cvs/src/lib/libpthread/include/pthread_np.h,v
retrieving revision 1.11
diff -u -p -r1.11 pthread_np.h
--- lib/libpthread/include/pthread_np.h 22 Mar 2012 17:21:36 -  1.11
+++ lib/libpthread/include/pthread_np.h 18 Jul 2017 20:50:26 -
@@ -46,6 +46,7 @@ __BEGIN_DECLS
 int pthread_mutexattr_getkind_np(pthread_mutexattr_t);
 int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int);
 void pthread_set_name_np(pthread_t, const char *);
+void pthread_get_name_np(pthread_t, char *, size_t);
 int pthread_stackseg_np(pthread_t, stack_t *);
 int pthread_main_np(void);
 __END_DECLS
Index: lib/libpthread/man/pthread_set_name_np.3
===
RCS file: /cvs/src/lib/libpthread/man/pthread_set_name_np.3,v
retrieving revision 1.6
diff -u -p -r1.6 pthread_set_name_np.3
--- lib/libpthread/man/pthread_set_name_np.36 Mar 2014 17:42:25 -   
1.6
+++ lib/libpthread/man/pthread_set_name_np.318 Jul 2017 20:50:26 -
@@ -11,6 +11,8 @@
 .In pthread_np.h
 .Ft void
 .Fn pthread_set_name_np "pthread_t thread" "const char *name"
+.Ft void
+.Fn pthread_get_name_np "pthread_t thread" "char *name" "size_t len"
 .Sh DESCRIPTION
 The
 .Fn pthread_set_name_np
@@ -26,6 +28,11 @@ signal.
 The string pointed to by
 .Fa name
 is copied, and so need not be valid for the life of the thread.
+.Fn pthread_get_name_np
+function retrieves
+.Fa name
+associated with
+.Fa thread .
 .Sh SEE ALSO
 .Xr pthreads 3
 .Sh STANDARDS
Index: lib/libpthread/man/pthreads.3
===
RCS file: /cvs/src/lib/libpthread/man/pthreads.3,v
retrieving revision 1.41
diff -u -p -r1.41 pthreads.3
--- lib/libpthread/man/pthreads.3   16 Jul 2013 15:21:11 -  1.41
+++ lib/libpthread/man/pthreads.3   18 Jul 2017 20:50:26 -
@@ -169,6 +169,8 @@ The functions available are as follows:
 Identify the main thread.
 .It Fn pthread_set_name_np
 Set the name of a thread.
+.It Fn pthread_get_name_np
+Get the name of a thread
 .It Fn pthread_stackseg_np
 Return stack size and location.
 .It Fn pthread_yield
@@ -421,6 +423,7 @@ with larger numbers generating more verb
 .Xr pthread_detach 3 ,
 .Xr pthread_equal 3 ,
 .Xr pthread_exit 3 ,
+.Xr pthread_get_name_np 3 ,
 .Xr pthread_getcpuclockid 3 ,
 .Xr pthread_getspecific 3 ,
 .Xr pthread_join 3 ,
Index: lib/librthread/Symbols.map
===
RCS file: /cvs/src/lib/librthread/Symbols.map,v
retrieving revision 1.3
diff -u -p -r1.3 Symbols.map
--- lib/librthread/Symbols.map  27 Feb 2017 07:15:22 -  1.3
+++ lib/librthread/Symbols.map  18 Jul 2017 20:50:26 -
@@ -54,6 +54,7 @@
pthread_detach;
pthread_equal;
pthread_exit;
+   pthread_get_name_np;
pthread_getconcurrency;
pthread_getcpuclockid;
pthread_getprio;
Index: lib/librthread/pthread_np.h
===
RCS file: /cvs/src/lib/librthread/pthread_np.h,v
retrieving revision 1.1
diff -u -p -r1.1 pthread_np.h
--- lib/librthread/pthread_np.h 2 Apr 2016 19:56:53 -   1.1
+++ lib/librthread/pthread_np.h 18 Jul 2017 20:50:26 -
@@ -24,6 +24,7 @@ PROTO_DEPRECATED(pthread_main_np);
 PROTO_DEPRECATED(pthread_mutexattr_getkind_np);
 PROTO_DEPRECATED(pthread_mutexattr_setkind_np);
 PROTO_DEPRECATED(pthread_set_name_np);
+PROTO_DEPRECATED(pthread_get_name_np);
 PROTO_DEPRECATED(pthread_stackseg_np);
 
 #endif /* !_LIBPTHREAD_PTHREAD_NP_H_ */
Index: lib/librthread/rthread_np.c
===
RCS file: /cvs/src/lib/librthread/rthread_np.c,v
retrieving revision 1.19
diff -u -p -r1.19 rthread_np.c
--- lib/librthread/rthread_np.c 7 May 2016 19:05:22 -   1.19
+++ lib/librthread/rthread_np.c 18 Jul 2017 20:50:26 -
@@ -43,6 +43,20 @@ pthread_set_na

Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Yes that s true NetBSD having a variadic like argument as well ... etc ...
I did not have high expectations just wanted to propose ... :-)

On 18 July 2017 at 14:55, Landry Breuil <lan...@openbsd.org> wrote:

> On Tue, Jul 18, 2017 at 01:43:42PM +0100, David CARLIER wrote:
> > Ah I recognise you you re Mozilla contributor right ? You re probably
> right
> > but that was just an example eventhough I admit it s not extremely widely
> > used ...
>
> Note that you'll have to be careful in your arguments for this function:
>
> - _np prefix is for 'nonportable' so nothing standardises it
> - some oses have getname_np, freebsd has get_name_np
> - linux and netbsd share the function name but not the prototype for
>   setname_mp ?
> - macos enforces the running thread to set its own name
>
> (cf https://stackoverflow.com/a/7989973)
>
> so this looks like a shitshow, and a pretty good reason for not
> having it :)
>
>


Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Oups mistake of mine. good catch

On 18 July 2017 at 14:08, Karel Gardas <gard...@gmail.com> wrote:

> Why your patch defines MALLOC_STATS?
>
> -/* #define MALLOC_STATS */
> +#define MALLOC_STATS
>
> On Tue, Jul 18, 2017 at 2:43 PM, David CARLIER <devne...@gmail.com> wrote:
> > Ah I recognise you you re Mozilla contributor right ? You re probably
> right
> > but that was just an example eventhough I admit it s not extremely widely
> > used ...
> >
> > On 18 July 2017 at 13:36, Landry Breuil <lan...@openbsd.org> wrote:
> >
> >> On Tue, Jul 18, 2017 at 01:24:21PM +0100, David CARLIER wrote:
> >> > Hi.
> >> >
> >> > I sent a diff originally to a smaller audience but finally decided to
> >> post
> >> > it in the mailing list.
> >> > So it is to introduce the pthread_set_name_np's counterpart so
> >> > pthread_get_name_np.
> >> > Some softwares use it (NSPR for example) and anyway internally in my
> >> > workplace we have multiplatform needing this feature would be nice
> having
> >> > this for OpenBSD as well :-)
> >>
> >> the js engine uses it:
> >> https://bugzilla.mozilla.org/show_bug.cgi?id=1298451
> >>
> >> but nspr stopped using it or never used it, there's only a reference to
> >> pthread_set_name_np:
> >> https://hg.mozilla.org/projects/nspr/file/tip/pr/src/
> >> pthreads/ptthread.c#l1759
> >>
> >> PR_GetThreadName (just below) returns the 'local' name value, and doesnt
> >> get it from the system.
> >>
> >> Landry
> >>
> >>
>


Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Ah I recognise you you re Mozilla contributor right ? You re probably right
but that was just an example eventhough I admit it s not extremely widely
used ...

On 18 July 2017 at 13:36, Landry Breuil <lan...@openbsd.org> wrote:

> On Tue, Jul 18, 2017 at 01:24:21PM +0100, David CARLIER wrote:
> > Hi.
> >
> > I sent a diff originally to a smaller audience but finally decided to
> post
> > it in the mailing list.
> > So it is to introduce the pthread_set_name_np's counterpart so
> > pthread_get_name_np.
> > Some softwares use it (NSPR for example) and anyway internally in my
> > workplace we have multiplatform needing this feature would be nice having
> > this for OpenBSD as well :-)
>
> the js engine uses it:
> https://bugzilla.mozilla.org/show_bug.cgi?id=1298451
>
> but nspr stopped using it or never used it, there's only a reference to
> pthread_set_name_np:
> https://hg.mozilla.org/projects/nspr/file/tip/pr/src/
> pthreads/ptthread.c#l1759
>
> PR_GetThreadName (just below) returns the 'local' name value, and doesnt
> get it from the system.
>
> Landry
>
>


introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Hi.

I sent a diff originally to a smaller audience but finally decided to post
it in the mailing list.
So it is to introduce the pthread_set_name_np's counterpart so
pthread_get_name_np.
Some softwares use it (NSPR for example) and anyway internally in my
workplace we have multiplatform needing this feature would be nice having
this for OpenBSD as well :-)

Let me know what you think.

Kind regards.
Index: lib/libc/stdlib/malloc.c
===
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.228
diff -u -p -r1.228 malloc.c
--- lib/libc/stdlib/malloc.c10 Jul 2017 09:44:16 -  1.228
+++ lib/libc/stdlib/malloc.c15 Jul 2017 19:54:00 -
@@ -23,7 +23,7 @@
  * can buy me a beer in return. Poul-Henning Kamp
  */
 
-/* #define MALLOC_STATS */
+#define MALLOC_STATS
 
 #include 
 #include  /* PAGE_SHIFT ALIGN */
Index: lib/libpthread/include/pthread_np.h
===
RCS file: /cvs/src/lib/libpthread/include/pthread_np.h,v
retrieving revision 1.11
diff -u -p -r1.11 pthread_np.h
--- lib/libpthread/include/pthread_np.h 22 Mar 2012 17:21:36 -  1.11
+++ lib/libpthread/include/pthread_np.h 15 Jul 2017 19:54:00 -
@@ -46,6 +46,7 @@ __BEGIN_DECLS
 int pthread_mutexattr_getkind_np(pthread_mutexattr_t);
 int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int);
 void pthread_set_name_np(pthread_t, const char *);
+void pthread_get_name_np(pthread_t, char *, size_t);
 int pthread_stackseg_np(pthread_t, stack_t *);
 int pthread_main_np(void);
 __END_DECLS
Index: lib/libpthread/man/Makefile.inc
===
RCS file: /cvs/src/lib/libpthread/man/Makefile.inc,v
retrieving revision 1.36
diff -u -p -r1.36 Makefile.inc
--- lib/libpthread/man/Makefile.inc 30 Mar 2016 06:38:42 -  1.36
+++ lib/libpthread/man/Makefile.inc 15 Jul 2017 19:54:00 -
@@ -31,6 +31,7 @@ MAN+= \
pthread_detach.3 \
pthread_equal.3 \
pthread_exit.3 \
+   pthread_get_name_np.3 \
pthread_getconcurrency.3 \
pthread_getcpuclockid.3 \
pthread_getspecific.3 \
Index: lib/libpthread/man/pthread_get_name_np.3
===
RCS file: lib/libpthread/man/pthread_get_name_np.3
diff -N lib/libpthread/man/pthread_get_name_np.3
--- /dev/null   1 Jan 1970 00:00:00 -
+++ lib/libpthread/man/pthread_get_name_np.315 Jul 2017 19:54:00 -
@@ -0,0 +1,29 @@
+.Dd $Mdocdate: July 15 2017 $
+.Dt PTHREAD_GET_NAME_NP 3
+.Os
+.Sh NAME
+.Nm pthread_get_name_np
+.Nd get the name of a thread
+.Sh SYNOPSIS
+.In pthread.h
+.In pthread_np.h
+.Ft void
+.Fn pthread_get_name_np "pthread_t thread" "char *name" "size_t len"
+.Sh DESCRIPTION
+The
+.Fn pthread_get_name_np
+function retrieves
+.Fa name associated
+with
+.Fa thread .
+.Pp
+If pthread_set_name_np was not called for this
+.Fa thread
+the name parameter will be empty.
+.Sh SEE ALSO
+.Xr pthreads 3
+.Sh STANDARDS
+The
+.Fn pthread_get_name_np
+function is non-portable and may not be supported with the above
+semantics on other POSIX systems.
Index: lib/libpthread/man/pthreads.3
===
RCS file: /cvs/src/lib/libpthread/man/pthreads.3,v
retrieving revision 1.41
diff -u -p -r1.41 pthreads.3
--- lib/libpthread/man/pthreads.3   16 Jul 2013 15:21:11 -  1.41
+++ lib/libpthread/man/pthreads.3   15 Jul 2017 19:54:00 -
@@ -169,6 +169,8 @@ The functions available are as follows:
 Identify the main thread.
 .It Fn pthread_set_name_np
 Set the name of a thread.
+.It Fn pthread_get_name_np
+Get the name of a thread
 .It Fn pthread_stackseg_np
 Return stack size and location.
 .It Fn pthread_yield
@@ -421,6 +423,7 @@ with larger numbers generating more verb
 .Xr pthread_detach 3 ,
 .Xr pthread_equal 3 ,
 .Xr pthread_exit 3 ,
+.Xr pthread_get_name_np 3 ,
 .Xr pthread_getcpuclockid 3 ,
 .Xr pthread_getspecific 3 ,
 .Xr pthread_join 3 ,
Index: lib/librthread/Symbols.map
===
RCS file: /cvs/src/lib/librthread/Symbols.map,v
retrieving revision 1.3
diff -u -p -r1.3 Symbols.map
--- lib/librthread/Symbols.map  27 Feb 2017 07:15:22 -  1.3
+++ lib/librthread/Symbols.map  15 Jul 2017 19:54:00 -
@@ -54,6 +54,7 @@
pthread_detach;
pthread_equal;
pthread_exit;
+   pthread_get_name_np;
pthread_getconcurrency;
pthread_getcpuclockid;
pthread_getprio;
Index: lib/librthread/pthread_np.h
===
RCS file: /cvs/src/lib/librthread/pthread_np.h,v
retrieving revision 1.1
diff -u -p -r1.1 pthread_np.h
--- lib/librthread/pthread_np.h 2 Apr 2016 19:56:53 -   1.1
+++ lib/librthread/pthread_np.h 15 Jul 2017 19:54:00 

Re: Possible typo

2016-06-15 Thread David CARLIER
Ah ok I may have a not too updated mirror then I updated locally like 1h
ago. Thanks !

On 15 June 2016 at 17:28, Todd C. Miller <todd.mil...@courtesan.com> wrote:

> On Wed, 15 Jun 2016 17:26:46 +0100, David CARLIER wrote:
>
> > maybe someone already mentioned it, but I tried to compile the kernel
> today
> > and
> > in sys/netinet/udp_usrreq.c, line 937 might contain an extra parenthesis
> > after the first condition
> >
> > ie
> >
> > if ((inp->inp_flags & INP_IPSECFLOWINFO) != 0
> >
> > *)*
> > Hope it s useful.
>
> This was fixed recently by:
>
> CVSROOT:/cvs
> Module name:src
> Changes by: vgr...@cvs.openbsd.org  2016/06/15 10:06:35
>
> Modified files:
> sys/netinet: udp_usrreq.c
>
> Log message:
> Fix typo from rebase : extra parenthese
>


Possible typo

2016-06-15 Thread David CARLIER
Hi all,

maybe someone already mentioned it, but I tried to compile the kernel today
and
in sys/netinet/udp_usrreq.c, line 937 might contain an extra parenthesis
after the first condition

ie

if ((inp->inp_flags & INP_IPSECFLOWINFO) != 0

*)*
Hope it s useful.

Regards.


[patch] installboot

2016-03-26 Thread David CARLIER
Hi,

Here a little diff to fix small memory leaks inside installboot. Hope it
finds its way.

Kind regards.
Index: i386_installboot.c
===
RCS file: /cvs/src/usr.sbin/installboot/i386_installboot.c,v
retrieving revision 1.26
diff -u -p -r1.26 i386_installboot.c
--- i386_installboot.c  28 Dec 2015 23:00:29 -  1.26
+++ i386_installboot.c  24 Mar 2016 17:15:53 -
@@ -794,6 +794,8 @@ getbootparams(char *boot, int devfd, str
(unsigned int)char *)ap) - buf) + INODEOFF));
}
 
+   free(buf);
+
return 0;
 }
 
Index: i386_softraid.c
===
RCS file: /cvs/src/usr.sbin/installboot/i386_softraid.c,v
retrieving revision 1.9
diff -u -p -r1.9 i386_softraid.c
--- i386_softraid.c 1 Dec 2015 06:39:52 -   1.9
+++ i386_softraid.c 24 Mar 2016 17:15:53 -
@@ -194,5 +194,7 @@ sr_install_bootldr(int devfd, char *dev)
fprintf(stderr, "%s is %d blocks x %d bytes\n",
stage2, nblocks, bsize);
 
+   free(p);
+
close(fd);
 }


Little patch

2016-01-26 Thread David CARLIER
Hi all,

I just had a short chat with otto and would like to know if this little
patch would be considered. The reasoning is while debugging a program I got
a segmentation fault inside the loop as pool was NULL probably due to the
fact that malloc_init was not called first.

Thanks in advance.

Kind regards.

Index: malloc.c
===
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.176
diff -u -p -r1.176 malloc.c
--- malloc.c13 Sep 2015 20:29:23 -  1.176
+++ malloc.c26 Jan 2016 14:35:10 -
@@ -1844,6 +1844,8 @@ malloc_dump(int fd)
struct region_info *r;
int saved_errno = errno;

+   if (pool == NULL)
+   return;
for (i = 0; i < MALLOC_DELAYED_CHUNK_MASK + 1; i++) {
p = pool->delayed_chunks[i];
if (p == NULL)


Re: Little patch

2016-01-26 Thread David CARLIER
Nevermind otto yook care of it already :)

On 26 January 2016 at 15:39, David CARLIER <devne...@gmail.com> wrote:

> Hi all,
>
> I just had a short chat with otto and would like to know if this little
> patch would be considered. The reasoning is while debugging a program I got
> a segmentation fault inside the loop as pool was NULL probably due to the
> fact that malloc_init was not called first.
>
> Thanks in advance.
>
> Kind regards.
>
> Index: malloc.c
> ===
> RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
> retrieving revision 1.176
> diff -u -p -r1.176 malloc.c
> --- malloc.c13 Sep 2015 20:29:23 -  1.176
> +++ malloc.c26 Jan 2016 14:35:10 -
> @@ -1844,6 +1844,8 @@ malloc_dump(int fd)
> struct region_info *r;
> int saved_errno = errno;
>
> +   if (pool == NULL)
> +   return;
> for (i = 0; i < MALLOC_DELAYED_CHUNK_MASK + 1; i++) {
> p = pool->delayed_chunks[i];
> if (p == NULL)
>
>
>


Re: MALLOC_STATS and pledge

2015-11-14 Thread David CARLIER
Might be indeed, there are other use cases with valgrind and protexec
and so on ..., utrace might be a good suggestion too except maybe a
need for an exception in pledge's side then.

On 13 November 2015 at 18:34, Ted Unangst <t...@tedunangst.com> wrote:
> David CARLIER wrote:
>> Hi all,
>>
>> I ve tried to discuss this point with Otto Moerbeek but he might be
>> very busy so I throw the topic here if you do not mind ...
>>
>> I have the habit to enable MALLOC_STATS but with the recent pledge
>> feature, it s now difficult to debug some pledged applications with
>> MALLOC_OPTIONS=D as, for malloc_dump, wpath and rpath are needed ...
>> and it is fore sure not wishable to enable those in those userland
>> apps.
>>
>> Is there a way, somehow, to succeed ? For the moment I ve slighty
>> modified malloc_dump to only write on stderr and then I redirect the
>> output myself.
>
> I would say the simplest is to disable the pledge() call in the program while
> debugging.



MALLOC_STATS and pledge

2015-11-13 Thread David CARLIER
Hi all,

I ve tried to discuss this point with Otto Moerbeek but he might be
very busy so I throw the topic here if you do not mind ...

I have the habit to enable MALLOC_STATS but with the recent pledge
feature, it s now difficult to debug some pledged applications with
MALLOC_OPTIONS=D as, for malloc_dump, wpath and rpath are needed ...
and it is fore sure not wishable to enable those in those userland
apps.

Is there a way, somehow, to succeed ? For the moment I ve slighty
modified malloc_dump to only write on stderr and then I redirect the
output myself.

Thanks in advance.

Kind regards.



small memory leaks in localtime

2015-09-07 Thread David CARLIER
Hi all,

Both internal state variables, lclptr and gmtptr are allocated once but
never freed so I was wondering if this little diff which avoids the
unnecessary dynamic allocations would have any use ?

Thanks in advance.

Regards.
Index: localtime.c
===
RCS file: /cvs/src/lib/libc/time/localtime.c,v
retrieving revision 1.52
diff -u -p -r1.52 localtime.c
--- localtime.c 7 Apr 2015 01:47:04 -   1.52
+++ localtime.c 7 Sep 2015 19:58:34 -
@@ -168,8 +168,10 @@ static int tzload(const char * name, st
 static int tzparse(const char * name, struct state * sp,
int lastditch);
 
-static struct state *  lclptr;
-static struct state *  gmtptr;
+static struct state   lclmem;
+static struct state   gmtmem;
+static struct state *  lclptr = 
+static struct state *  gmtptr = 
 
 
 #ifndef TZ_STRLEN_MAX
@@ -1093,13 +1095,6 @@ tzsetwall_basic(void)
return;
lcl_is_set = -1;
 
-   if (lclptr == NULL) {
-   lclptr = calloc(1, sizeof *lclptr);
-   if (lclptr == NULL) {
-   settzname();/* all we can do */
-   return;
-   }
-   }
if (tzload(NULL, lclptr, TRUE) != 0)
gmtload(lclptr);
settzname();
@@ -1137,13 +1132,6 @@ tzset_basic(void)
if (lcl_is_set)
strlcpy(lcl_TZname, name, sizeof lcl_TZname);
 
-   if (lclptr == NULL) {
-   lclptr = calloc(1, sizeof *lclptr);
-   if (lclptr == NULL) {
-   settzname();/* all we can do */
-   return;
-   }
-   }
if (*name == '\0') {
/*
** User wants it fast rather than right.
@@ -1309,9 +1297,7 @@ gmtsub(const time_t *timep, long offset,
_THREAD_PRIVATE_MUTEX_LOCK(gmt);
if (!gmt_is_set) {
gmt_is_set = TRUE;
-   gmtptr = (struct state *) calloc(1, sizeof *gmtptr);
-   if (gmtptr != NULL)
-   gmtload(gmtptr);
+   gmtload(gmtptr);
}
_THREAD_PRIVATE_MUTEX_UNLOCK(gmt);
result = timesub(timep, offset, gmtptr, tmp);
@@ -1323,12 +1309,8 @@ gmtsub(const time_t *timep, long offset,
*/
if (offset != 0)
tmp->TM_ZONE = wildabbr;
-   else {
-   if (gmtptr == NULL)
-   tmp->TM_ZONE = (char *)gmt;
-   else
-   tmp->TM_ZONE = gmtptr->chars;
-   }
+   else 
+   tmp->TM_ZONE = gmtptr->chars;
 #endif /* defined TM_ZONE */
return result;
 }


small ed diff

2015-04-29 Thread David CARLIER
Hello everybody.

There it is a tiny diff about ed ...

1/ using a long long (for 32 bits case) for strtol.
2/ realloc = reallocarray

Hope it has any use

Kind regards.
Index: ed.h
===
RCS file: /cvs/src/bin/ed/ed.h,v
retrieving revision 1.15
diff -u -p -r1.15 ed.h
--- ed.h16 Jan 2015 06:39:32 -  1.15
+++ ed.h29 Apr 2015 22:22:22 -
@@ -105,22 +105,26 @@ if (--mutex == 0) { \
 
 /* STRTOI: convert a string to int */
 #define STRTOI(i, p) { \
-   long l = strtol(p, p, 10); \
-   if (l = INT_MIN || l = INT_MAX) { \
-   seterrmsg(number out of range); \
-   i = 0; \
-   return ERR; \
-   } else \
-   i = (int)l; \
+  long long l = strtol(p, p, 10); \
+  if (l = INT_MIN || l = INT_MAX) { \
+ seterrmsg(number out of range); \
+ i = 0; \
+ return ERR; \
+  } else \
+ i = (int)l; \
 }
 
 /* REALLOC: assure at least a minimum size for buffer b */
 #define REALLOC(b,n,i,err) \
 if ((i)  (n)) { \
-   int ti = (n); \
+   size_t ti = (n) + max((i), MINBUFSZ); \
char *ts; \
SPL1(); \
-   if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
+   if ((ts = reallocarray((b), ti, sizeof(char))) == NULL) { \
+  if ((b)) { \
+  free((b)); \
+  ((b)) = 0; \
+  } \
perror(NULL); \
seterrmsg(out of memory); \
SPL0(); \


tiny tetris patch

2015-03-15 Thread David CARLIER
Hi all,

As tetris is one of my preferred game :-) ... just did wrapper around
setegid in same manner than xmalloc and such. If it can find any use ...

Thanks.
Index: scores.c
===
RCS file: /cvs/src/games/tetris/scores.c,v
retrieving revision 1.12
diff -u -p -r1.12 scores.c
--- scores.c16 Nov 2014 04:49:49 -  1.12
+++ scores.c15 Mar 2015 09:08:46 -
@@ -111,11 +111,11 @@ getscores(FILE **fpp)
human = reading;
lck = LOCK_SH;
}
-   setegid(egid);
+   xsetegid(egid);
mask = umask(S_IWOTH);
sd = open(_PATH_SCOREFILE, mint, 0666);
(void)umask(mask);
-   setegid(gid);
+   xsetegid(gid);
if (sd  0) {
if (fpp == NULL) {
nscores = 0;
@@ -123,10 +123,10 @@ getscores(FILE **fpp)
}
err(1, cannot open %s for %s, _PATH_SCOREFILE, human);
}
-   setegid(egid);
+   xsetegid(egid);
if ((sf = fdopen(sd, mstr)) == NULL)
err(1, cannot fdopen %s for %s, _PATH_SCOREFILE, human);
-   setegid(gid);
+   xsetegid(gid);
 
/*
 * Grab a lock.
Index: tetris.c
===
RCS file: /cvs/src/games/tetris/tetris.c,v
retrieving revision 1.25
diff -u -p -r1.25 tetris.c
--- tetris.c16 Nov 2014 04:49:49 -  1.25
+++ tetris.c15 Mar 2015 09:08:46 -
@@ -161,7 +161,7 @@ main(int argc, char *argv[])
 
gid = getgid();
egid = getegid();
-   setegid(gid);
+   xsetegid(gid);
 
classic = showpreview = 0;
while ((ch = getopt(argc, argv, ck:l:ps)) != -1)
@@ -363,4 +363,11 @@ usage(void)
 {
(void)fprintf(stderr, usage: tetris [-cps] [-k keys] [-l level]\n);
exit(1);
+}
+
+void
+xsetegid(gid_t gid)
+{
+if (setegid(gid) == -1)
+err(1, setegid() failed);
 }
Index: tetris.h
===
RCS file: /cvs/src/games/tetris/tetris.h,v
retrieving revision 1.10
diff -u -p -r1.10 tetris.h
--- tetris.h10 Aug 2008 12:23:25 -  1.10
+++ tetris.h15 Mar 2015 09:08:46 -
@@ -176,3 +176,4 @@ extern int  classic;
 intfits_in(const struct shape *, int);
 void   place(const struct shape *, int, int);
 void   stop(char *);
+void   xsetegid(gid_t);


[no subject]

2015-01-02 Thread David Carlier
Hi again after discussins with Helg, second change is not relevant, so only
the first should remains.

Kind regards.

Index: fuse.c
===
RCS file: /cvs/src/lib/libfuse/fuse.c,v
retrieving revision 1.24
diff -u -p -r1.24 fuse.c
--- fuse.c 20 May 2014 13:32:22 - 1.24
+++ fuse.c 1 Jan 2015 13:17:02 -
@@ -493,5 +493,8 @@ fuse_main(int argc, char **argv, const s
  if (!fuse)
  return (-1);

+ if (mp)
+ free(mp);
+
  return (fuse_loop(fuse));
 }


Re: your mail

2015-01-02 Thread David Carlier
In OpenBSD we just write that as free(mp), the if isn't required.


Will remember it ;-)

Index: fuse.c
===
RCS file: /cvs/src/lib/libfuse/fuse.c,v
retrieving revision 1.24
diff -u -p -r1.24 fuse.c
--- fuse.c 20 May 2014 13:32:22 - 1.24
+++ fuse.c 2 Jan 2015 16:53:30 -
@@ -493,5 +493,7 @@ fuse_main(int argc, char **argv, const s
  if (!fuse)
  return (-1);

+ free(mp);
+
  return (fuse_loop(fuse));
 }





libfuse, potential memory leaks

2015-01-01 Thread David Carlier
Hello and happy new year.

So this is a quite a small diff which, hopefully, will make lib fuse
slightly better. Indeed, it might exist two small potential memory leaks,
first the memory allocated after parsing command line when it succeeds, the
other the very first option argument in the list. Hope it might finds some
interests.

Kind regards.

Index: fuse.c
===
RCS file: /cvs/src/lib/libfuse/fuse.c,v
retrieving revision 1.24
diff -u -p -r1.24 fuse.c
--- fuse.c 20 May 2014 13:32:22 - 1.24
+++ fuse.c 1 Jan 2015 13:17:02 -
@@ -493,5 +493,8 @@ fuse_main(int argc, char **argv, const s
  if (!fuse)
  return (-1);

+ if (mp)
+ free(mp);
+
  return (fuse_loop(fuse));
 }
Index: fuse_opt.c
===
RCS file: /cvs/src/lib/libfuse/fuse_opt.c,v
retrieving revision 1.11
diff -u -p -r1.11 fuse_opt.c
--- fuse_opt.c 8 Oct 2014 04:50:10 - 1.11
+++ fuse_opt.c 1 Jan 2015 13:17:02 -
@@ -331,7 +331,7 @@ int
 fuse_opt_insert_arg(struct fuse_args *args, int p, const char *name)
 {
  char **av;
- char *this_arg, *next_arg;
+ char *this_arg, *next_arg, *hold_arg;
  int i;

  if (name == NULL)
@@ -353,6 +353,8 @@ fuse_opt_insert_arg(struct fuse_args *ar
  return (-1);
  }

+ hold_arg = this_arg;
+
  args-argc++;
  args-argv = av;
  for (i = p; i  args-argc; i++) {
@@ -360,6 +362,8 @@ fuse_opt_insert_arg(struct fuse_args *ar
  args-argv[i] = this_arg;
  this_arg = next_arg;
  }
+
+ free(hold_arg);
  return (0);
 }


ato* = strto*

2014-12-09 Thread David Carlier
Hi all,

I made a small first diff to replace some ato* functions call to strtonum/l
ones ...
Althought not sure about the sudo one because it looks contrib code and
also might appear a bit overengineered ... but in case !

Thanks in advance.

Index: bin/ps/ps.c
===
RCS file: /cvs/src/bin/ps/ps.c,v
retrieving revision 1.62
diff -u -p -r1.62 ps.c
--- bin/ps/ps.c8 Jul 2014 23:31:22 -1.62
+++ bin/ps/ps.c9 Dec 2014 13:34:44 -
@@ -97,6 +97,7 @@ main(int argc, char *argv[])
 uid_t uid;
 int all, ch, flag, i, fmt, lineno, nentries;
 int prtheader, showthreads, wflag, kflag, what, Uflag, xflg;
+const char *errstr;
 char *nlistf, *memf, *swapf, *cols, errbuf[_POSIX2_LINE_MAX];

 if ((cols = getenv(COLUMNS)) != NULL  *cols != '\0') {
@@ -188,7 +189,9 @@ main(int argc, char *argv[])
 fmt = 1;
 break;
 case 'p':
-pid = atol(optarg);
+pid = (pid_t)strtonum(optarg, -1, (SHRT_MAX - 1), errstr);
+if (errstr)
+errx(1, pid: %s, errstr);
 xflg = 1;
 break;
 case 'r':
Index: bin/systrace/systrace.c
===
RCS file: /cvs/src/bin/systrace/systrace.c,v
retrieving revision 1.61
diff -u -p -r1.61 systrace.c
--- bin/systrace/systrace.c26 Nov 2014 18:34:51 -1.61
+++ bin/systrace/systrace.c9 Dec 2014 13:34:44 -
@@ -644,6 +644,7 @@ int
 main(int argc, char **argv)
 {
 int i, c;
+const char *errstr;
 char **args;
 char *filename = NULL;
 char *policypath = NULL;
@@ -707,8 +708,9 @@ main(int argc, char **argv)
 case 'p':
 if (setcredentials)
 usage();
-if ((pidattach = atoi(optarg)) == 0) {
-warnx(bad pid: %s, optarg);
+pidattach = strtonum(optarg, 1, (SHRT_MAX - 1), errstr);
+if (errstr) {
+warnx(bad pid: %s (%s), optarg, errstr);
 usage();
 }
 break;
Index: usr.bin/sudo/sudo.c
===
RCS file: /cvs/src/usr.bin/sudo/sudo.c,v
retrieving revision 1.48
diff -u -p -r1.48 sudo.c
--- usr.bin/sudo/sudo.c7 Dec 2013 14:53:29 -1.48
+++ usr.bin/sudo/sudo.c9 Dec 2014 13:35:03 -
@@ -37,6 +37,9 @@
 # include sys/time.h
 # include sys/resource.h
 #endif
+#ifdef BSD
+# include sys/sysctl.h
+#endif
 #include stdio.h
 #ifdef STDC_HEADERS
 # include stdlib.h
@@ -853,6 +856,10 @@ parse_args(argc, argv)
 int argc;
 char **argv;
 {
+#ifdef BSD
+const char *errstr;
+size_t maxfiles, maxfileslen;
+#endif
 int mode = 0;/* what mode is sudo to be run in? */
 int flags = 0;/* mode flags */
 int valid_flags, ch;
@@ -861,6 +868,12 @@ parse_args(argc, argv)
 if (strcmp(getprogname(), sudoedit) == 0)
 mode = MODE_EDIT;

+#ifdef BSD
+if (sysctl(kern.maxfiles, strlen(kern.maxfiles), NULL, NULL,
+maxfiles, maxfileslen) == -1)
+errorx(1, kern.maxfiles failed);
+#endif
+
 /* Returns true if the last option string was -- */
 #define got_end_of_args(optind  1  argv[optind - 1][0] == '-'  \
 argv[optind - 1][1] == '-'  argv[optind - 1][2] == '\0')
@@ -893,8 +906,14 @@ parse_args(argc, argv)
 SET(flags, MODE_BACKGROUND);
 break;
 case 'C':
+#ifdef BSD
+user_closefrom = (int)strtonum(optarg, 3, maxfiles, errstr);
+if (errstr) {
+warningx(the argument to -C is invalid: %s, errstr);
+#else
 if ((user_closefrom = atoi(optarg))  3) {
 warningx(the argument to -C must be at least 3);
+#endif
 usage(1);
 }
 break;
Index: usr.bin/vmstat/vmstat.c
===
RCS file: /cvs/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.134
diff -u -p -r1.134 vmstat.c
--- usr.bin/vmstat/vmstat.c23 Nov 2014 04:34:48 -1.134
+++ usr.bin/vmstat/vmstat.c9 Dec 2014 13:35:03 -
@@ -129,6 +129,7 @@ int
 main(int argc, char *argv[])
 {
 char errbuf[_POSIX2_LINE_MAX];
+char *preps;
 int c, todo = 0, reps = 0;
 const char *errstr;
 u_int interval = 0;
@@ -136,7 +137,9 @@ main(int argc, char *argv[])
 while ((c = getopt(argc, argv, c:fiM:mN:stw:vz)) != -1) {
 switch (c) {
 case 'c':
-reps = atoi(optarg);
+reps = (int)strtol(optarg, preps, 10);
+if (*preps != '\0' || errno != 0)
+errx(1, -c %s: invalid argument, optarg);
 break;
 case 'f':
 todo |= FORKSTAT;
@@ -224,8 +227,11 @@ main(int argc, char *argv[])
 if (errstr)
 errx(1, %s: %s, *argv, errstr);

-if (*++argv)
-reps = atoi(*argv);
+if (*++argv) {
+   

Re: ato* = strto*

2014-12-09 Thread David Carlier
Slighty different version, so withdrawal of casts and strtol = strtonum.
I still maintain (SHRT_MAX - 1) as PID_MAX is not exposed to the userland
(@tedu mentioned he planned to increase it,
would it be good to expose it via, for example, sysctl which makes it also
settable ?)



Index: bin/ps/ps.c
===
RCS file: /cvs/src/bin/ps/ps.c,v
retrieving revision 1.62
diff -u -p -r1.62 ps.c
--- bin/ps/ps.c8 Jul 2014 23:31:22 -1.62
+++ bin/ps/ps.c9 Dec 2014 16:51:51 -
@@ -97,6 +97,7 @@ main(int argc, char *argv[])
 uid_t uid;
 int all, ch, flag, i, fmt, lineno, nentries;
 int prtheader, showthreads, wflag, kflag, what, Uflag, xflg;
+const char *errstr;
 char *nlistf, *memf, *swapf, *cols, errbuf[_POSIX2_LINE_MAX];

 if ((cols = getenv(COLUMNS)) != NULL  *cols != '\0') {
@@ -188,7 +189,9 @@ main(int argc, char *argv[])
 fmt = 1;
 break;
 case 'p':
-pid = atol(optarg);
+pid = strtonum(optarg, -1, (SHRT_MAX - 1), errstr);
+if (errstr)
+errx(1, pid: %s, errstr);
 xflg = 1;
 break;
 case 'r':
Index: bin/systrace/systrace.c
===
RCS file: /cvs/src/bin/systrace/systrace.c,v
retrieving revision 1.61
diff -u -p -r1.61 systrace.c
--- bin/systrace/systrace.c26 Nov 2014 18:34:51 -1.61
+++ bin/systrace/systrace.c9 Dec 2014 16:51:51 -
@@ -644,6 +644,7 @@ int
 main(int argc, char **argv)
 {
 int i, c;
+const char *errstr;
 char **args;
 char *filename = NULL;
 char *policypath = NULL;
@@ -707,8 +708,9 @@ main(int argc, char **argv)
 case 'p':
 if (setcredentials)
 usage();
-if ((pidattach = atoi(optarg)) == 0) {
-warnx(bad pid: %s, optarg);
+pidattach = strtonum(optarg, 1, (SHRT_MAX - 1), errstr);
+if (errstr) {
+warnx(bad pid: %s (%s), optarg, errstr);
 usage();
 }
 break;
Index: usr.bin/sudo/sudo.c
===
RCS file: /cvs/src/usr.bin/sudo/sudo.c,v
retrieving revision 1.48
diff -u -p -r1.48 sudo.c
--- usr.bin/sudo/sudo.c7 Dec 2013 14:53:29 -1.48
+++ usr.bin/sudo/sudo.c9 Dec 2014 16:52:09 -
@@ -37,6 +37,9 @@
 # include sys/time.h
 # include sys/resource.h
 #endif
+#ifdef BSD
+# include sys/sysctl.h
+#endif
 #include stdio.h
 #ifdef STDC_HEADERS
 # include stdlib.h
@@ -853,6 +856,10 @@ parse_args(argc, argv)
 int argc;
 char **argv;
 {
+#ifdef BSD
+const char *errstr;
+size_t maxfiles, maxfileslen;
+#endif
 int mode = 0;/* what mode is sudo to be run in? */
 int flags = 0;/* mode flags */
 int valid_flags, ch;
@@ -861,6 +868,12 @@ parse_args(argc, argv)
 if (strcmp(getprogname(), sudoedit) == 0)
 mode = MODE_EDIT;

+#ifdef BSD
+if (sysctl(kern.maxfiles, strlen(kern.maxfiles), NULL, NULL,
+maxfiles, maxfileslen) == -1)
+errorx(1, kern.maxfiles failed);
+#endif
+
 /* Returns true if the last option string was -- */
 #define got_end_of_args(optind  1  argv[optind - 1][0] == '-'  \
 argv[optind - 1][1] == '-'  argv[optind - 1][2] == '\0')
@@ -893,8 +906,14 @@ parse_args(argc, argv)
 SET(flags, MODE_BACKGROUND);
 break;
 case 'C':
+#ifdef BSD
+user_closefrom = strtonum(optarg, 3, maxfiles, errstr);
+if (errstr) {
+warningx(the argument to -C is invalid: %s, errstr);
+#else
 if ((user_closefrom = atoi(optarg))  3) {
 warningx(the argument to -C must be at least 3);
+#endif
 usage(1);
 }
 break;
Index: usr.bin/vmstat/vmstat.c
===
RCS file: /cvs/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.134
diff -u -p -r1.134 vmstat.c
--- usr.bin/vmstat/vmstat.c23 Nov 2014 04:34:48 -1.134
+++ usr.bin/vmstat/vmstat.c9 Dec 2014 16:52:10 -
@@ -136,7 +136,9 @@ main(int argc, char *argv[])
 while ((c = getopt(argc, argv, c:fiM:mN:stw:vz)) != -1) {
 switch (c) {
 case 'c':
-reps = atoi(optarg);
+reps = strtonum(optarg, 0, INT_MAX, errstr);
+if (errstr)
+errx(1, -c %s: %s, optarg, errstr);
 break;
 case 'f':
 todo |= FORKSTAT;
@@ -224,8 +226,11 @@ main(int argc, char *argv[])
 if (errstr)
 errx(1, %s: %s, *argv, errstr);

-if (*++argv)
-reps = atoi(*argv);
+if (*++argv) {
+reps = strtonum(*argv, 0, INT_MAX, errstr);
+if (errstr)
+errx(1, %s: %s, *argv, errstr);
+}
 }
 #endif

On 9 December 2014 at 13:38, David Carlier

Small diff ...

2014-12-08 Thread David Carlier
Following small discussion I had with tedu@ this is just small diff, just
for the sake of C standard correctness ... dropping some arithmetic
pointer with void pointers ...

Hopes it might find some interest/usefullness ...

Thanks in advance.


Index: gnu/gcc/gcc/unwind-dw2.c
===
RCS file: /cvs/src/gnu/gcc/gcc/unwind-dw2.c,v
retrieving revision 1.2
diff -u -p -r1.2 unwind-dw2.c
--- gnu/gcc/gcc/unwind-dw2.c7 May 2010 22:06:10 -1.2
+++ gnu/gcc/gcc/unwind-dw2.c8 Dec 2014 17:03:58 -
@@ -1528,9 +1528,9 @@ uw_install_context_1 (struct _Unwind_Con

   /* We adjust SP by the difference between CURRENT and TARGET's CFA.
*/
   if (STACK_GROWS_DOWNWARD)
-return target_cfa - current-cfa + target-args_size;
+return (unsigned char *)target_cfa - (unsigned char *)current-cfa +
target-args_size;
   else
-return current-cfa - target_cfa - target-args_size;
+return (unsigned char *)current-cfa - (unsigned char *)target_cfa -
target-args_size;
 }
   return 0;
 }
Index: lib/librthread/rthread_np.c
===
RCS file: /cvs/src/lib/librthread/rthread_np.c,v
retrieving revision 1.14
diff -u -p -r1.14 rthread_np.c
--- lib/librthread/rthread_np.c9 Aug 2014 03:29:35 -1.14
+++ lib/librthread/rthread_np.c8 Dec 2014 17:04:00 -
@@ -66,7 +66,7 @@ pthread_stackseg_np(pthread_t thread, st
 #ifdef MACHINE_STACK_GROWS_UP
 sinfo-ss_sp = thread-stack-base;
 #else
-sinfo-ss_sp = thread-stack-base + thread-stack-len;
+sinfo-ss_sp = (unsigned char *)thread-stack-base +
thread-stack-len;
 #endif
 sinfo-ss_size = thread-stack-len;
 if (thread-stack-guardsize != 1)
Index: libexec/ld.so/util.c
===
RCS file: /cvs/src/libexec/ld.so/util.c,v
retrieving revision 1.35
diff -u -p -r1.35 util.c
--- libexec/ld.so/util.c14 Jul 2014 03:54:50 -1.35
+++ libexec/ld.so/util.c8 Dec 2014 17:04:00 -
@@ -72,16 +72,17 @@ void
 _dl_randombuf(void *buf, size_t buflen)
 {
 size_t chunk;
+unsigned char *pbuf = buf;

 while (buflen != 0) {
 if (buflen  256)
 chunk = 256;
 else
 chunk = buflen;
-if (_dl_getentropy(buf, chunk) != 0)
+if (_dl_getentropy(pbuf, chunk) != 0)
 _dl_exit(8);
 buflen -= chunk;
-buf += chunk;
+pbuf += chunk;
 }
 }

Index: usr.sbin/nsd/difffile.c
===
RCS file: /cvs/src/usr.sbin/nsd/difffile.c,v
retrieving revision 1.1.1.15
diff -u -p -r1.1.1.15 difffile.c
--- usr.sbin/nsd/difffile.c16 Sep 2014 16:54:03 -1.1.1.15
+++ usr.sbin/nsd/difffile.c8 Dec 2014 17:04:01 -
@@ -716,10 +716,10 @@ delete_RR(namedb_type* db, const dname_t
 rrset-rr_count-1])
 zone-nsec3_param = rrset-rrs[rrnum];
 else
-zone-nsec3_param =
-(void*)zone-nsec3_param
--(void*)rrs_orig +
-(void*)rrset-rrs;
+zone-nsec3_param = (void*)(
+(char*)zone-nsec3_param
+-(char*)rrs_orig +
+(char*)rrset-rrs);
 }
 #endif /* NSEC3 */
 rrset-rr_count --;
@@ -817,8 +817,8 @@ add_RR(namedb_type* db, const dname_type
 assert(zone-nsec3_param = rrs_old 
 zone-nsec3_param  rrs_old+rrset-rr_count);
 /* in this order to make sure no overflow/underflow*/
-zone-nsec3_param = (void*)zone-nsec3_param -
-(void*)rrs_old + (void*)rrset-rrs;
+zone-nsec3_param = (void*)((char *)zone-nsec3_param -
+(char*)rrs_old + (char*)rrset-rrs);
 }
 #endif /* NSEC3 */
 }

Index: usr.sbin/nsd/udb.h
===
RCS file: /cvs/src/usr.sbin/nsd/udb.h,v
retrieving revision 1.1.1.3
diff -u -p -r1.1.1.3 udb.h
--- usr.sbin/nsd/udb.h16 Sep 2014 16:54:00 -1.1.1.3
+++ usr.sbin/nsd/udb.h8 Dec 2014 17:04:01 -
@@ -54,7 +54,7 @@ typedef uint64_t udb_void;
 /** convert relptr to usable pointer */
 #define UDB_REL(base, relptr) ((base) + (relptr))
 /** from system pointer to relative pointer */
-#define UDB_SYSTOREL(base, ptr) ((udb_void)((void*)(ptr) - (base)))
+#define UDB_SYSTOREL(base, ptr) ((udb_void)((ptr) - (base)))

 /** MAX 2**x exponent of alloced chunks, for 1Mbytes.  The smallest
  * chunk is 16bytes (8preamble+8data), so 0-3 is unused. */
Index: usr.sbin/nsd/xfrd-tcp.c
===
RCS file: /cvs/src/usr.sbin/nsd/xfrd-tcp.c,v
retrieving revision 1.9
diff -u -p -r1.9 xfrd-tcp.c
--- usr.sbin/nsd/xfrd-tcp.c16 Sep 2014 17:01:38 -1.9

Posix RealTime Extensions.

2014-11-16 Thread David Carlier
Hi all,

sorry I m far to be an OpenBSD expert but I was wondering why it lacks some
functions like sigqueue and such ... Is there any plan to add them in the
future and if not what is the reasoning behind it ?

Thanks in advance.


5.6 ... small detail

2014-11-04 Thread David Carlier
Hi all,

Just updated to 5.6 and was happy to see that gets(3) was removed for good
... althought it seems to be still available only in the man page.

Kind regards.


Re: 5.6 ... small detail

2014-11-04 Thread David Carlier
Thanks !

On 4 November 2014 19:00, Otto Moerbeek o...@drijf.net wrote:

 On Tue, Nov 04, 2014 at 01:49:32PM -0500, Ted Unangst wrote:

  On Tue, Nov 04, 2014 at 16:38, David Carlier wrote:
   Hi all,
  
   Just updated to 5.6 and was happy to see that gets(3) was removed for
 good
   ... althought it seems to be still available only in the man page.
 
  It's no longer part of the fgets man page, but if you have the old
  gets man page lying around, yes, it will still be there.

 The upgrade instruction http://www.openbsd.org/faq/upgrade56.html#RmFiles
 fail to mention this file should be removed. Not that it matters a lot.

 -Otto



Re: chmod.c undefined behavior

2014-09-24 Thread David Carlier
I mght be wrong, but why not just initialize to NULL?

On 24 September 2014 10:10, Matti Karnaattu mkarnaa...@gmail.com wrote:

 I noticed that chmod.c have uninitialized variable char *ep that was
 used. This diff clarify what I mean.


  Index: chmod.c
 ===
 RCS file: /OpenBSD/src/bin/chmod/chmod.c,v
 retrieving revision 1.30
 diff -u -p -u -p -r1.30 chmod.c
 --- chmod.c 21 May 2014 06:23:01 -  1.30
 +++ chmod.c 24 Sep 2014 08:47:58 -
 @@ -65,7 +65,7 @@ main(int argc, char *argv[])
 uid_t uid;
 gid_t gid;
 u_int32_t fclear, fset;
 -   char *ep, *mode, *cp, *flags;
 +   char *mode, *cp, *flags;
 setlocale(LC_ALL, );
 @@ -148,13 +148,11 @@ done:
 flags = *argv;
 if (*flags = '0'  *flags = '7') {
 errno = 0;
 -   val = strtoul(flags, ep, 8);
 +   val = strtoul(flags, (char *)NULL, 8);
 if (val  UINT_MAX)
 errno = ERANGE;
 if (errno)
 err(1, invalid flags: %s, flags);
 -   if (*ep)
 -   errx(1, invalid flags: %s, flags);
 fset = val;
 oct = 1;
 } else {
 @@ -167,13 +165,11 @@ done:
 mode = *argv;
 if (*mode = '0'  *mode = '7') {
 errno = 0;
 -   val = strtol(mode, ep, 8);
 +   val = strtol(mode, (char *)NULL, 8);
 if (val  INT_MAX || val  0)
 errno = ERANGE;
 if (errno)
 err(1, invalid file mode: %s, mode);
 -   if (*ep)
 -   errx(1, invalid file mode: %s, mode);
 omode = val;
 oct = 1;
 } else {




Re: chmod.c undefined behavior

2014-09-24 Thread David Carlier
You make the point indeed I had overreacted, just tried to participate :-)

I mght be wrong, but why not just initialize to NULL?

I am watching this thread to spot people who should never be OpenBSD
developers..

Eheh you re probably right.

On 24 September 2014 13:22, Ingo Schwarze schwa...@usta.de wrote:

 Hi David,

 David Carlier wrote on Wed, Sep 24, 2014 at 10:19:57AM +0100:
  On 24 September 2014 10:10, Matti Karnaattu mkarnaa...@gmail.com
 wrote:

  I noticed that chmod.c have uninitialized variable char *ep
  that was used.  This diff clarify what I mean.

  I might be wrong,

 You are.

  but why not just initialize to NULL?

 That is exactly how one must *not*, under any circumstances, ever
 react to the findings of an audit.  It is very important to not
 react in such a way.

 If an audit - no matter whether a manual audit (like here) or
 tool-driven static analysis - reveals a potential bug or vulnerability,
 *never* proceed to merely sweep it under the carpet without caring
 what the code actually does.  For example, if your auditing tool
 reports potential use of uninitialized variable, do *not* just
 add foo = NULL to the top of the function.  Look at what the
 function does and decide whether it makes the codes safer or more
 readable to initialize.

 Adding code to merely shut up an audit is harmful in more than one
 way.  First, it may hide an actually problem.  Second, it may create
 a new problem if you happen to pick the wrong value for initialization.
 Third, it might in somes cases shift a problem elsewehere where it
 might be more harmful or harder to detect.

 I think you have earned yourself a flame, but i'm sorry to say i'm
 not in the mood right now.  :-)


 In the case at hand, the code is obviously correct as it stands.
 Just search for ep from the top.  The first line you find is the
 declaration, the second line is the strtoul() explicitly initializing
 it.  Adding a second initialization before would be confusing.  Any
 future auditor would wonder what the point of that obviously useless
 statement is and would probably waste some time trying to figure
 out whether it hides some logic oversight of the author of the code,
 probably ending up *removing* the ep = NULL to improve clarity
 for future audits.

 Yours,
   Ingo


 [ incorrect patch snipped ]



Small geoloc daemon

2014-08-10 Thread David Carlier
Hi all.

I ve made a first draft of a new geolocalization service available here
https://github.com/devnexen/geoloc

which can be used by some other daemons. In short terms, it can gives
geolocalization informations (country code, isp...) from an ip address.

Feel free to give some thoughts about it.

Kind regards.
David CARLIER
Afilias Technologies


Proposition

2014-07-11 Thread David Carlier
Hi all,

I was wondering if a generic small geoloc lib might interest ? which can
load dynamically any geo localisation library via dlopen and so on ... to
get, let's say, a country code with an ip address ... can serve for some
purposes (I ll use it for geolocalisation load balancing via relayd) ...

Kind regards.
David CARLIER
dotMobi / Afilias Technologies


Re: Proposition

2014-07-11 Thread David Carlier
Fair point Reyk, I honestly did not think about this daemon approach !

Thanks for your inputs !


On 11 July 2014 11:59, Reyk Floeter r...@openbsd.org wrote:

 Hi,

 On Fri, Jul 11, 2014 at 11:33:19AM +0100, David Carlier wrote:
  I was wondering if a generic small geoloc lib might interest ? which can
  load dynamically any geo localisation library via dlopen and so on ... to
  get, let's say, a country code with an ip address ... can serve for some
  purposes (I ll use it for geolocalisation load balancing via relayd) ...
 

 I would not support plugins or a dlopen() approach in relayd.  And
 doing dlopen in an external library isn't very nice either.

 So what information would relayd need for geolocalisation?  Do you
 have more details about the concepts?  You could run your
 geolocalisation service as a daemon itself and let relayd connect via
 a UNIX socket to query the required information.

 In relayd, the query an external tool via the socket to get the
 destination could be fairly generic and doesn't even have to be
 geolocalisation- specific.  It could be configured as part of the new
 filter rules that I committed yesterday.

 Reyk