-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: shell-daemons
action: commit
revision:
path_from:
revision_from: b0b04ab79f6e736892665bbac241bf9e45a66120:
path_to:
revision_to:

git.thebackupbox.net

shell-daemons

git://git.thebackupbox.net/shell-daemons

commit b0b04ab79f6e736892665bbac241bf9e45a66120
Author: epoch <epoch@hack.thebackupbox.net>
Date:   Fri Sep 18 04:22:03 2020 +0000

    added a usage: for when no arguments. attempted to prevent any possible overflow by allocating /at least/ enough based on the length of the expanding string where the string gets expanded compared to the input

diff --git a/normalpath.c b/normalpath.c

index a0b0175a072a4c2a5f7e55f2e60a4f408517d7f8..

index ..ef26659a0a1865a3c99a1a4de631f80e4197cf2a 100644

--- a/normalpath.c
+++ b/normalpath.c
@@ -11,11 +11,16 @@
 int main(int argc,char *argv[]) {
  int i,j,k,l;
  struct passwd *pwd;
+ if(argc < 2) {
+   fprintf(stderr,"usage: normalpath a/path/to/normalize/to/not/include/../../../or///t//h//e//s//e/\n");
+   exit(1);
+ }
  char *s=argv[1];
  char *t;
- char *out=malloc(MAXPATHLEN+1);
+ char *out;
  switch(s[0]) {
   case '/':
+   out=malloc(strlen(argv[1])+1);
    strcpy(out,"/");
    break;
   case '~':
@@ -31,10 +36,12 @@ int main(int argc,char *argv[]) {
      pwd=getpwuid(getuid());//there was a / after the ~
    }
    if(pwd) {
+     out=malloc(strlen(pwd->pw_dir)+strlen(argv[1])+1);//
      strcpy(out,pwd->pw_dir);
      strcat(out,"/");
      if(t) s=t+1;
    } else {
+     out=malloc(strlen(argv[1])+1);
      s=argv[1];//let's pretend like we're ignoring ~ now...
      if(t) *t='/';//undo this too
    }
@@ -42,9 +49,16 @@ int main(int argc,char *argv[]) {
   default:
 //old code, but might be what I decide I /really/ want.
 //   getcwd(out,MAXPATHLEN);
-   if(getenv("PWD")) strcpy(out,getenv("PWD"));
-   strcat(out,"/");
+   if(getenv("PWD")) {
+     out=malloc(strlen(getenv("PWD"))+strlen(argv[1])+1);
+     strcpy(out,getenv("PWD"));
+   } else {
+     out=malloc(strlen(argv[1])+1);
+     strcpy(out,"");
+   }
+   strcat(out,"/");//???
  }
+// the only place the string /might/ get longer is in the previous two cases of and ~
  strcat(out,s);
 #if DEBUG
  printf("%s\n",out);

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 10:41:09 2024