mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix sysconf(_SC_LINE_MAX) to return LINE_MAX
@ 2014-05-07  9:26 Christian Wiese
  2014-05-19 22:09 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Wiese @ 2014-05-07  9:26 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 218 bytes --]

Hi,

attached is a patch for fixing sysconf(_SC_LINE_MAX) to not always
return -1 but LINE_MAX as defined in limits.h.

Greetings
Chris

-- 
PGP Fingerprint: F96B A15F DF25 2B3E 49CB BA16 241B F3E7 52FE AFC6

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: musl-fix-sysconf-_SC_LINE_MAX-to-return-LINE_MAX.patch --]
[-- Type: text/x-patch, Size: 1636 bytes --]

From 9f7717649e338e53e8d068e8722f03229d1dd99b Mon Sep 17 00:00:00 2001
From: Christian Wiese <chris@opensde.org>
Date: Wed, 7 May 2014 10:43:28 +0200
Subject: [PATCH] fix sysconf(_SC_LINE_MAX) to return LINE_MAX

The problem was discovered when calling the wall(1) command from util-linux

---------------------------------------------------------------------------
./wall "123"
wall: cannot allocate 18446744073709551615 bytes: Out of memory
---------------------------------------------------------------------------

triggered by 'makemsg()' in 'term-utils/wall.c' which uses sysconf() to
determine LINE_MAX for allocating a buffer through the builtin xmalloc()

---------------%<----------------------------------------------------------
char *p, *lbuf, *tmpname, *mbuf;
long line_max;

line_max = sysconf(_SC_LINE_MAX);
lbuf = xmalloc(line_max);
---------------%<----------------------------------------------------------

which fails because in musl sysconf(_SC_LINE_MAX) is always returning -1.

Signed-off-by: Christian Wiese <chris@opensde.org>
---
 src/conf/sysconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/sysconf.c b/src/conf/sysconf.c
index bf433d6..21e0743 100644
--- a/src/conf/sysconf.c
+++ b/src/conf/sysconf.c
@@ -66,7 +66,7 @@ long sysconf(int name)
 		[_SC_COLL_WEIGHTS_MAX] = COLL_WEIGHTS_MAX,
 		[_SC_EQUIV_CLASS_MAX] = -1, /* ?? */
 		[_SC_EXPR_NEST_MAX] = -1,
-		[_SC_LINE_MAX] = -1,
+		[_SC_LINE_MAX] = LINE_MAX,
 		[_SC_RE_DUP_MAX] = RE_DUP_MAX,
 		[_SC_CHARCLASS_NAME_MAX] = -1, /* ?? */
 		[_SC_2_VERSION] = VER,
-- 
1.9.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-19 22:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-07  9:26 [PATCH] fix sysconf(_SC_LINE_MAX) to return LINE_MAX Christian Wiese
2014-05-19 22:09 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).