[BACK]Return to cgi.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/cgi.c between version 1.79 and 1.82

version 1.79, 2014/07/21 22:33:01 version 1.82, 2014/07/24 20:30:45
Line 53  struct req {
Line 53  struct req {
 };  };
   
 static  void             catman(const struct req *, const char *);  static  void             catman(const struct req *, const char *);
 static  int              cmp(const void *, const void *);  
 static  void             format(const struct req *, const char *);  static  void             format(const struct req *, const char *);
 static  void             html_print(const char *);  static  void             html_print(const char *);
 static  void             html_printquery(const struct req *);  static  void             html_printquery(const struct req *);
Line 422  resp_searchform(const struct req *req)
Line 421  resp_searchform(const struct req *req)
   
         /* Write architecture selector. */          /* Write architecture selector. */
   
         puts("<SELECT NAME=\"arch\">");          printf( "<SELECT NAME=\"arch\">\n"
                   "<OPTION VALUE=\"default\"");
           if (NULL == req->q.arch)
                   printf(" SELECTED");
           puts(">All Architectures</OPTION>");
         for (i = 0; i < arch_MAX; i++) {          for (i = 0; i < arch_MAX; i++) {
                 printf("<OPTION VALUE=\"%s\"", arch_names[i]);                  printf("<OPTION VALUE=\"%s\"", arch_names[i]);
                 if (NULL != req->q.arch &&                  if (NULL != req->q.arch &&
Line 467  resp_searchform(const struct req *req)
Line 470  resp_searchform(const struct req *req)
 }  }
   
 static int  static int
   validate_urifrag(const char *frag)
   {
   
           while ('\0' != *frag) {
                   if ( ! (isalnum((unsigned char)*frag) ||
                       '-' == *frag || '.' == *frag ||
                       '/' == *frag || '_' == *frag))
                           return(0);
                   frag++;
           }
           return(1);
   }
   
   static int
 validate_manpath(const struct req *req, const char* manpath)  validate_manpath(const struct req *req, const char* manpath)
 {  {
         size_t   i;          size_t   i;
Line 545  pg_error_internal(void)
Line 562  pg_error_internal(void)
 static void  static void
 pg_searchres(const struct req *req, struct manpage *r, size_t sz)  pg_searchres(const struct req *req, struct manpage *r, size_t sz)
 {  {
           char            *arch, *archend;
         size_t           i, iuse, isec;          size_t           i, iuse, isec;
           int              archprio, archpriouse;
         int              prio, priouse;          int              prio, priouse;
         char             sec;          char             sec;
   
Line 573  pg_searchres(const struct req *req, struct manpage *r,
Line 592  pg_searchres(const struct req *req, struct manpage *r,
                 return;                  return;
         }          }
   
         qsort(r, sz, sizeof(struct manpage), cmp);  
   
         resp_begin_html(200, NULL);          resp_begin_html(200, NULL);
         resp_searchform(req);          resp_searchform(req);
         puts("<DIV CLASS=\"results\">");          puts("<DIV CLASS=\"results\">");
Line 608  pg_searchres(const struct req *req, struct manpage *r,
Line 625  pg_searchres(const struct req *req, struct manpage *r,
                 puts("<HR>");                  puts("<HR>");
                 iuse = 0;                  iuse = 0;
                 priouse = 10;                  priouse = 10;
                   archpriouse = 3;
                 for (i = 0; i < sz; i++) {                  for (i = 0; i < sz; i++) {
                         isec = strcspn(r[i].file, "123456789");                          isec = strcspn(r[i].file, "123456789");
                         sec = r[i].file[isec];                          sec = r[i].file[isec];
                         if ('\0' == sec)                          if ('\0' == sec)
                                 continue;                                  continue;
                         prio = sec_prios[sec - '1'];                          prio = sec_prios[sec - '1'];
                           if (NULL == req->q.arch) {
                                   archprio =
                                       (NULL == (arch = strchr(
                                           r[i].file + isec, '/'))) ? 3 :
                                       (NULL == (archend = strchr(
                                           arch + 1, '/'))) ? 0 :
                                       strncmp(arch, "amd64/",
                                           archend - arch) ? 2 : 1;
                                   if (archprio < archpriouse) {
                                           archpriouse = archprio;
                                           priouse = prio;
                                           iuse = i;
                                           continue;
                                   }
                                   if (archprio > archpriouse)
                                           continue;
                           }
                         if (prio >= priouse)                          if (prio >= priouse)
                                 continue;                                  continue;
                         priouse = prio;                          priouse = prio;
Line 960  main(void)
Line 995  main(void)
         if (NULL == (scriptname = getenv("SCRIPT_NAME")))          if (NULL == (scriptname = getenv("SCRIPT_NAME")))
                 scriptname = "";                  scriptname = "";
   
           if ( ! validate_urifrag(scriptname)) {
                   fprintf(stderr, "unsafe SCRIPT_NAME \"%s\"\n",
                       scriptname);
                   pg_error_internal();
                   return(EXIT_FAILURE);
           }
   
         /*          /*
          * First we change directory into the MAN_DIR so that           * First we change directory into the MAN_DIR so that
          * subsequent scanning for manpath directories is rooted           * subsequent scanning for manpath directories is rooted
Line 987  main(void)
Line 1029  main(void)
                 return(EXIT_FAILURE);                  return(EXIT_FAILURE);
         }          }
   
           if ( ! (NULL == req.q.arch || validate_urifrag(req.q.arch))) {
                   pg_error_badrequest(
                       "You specified an invalid architecture.");
                   return(EXIT_FAILURE);
           }
   
         /* Dispatch to the three different pages. */          /* Dispatch to the three different pages. */
   
         path = getenv("PATH_INFO");          path = getenv("PATH_INFO");
Line 1008  main(void)
Line 1056  main(void)
         return(EXIT_SUCCESS);          return(EXIT_SUCCESS);
 }  }
   
 static int  
 cmp(const void *p1, const void *p2)  
 {  
   
         return(strcasecmp(((const struct manpage *)p1)->names,  
             ((const struct manpage *)p2)->names));  
 }  
   
 /*  /*
  * Scan for indexable paths.   * Scan for indexable paths.
  */   */
Line 1038  pathgen(struct req *req)
Line 1078  pathgen(struct req *req)
                         dpsz--;                          dpsz--;
                 req->p = mandoc_realloc(req->p,                  req->p = mandoc_realloc(req->p,
                     (req->psz + 1) * sizeof(char *));                      (req->psz + 1) * sizeof(char *));
                 req->p[req->psz++] = mandoc_strndup(dp, dpsz);                  dp = mandoc_strndup(dp, dpsz);
                   if ( ! validate_urifrag(dp)) {
                           fprintf(stderr, "%s/manpath.conf contains "
                               "unsafe path \"%s\"\n", MAN_DIR, dp);
                           pg_error_internal();
                           exit(EXIT_FAILURE);
                   }
                   if (NULL != strchr(dp, '/')) {
                           fprintf(stderr, "%s/manpath.conf contains "
                               "path with slash \"%s\"\n", MAN_DIR, dp);
                           pg_error_internal();
                           exit(EXIT_FAILURE);
                   }
                   req->p[req->psz++] = dp;
         }          }
   
         if ( req->p == NULL ) {          if ( req->p == NULL ) {

Legend:
Removed from v.1.79  
changed lines
  Added in v.1.82

CVSweb