"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: gotwebd: openat(2) and less params for scraping repo info
To:
Stefan Sperling <stsp@stsp.name>
Cc:
gameoftrees@openbsd.org
Date:
Tue, 22 Nov 2022 20:10:15 +0100

Download raw body.

Thread
  • Christian Weisgerber:

    gotwebd: openat(2) and less params for scraping repo info

  • On 2022/11/22 19:49:34 +0100, Stefan Sperling <stsp@stsp.name> wrote:
    > On Tue, Nov 22, 2022 at 07:43:17PM +0100, Omar Polo wrote:
    > > P.S.: the check len < SIZE_MAX - 1 is there just to avoid the implicit
    > > cast.  It's silly to try to calloc a number like that, but here i'd
    > > like to focus on just switchi to openat and reducing the seeks, a
    > > sensible upper limit can be discussed and applied later.
    > 
    > Yeah. We should probably be asking getrlimit() for RLIMIT_DATA more often.
    
    hum, not so sure in this case.  I'd just settle on a sensible maximum
    value, like 1024.  we can't malloc RLIMIT_DATA either because we've
    already allocated memory for other things, or am I mixing things?
    
    These are files that are displayed in the gotwebd UI, it doesn't make
    sense to have a lot of content.  They should be just a few lines.
    Furthermore, description and cloneurl are just informative and can be
    safely truncated.
    
    just to provide a datapoint, this is what I currently have:
    
    	antartica$ find /var/www/got/public/ \
    		-name description -o -name cloneurl \
    		-exec stat -f %z {} + | sort -rh | head
    	140
    	137
    	134
    	128
    	125
    	116
    	113
    	113
    	113
    	113
    
    these are bytes...
    
    
    diff /home/op/w/got
    commit - 3b81530f7d0ffe60024f054f6d87ff8dd558e3fe
    path + /home/op/w/got
    blob - 6991dbcb9481482215de315ffb2caf894bad5350
    file + gotwebd/gotweb.c
    --- gotwebd/gotweb.c
    +++ gotwebd/gotweb.c
    @@ -2510,8 +2510,8 @@ gotweb_get_repo_description(char **description, struct
     	}
     
     	len = sb.st_size;
    -	if (len > SIZE_MAX - 1)
    -		len = SIZE_MAX - 1;
    +	if (len > GOTWEBD_MAXDESCRSZ - 1)
    +		len = GOTWEBD_MAXDESCRSZ - 1;
     
     	*description = calloc(len + 1, sizeof(**description));
     	if (*description == NULL) {
    @@ -2556,8 +2556,8 @@ gotweb_get_clone_url(char **url, struct server *srv, c
     	}
     
     	len = sb.st_size;
    -	if (len > SIZE_MAX - 1)
    -		len = SIZE_MAX - 1;
    +	if (len > GOTWEBD_MAXCLONEURLSZ - 1)
    +		len = GOTWEBD_MAXCLONEURLSZ - 1;
     
     	*url = calloc(len + 1, sizeof(**url));
     	if (*url == NULL) {
    blob - 0a9217f7fb5cc2256686d1d01c59b69e5f96d4ad
    file + gotwebd/gotwebd.h
    --- gotwebd/gotwebd.h
    +++ gotwebd/gotwebd.h
    @@ -39,6 +39,8 @@
     
     #define GOTWEBD_USER		 "www"
     
    +#define GOTWEBD_MAXDESCRSZ	 1024
    +#define GOTWEBD_MAXCLONEURLSZ	 1024
     #define GOTWEBD_CACHESIZE	 1024
     #define GOTWEBD_MAXCLIENTS	 1024
     #define GOTWEBD_MAXTEXT		 511
    
    
  • Christian Weisgerber:

    gotwebd: openat(2) and less params for scraping repo info