utmp fix for mips64 uClibc systems
Waldemar Brodkorb
mail at waldemar-brodkorb.de
Mon Sep 24 19:12:01 UTC 2012
Hi Developers,
I have some strange problem with getty, init and login on mips64
uClibc (0.9.33.2) systems:
qemu-system-mips64, big endian, n64
lemote yeelong, little endian, n32
Following test code segfaults:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
int n;
n=open("/dev/nul", O_RDWR);
close(n);
return(0);
}
When close get a -1 as argument, it segfaults.
Suggested patch for libbb/utmp.c to avoid this in the mentioned apps:
best regards
Waldemar
---
>From f1b662fe3a847c190c46f93c0f13002ee3ca6c0c Mon Sep 17 00:00:00
2001
From: Waldemar Brodkorb <wbx at openadk.org>
Date: Mon, 24 Sep 2012 21:10:52 +0200
Subject: [PATCH] close(-1) segfaults on mips64 uClibc systems
Signed-off-by: Waldemar Brodkorb <wbx at openadk.org>
---
libbb/utmp.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/libbb/utmp.c b/libbb/utmp.c
index 09443fb..c56fdb3 100644
--- a/libbb/utmp.c
+++ b/libbb/utmp.c
@@ -10,8 +10,14 @@
static void touch(const char *filename)
{
- if (access(filename, R_OK | W_OK) == -1)
- close(open(filename, O_WRONLY | O_CREAT, 0664));
+ int c = 0;
+
+ if (access(filename, R_OK | W_OK) == -1) {
+ c=open(filename, O_WRONLY | O_CREAT, 0664);
+ if (c > 0) {
+ close(c);
+ }
+ }
}
void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char
*tty_name, const char *username, const char *hostname)
--
1.7.10.4
More information about the busybox
mailing list