home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 6.2.507 < prev    next >
Encoding:
Internet Message Format  |  2004-04-26  |  7.2 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.2.507
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 6.2.507
  11. Problem:    The ownership of the file with the password for the NetBeans
  12.             connection is not checked.  "-nb={file}" doesn't work for GTK.
  13. Solution:   Only accept the file when owned by the user and not accessible by
  14.             others.  Detect "-nb=" for GTK.
  15. Files:      src/netbeans.c, src/gui_gtk_x11.c
  16.     
  17.  
  18. *** ../vim-6.2.506/src/netbeans.c    Sat Apr 17 21:14:10 2004
  19. --- src/netbeans.c    Tue Apr 27 18:16:51 2004
  20. ***************
  21. *** 70,76 ****
  22.   static long get_buf_size __ARGS((buf_T *));
  23.   
  24.   static void netbeans_connect __ARGS((void));
  25. ! static void getConnInfo __ARGS((char *file, char **host, char **port, char **password));
  26.   
  27.   static void nb_init_graphics __ARGS((void));
  28.   static void coloncmd __ARGS((char *cmd, ...));
  29. --- 70,76 ----
  30.   static long get_buf_size __ARGS((buf_T *));
  31.   
  32.   static void netbeans_connect __ARGS((void));
  33. ! static int getConnInfo __ARGS((char *file, char **host, char **port, char **password));
  34.   
  35.   static void nb_init_graphics __ARGS((void));
  36.   static void coloncmd __ARGS((char *cmd, ...));
  37. ***************
  38. *** 247,262 ****
  39.       char    *arg = NULL;
  40.   
  41.       if (netbeansArg[3] == '=')
  42.       /* "-nb=fname": Read info from specified file. */
  43. !     getConnInfo(netbeansArg + 4, &hostname, &address, &password);
  44.       else
  45.       {
  46.       if (netbeansArg[3] == ':')
  47.           /* "-nb:<host>:<addr>:<password>": get info from argument */
  48.           arg = netbeansArg + 4;
  49.       if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL)
  50.           /* "-nb": get info from file specified in environment */
  51. !         getConnInfo(fname, &hostname, &address, &password);
  52.       else
  53.       {
  54.           if (arg != NULL)
  55. --- 247,269 ----
  56.       char    *arg = NULL;
  57.   
  58.       if (netbeansArg[3] == '=')
  59. +     {
  60.       /* "-nb=fname": Read info from specified file. */
  61. !     if (getConnInfo(netbeansArg + 4, &hostname, &address, &password)
  62. !                                       == FAIL)
  63. !         return;
  64. !     }
  65.       else
  66.       {
  67.       if (netbeansArg[3] == ':')
  68.           /* "-nb:<host>:<addr>:<password>": get info from argument */
  69.           arg = netbeansArg + 4;
  70.       if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL)
  71. +     {
  72.           /* "-nb": get info from file specified in environment */
  73. !         if (getConnInfo(fname, &hostname, &address, &password) == FAIL)
  74. !         return;
  75. !     }
  76.       else
  77.       {
  78.           if (arg != NULL)
  79. ***************
  80. *** 326,335 ****
  81.       server.sin_port = htons(port);
  82.       if ((host = gethostbyname(hostname)) == NULL)
  83.       {
  84. !     if (access(hostname, R_OK) >= 0)
  85.       {
  86.           /* DEBUG: input file */
  87. !         sd = open(hostname, O_RDONLY);
  88.           goto theend;
  89.       }
  90.       PERROR("gethostbyname() in netbeans_connect()");
  91. --- 333,342 ----
  92.       server.sin_port = htons(port);
  93.       if ((host = gethostbyname(hostname)) == NULL)
  94.       {
  95. !     if (mch_access(hostname, R_OK) >= 0)
  96.       {
  97.           /* DEBUG: input file */
  98. !         sd = mch_open(hostname, O_RDONLY, 0);
  99.           goto theend;
  100.       }
  101.       PERROR("gethostbyname() in netbeans_connect()");
  102. ***************
  103. *** 421,463 ****
  104.   /*
  105.    * Obtain the NetBeans hostname, port address and password from a file.
  106.    * Return the strings in allocated memory.
  107.    */
  108. !     static void
  109.   getConnInfo(char *file, char **host, char **port, char **auth)
  110.   {
  111. !     FILE *fp = mch_fopen(file, "r");
  112.       char_u buf[BUFSIZ];
  113.       char_u *lp;
  114.       char_u *nl;
  115.   
  116.       if (fp == NULL)
  117.       PERROR("E660: Cannot open NetBeans connection info file");
  118. !     else
  119.       {
  120. !     /* Read the file. There should be one of each parameter */
  121. !     while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL)
  122. !     {
  123. !         if ((nl = vim_strchr(lp, '\n')) != NULL)
  124. !         *nl = 0;        /* strip off the trailing newline */
  125.   
  126. !         if (STRNCMP(lp, "host=", 5) == 0)
  127. !         {
  128. !         vim_free(*host);
  129. !         *host = (char *)vim_strsave(&buf[5]);
  130. !         }
  131. !         else if (STRNCMP(lp, "port=", 5) == 0)
  132. !         {
  133. !         vim_free(*port);
  134. !         *port = (char *)vim_strsave(&buf[5]);
  135. !         }
  136. !         else if (STRNCMP(lp, "auth=", 5) == 0)
  137. !         {
  138. !         vim_free(*auth);
  139. !         *auth = (char *)vim_strsave(&buf[5]);
  140. !         }
  141.       }
  142. -     fclose(fp);
  143.       }
  144.   }
  145.   
  146.   
  147. --- 428,491 ----
  148.   /*
  149.    * Obtain the NetBeans hostname, port address and password from a file.
  150.    * Return the strings in allocated memory.
  151. +  * Return FAIL if the file could not be read, OK otherwise (no matter what it
  152. +  * contains).
  153.    */
  154. !     static int
  155.   getConnInfo(char *file, char **host, char **port, char **auth)
  156.   {
  157. !     FILE *fp;
  158.       char_u buf[BUFSIZ];
  159.       char_u *lp;
  160.       char_u *nl;
  161. + #ifdef UNIX
  162. +     struct stat    st;
  163.   
  164. +     /*
  165. +      * For Unix only accept the file when it's owned by the current user and
  166. +      * not accessible by others.
  167. +      */
  168. +     if (mch_stat(file, &st) == 0
  169. +         && (st.st_uid != getuid() || (st.st_mode & 0077)))
  170. +     {
  171. +     EMSG2(_("E668: Ownership of NetBeans connection file invalid: \"%s\""),
  172. +                                     file);
  173. +     return FAIL;
  174. +     }
  175. + #endif
  176. +     fp = mch_fopen(file, "r");
  177.       if (fp == NULL)
  178. +     {
  179.       PERROR("E660: Cannot open NetBeans connection info file");
  180. !     return FAIL;
  181. !     }
  182. !     /* Read the file. There should be one of each parameter */
  183. !     while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL)
  184.       {
  185. !     if ((nl = vim_strchr(lp, '\n')) != NULL)
  186. !         *nl = 0;        /* strip off the trailing newline */
  187.   
  188. !     if (STRNCMP(lp, "host=", 5) == 0)
  189. !     {
  190. !         vim_free(*host);
  191. !         *host = (char *)vim_strsave(&buf[5]);
  192. !     }
  193. !     else if (STRNCMP(lp, "port=", 5) == 0)
  194. !     {
  195. !         vim_free(*port);
  196. !         *port = (char *)vim_strsave(&buf[5]);
  197. !     }
  198. !     else if (STRNCMP(lp, "auth=", 5) == 0)
  199. !     {
  200. !         vim_free(*auth);
  201. !         *auth = (char *)vim_strsave(&buf[5]);
  202.       }
  203.       }
  204. +     fclose(fp);
  205. +     return OK;
  206.   }
  207.   
  208.   
  209. ***************
  210. *** 578,584 ****
  211.           if (file == NULL)
  212.           outfd = -3;
  213.           else
  214. !         outfd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
  215.       }
  216.   
  217.       if (outfd >= 0)
  218. --- 606,612 ----
  219.           if (file == NULL)
  220.           outfd = -3;
  221.           else
  222. !         outfd = mch_open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
  223.       }
  224.   
  225.       if (outfd >= 0)
  226. *** ../vim-6.2.506/src/gui_gtk_x11.c    Mon Apr  5 20:28:39 2004
  227. --- src/gui_gtk_x11.c    Tue Apr 27 18:00:59 2004
  228. ***************
  229. *** 480,486 ****
  230.               break;
  231.   #ifdef FEAT_NETBEANS_INTG
  232.           /* darn, -nb has non-standard syntax */
  233. !         if (argv[i][len] == ':'
  234.               && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS)
  235.               break;
  236.   #endif
  237. --- 480,486 ----
  238.               break;
  239.   #ifdef FEAT_NETBEANS_INTG
  240.           /* darn, -nb has non-standard syntax */
  241. !         if (vim_strchr(":=", argv[i][len]) != NULL
  242.               && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS)
  243.               break;
  244.   #endif
  245. *** ../vim-6.2.506/src/version.c    Tue Apr 27 16:27:09 2004
  246. --- src/version.c    Tue Apr 27 21:38:31 2004
  247. ***************
  248. *** 639,640 ****
  249. --- 639,642 ----
  250.   {   /* Add new patch number below this line */
  251. + /**/
  252. +     507,
  253.   /**/
  254.  
  255. -- 
  256. Despite the cost of living, have you noticed how it remains so popular?
  257.  
  258.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  259. ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  260. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  261.  \\\  Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
  262.