damus-io / nostrdb

The unfairly fast embedded nostr database backed by lmdb
Other
92 stars 17 forks source link

Delete unuse argument (destsize) #18

Closed Hakkadaikon closed 10 months ago

Hakkadaikon commented 10 months ago

Hi ! I'm hakkadaikon. (npub: npub1zqdnpm5gcfap8hngha7gcp3k363786phvs2etsvxw4nh6x9ydfzsuyk6mn)

I added this because there was no destsize check in the hex_encode method. Please check. 🙏

jb55 commented 10 months ago

we don't ever use this function with unknown destination sizes, is there a specific issue you're trying to fix here?

Hakkadaikon commented 10 months ago

we don't ever use this function with unknown destination sizes

I thought I meant to detect a buffer overflow on the destination size, since the destination size is passed as an argument and is not used.

If destsize is just being passed for future use, this may not be necessary.

jb55 commented 10 months ago

On Fri, Dec 01, 2023 at 10:30:36AM -0800, Hakkadaikon wrote:

we don't ever use this function with unknown destination sizes

If destsize is just being passed for future use, this may not be necessary.

oh we can remove destsize if we're not using it

Hakkadaikon commented 10 months ago

OK, I'll create a "new pull request with destsize removed".

jb55 commented 10 months ago

On Fri, Dec 01, 2023 at 10:36:06AM -0800, Hakkadaikon wrote:

OK, I'll create a "new pull request with destsize removed".

you can just update this one as well if you want

Hakkadaikon commented 10 months ago

you can just update this one as well if you want

Hi, I have changed the title and modification details of this pull request. (Unused variable: destsize removed.) Please check.🙏

Also, hex_encode was only used in one place.

jb55 commented 10 months ago

Thanks!

Reviewed-by: William Casarin @.***>

On Sat, Dec 02, 2023 at 02:52:14AM +0900, hakkadaikon wrote:

Closes: https://github.com/damus-io/nostrdb/pull/18

hex.h | 2 +- nostrdb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hex.h b/hex.h index 88000a7..ce20ff4 100644 --- a/hex.h +++ b/hex.h @@ -50,7 +50,7 @@ static inline char hexchar(unsigned int val) abort(); }

-static int hex_encode(const void buf, size_t bufsize, char dest, size_t destsize) +static int hex_encode(const void buf, size_t bufsize, char dest) { size_t i;

diff --git a/nostrdb.c b/nostrdb.c index d973b67..2a8451f 100644 --- a/nostrdb.c +++ b/nostrdb.c @@ -3616,7 +3616,7 @@ static int ndb_event_commitment(struct ndb_note ev, unsigned char buf, int buf struct cursor cur; int ok;

  • if (!hex_encode(ev->pubkey, sizeof(ev->pubkey), pubkey, sizeof(pubkey)))
  • if (!hex_encode(ev->pubkey, sizeof(ev->pubkey), pubkey)) return 0;

    make_cursor(buf, buf + buflen, &cur);