[PATCH] Fix / slightly simplify smbd/scavenger
Volker Lendecke
Volker.Lendecke at SerNet.DE
Fri Oct 30 09:49:40 UTC 2015
On Thu, Oct 29, 2015 at 08:23:26PM +0200, Uri Simchoni wrote:
>
>
> On 10/29/2015 06:02 PM, Volker Lendecke wrote:
> >+ ret = read_data(fd, child, sizeof(child));
> >+ if (ret == -1) {
> Doesn't seem to take EOF into account, but neither does the original
> code. How come?
Oversight, sorry. Attached find a new patch.
Thanks, Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
Besuchen Sie uns vom 10.-11.11.15 auf der ISSE!
Information Security Solutions Europe Conference
Hotel Palace Berlin, 20%-Rabattcode: "ISSE15SP"
Meet us at Information Security Conference ISSE!
November 10th - 11th 2015 in Hotel Palace Berlin
For 20% discount take voucher code: "ISSE15SP"
-------------- next part --------------
From ed4ff51e73f6c7194fab077736569507d215cfe0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 29 Oct 2015 14:27:32 +0100
Subject: [PATCH] smbd: Fix/simplify scavenger routines
Use read_data/write_data, "ofs" was not incremented
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/scavenger.c | 47 ++++++++++++++++++++---------------------------
1 file changed, 20 insertions(+), 27 deletions(-)
diff --git a/source3/smbd/scavenger.c b/source3/smbd/scavenger.c
index 6171c29..2001ce9 100644
--- a/source3/smbd/scavenger.c
+++ b/source3/smbd/scavenger.c
@@ -26,7 +26,7 @@
#include "smbd/scavenger.h"
#include "locking/proto.h"
#include "lib/util/util_process.h"
-#include "lib/util/sys_rw.h"
+#include "lib/util/sys_rw_data.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_SCAVENGER
@@ -144,21 +144,17 @@ static int smbd_scavenger_server_id_destructor(struct server_id *id)
static bool scavenger_say_hello(int fd, struct server_id self)
{
- const uint8_t *msg = (const uint8_t *)&self;
- size_t remaining = sizeof(self);
- size_t ofs = 0;
+ ssize_t ret;
struct server_id_buf tmp;
- while (remaining > 0) {
- ssize_t ret;
-
- ret = sys_write(fd, msg + ofs, remaining);
- if (ret == -1) {
- DEBUG(2, ("Failed to write to pipe: %s\n",
- strerror(errno)));
- return false;
- }
- remaining -= ret;
+ ret = write_data(fd, &self, sizeof(self));
+ if (ret == -1) {
+ DEBUG(2, ("Failed to write to pipe: %s\n", strerror(errno)));
+ return false;
+ }
+ if (ret < sizeof(self)) {
+ DBG_WARNING("Could not write serverid\n");
+ return false;
}
DEBUG(4, ("scavenger_say_hello: self[%s]\n",
@@ -168,21 +164,18 @@ static bool scavenger_say_hello(int fd, struct server_id self)
static bool scavenger_wait_hello(int fd, struct server_id *child)
{
- uint8_t *msg = (uint8_t *)child;
- size_t remaining = sizeof(*child);
- size_t ofs = 0;
struct server_id_buf tmp;
+ ssize_t ret;
- while (remaining > 0) {
- ssize_t ret;
-
- ret = sys_read(fd, msg + ofs, remaining);
- if (ret == -1) {
- DEBUG(2, ("Failed to read from pipe: %s\n",
- strerror(errno)));
- return false;
- }
- remaining -= ret;
+ ret = read_data(fd, child, sizeof(child));
+ if (ret == -1) {
+ DEBUG(2, ("Failed to read from pipe: %s\n",
+ strerror(errno)));
+ return false;
+ }
+ if (ret < sizeof(child)) {
+ DBG_WARNING("Could not read serverid\n");
+ return false;
}
DEBUG(4, ("scavenger_say_hello: child[%s]\n",
--
1.9.1
More information about the samba-technical
mailing list