beans

simple pastebin server
git clone git://git.bitsmanent.org/beans
Log | Files | Refs | LICENSE

commit 9c565e61b9d4dc0fe56d5ac645a950e5e60a3202
parent a80fee5e6eef3834e8948fe84df371e0e618db61
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Wed, 27 Apr 2022 20:29:15 +0200

Max file size is 32k

Diffstat:
Mbeans.c | 16++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/beans.c b/beans.c @@ -15,12 +15,13 @@ #include "arg.h" #define BACKLOG 32 +#define MAXSIZE 32000 /* in bytes */ /* function declarations */ void die(const char *errstr, ...); int bindon(char *port); void *ecalloc(size_t nmemb, size_t size); -char *readall(int sd, int *len); +char *readall(int sd, int *len, int limit); void run(void); void serve(int sd); void sout(int sd, char *fmt, ...); @@ -75,17 +76,24 @@ ecalloc(size_t nmemb, size_t size) { } char * -readall(int sd, int *len) { +readall(int sd, int *len, int limit) { char *buf; int sz = 512, r, l = 0; + if(limit && sz > limit) + sz = limit; + buf = ecalloc(1, sz); while((r = read(sd, &buf[l], sz - l)) != -1) { if(!r) break; l += r; + if(limit && l == limit) + break; if(l == sz) { sz *= 2; + if(limit && sz > limit) + sz = limit; if(!(buf = realloc(buf, sz))) die("realloc()\n"); } @@ -131,9 +139,9 @@ void serve(int sd) { int len, tmpsd; char *buf, *code; - char tmpfn[64] = {0}; + char tmpfn[320] = {0}; - buf = readall(sd, &len); + buf = readall(sd, &len, MAXSIZE); if(!(buf && len)) { sout(sd, "Nothing pasted.\n"); return;