All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ville Nuorvala <vnuorval@tcs.hut.fi>
To: bluez-devel@lists.sourceforge.net
Subject: Re: [Bluez-devel] [PATCH] Properly replace an existing key value pair in a text file
Date: Wed, 07 Sep 2005 19:04:12 +0300	[thread overview]
Message-ID: <431F0F7C.9090006@tcs.hut.fi> (raw)
In-Reply-To: <1126094276.10631.22.camel@blade>

[-- Attachment #1: Type: text/plain, Size: 1163 bytes --]

Marcel Holtmann wrote:
> Hi Ville,
> 
> 
>>textfile_put() was unable to replace a key value pair if it happened to 
>>be the last entry in a file. I noticed this problem in bluez-utils-2.19, 
>>but it still seems to exist in the latest CVS code. The patch below 
>>should fix it...
> 
> 
> I though that I fixed this. Are you sure that problem is still present?

Yes. I located the problem in Gentoo's bluez-utils-2.19 and since it 
hasn't yet been fixed in the CVS repository, I'm quite certain it still 
is present ;-)

I noticed the problem when hcid just wouldn't update the link key in 
var/lib/bluetooth/<hwaddr>/linkkeys, even though the debug statements 
claimed otherwise. The textfile_put() function clearly works incorrectly 
since zero is a valid value for the len variable, but the if (len <= 0 
|| ..) check causes the the function to exit before anything is written.

Btw, I resend the patch as a separate attachement since the tabs got 
screwed up last time.

Regards,
Ville
-- 
Ville Nuorvala
Research Assistant,
Laboratory for Theoretical Computer Science,
Helsinki University of Technology
email: vnuorval@tcs.hut.fi, phone: +358 (0)9 451 5257

[-- Attachment #2: replace_key_value.patch --]
[-- Type: text/x-patch, Size: 618 bytes --]

Index: common/textfile.c
===================================================================
RCS file: /cvsroot/bluez/utils/common/textfile.c,v
retrieving revision 1.6
diff -u -r1.6 textfile.c
--- common/textfile.c	30 Aug 2005 00:35:39 -0000	1.6
+++ common/textfile.c	7 Sep 2005 11:06:43 -0000
@@ -180,8 +180,14 @@
 	end += len;
 
 	len = size - (end - map);
-
-	if (len <= 0 || len > size) {
+	if (!len) {
+		munmap(map, size);
+		ftruncate(fd, base);
+		pos = lseek(fd, base, SEEK_SET);
+		err = write_key_value(fd, key, value);
+		goto unlock;
+	}
+	if (len < 0 || len > size) {
 		err = EILSEQ;
 		goto unmap;
 	}

  reply	other threads:[~2005-09-07 16:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-07 11:17 [Bluez-devel] [PATCH] Properly replace an existing key value pair in a text file Ville Nuorvala
2005-09-07 11:57 ` Marcel Holtmann
2005-09-07 16:04   ` Ville Nuorvala [this message]
2005-09-07 17:33     ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=431F0F7C.9090006@tcs.hut.fi \
    --to=vnuorval@tcs.hut.fi \
    --cc=bluez-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.