Просмотр исходного кода

remove 256 char line limit by using getline() (POSIX.1-2008)

David Kalnischkies лет назад: 13
Родитель
Сommit
7f18595b3e
2 измененных файлов с 6 добавлено и 3 удалено
  1. 5 3
      apt-pkg/contrib/netrc.cc
  2. 1 0
      debian/changelog

+ 5 - 3
apt-pkg/contrib/netrc.cc

@@ -79,13 +79,14 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw
     char *tok;
     char *tok;
     char *tok_buf;
     char *tok_buf;
     bool done = false;
     bool done = false;
-    char netrcbuffer[256];
+    char *netrcbuffer = NULL;
+    size_t netrcbuffer_size = 0;
 
 
     int state = NOTHING;
     int state = NOTHING;
     char state_login = 0;        /* Found a login keyword */
     char state_login = 0;        /* Found a login keyword */
     char state_password = 0;     /* Found a password keyword */
     char state_password = 0;     /* Found a password keyword */
 
 
-    while (!done && fgets(netrcbuffer, sizeof (netrcbuffer), file)) {
+    while (!done && getline(&netrcbuffer, &netrcbuffer_size, file) != -1) {
       tok = strtok_r (netrcbuffer, " \t\n", &tok_buf);
       tok = strtok_r (netrcbuffer, " \t\n", &tok_buf);
       while (!done && tok) {
       while (!done && tok) {
         if(login.empty() == false && password.empty() == false) {
         if(login.empty() == false && password.empty() == false) {
@@ -142,8 +143,9 @@ static int parsenetrc_string (char *host, std::string &login, std::string &passw
 
 
         tok = strtok_r (NULL, " \t\n", &tok_buf);
         tok = strtok_r (NULL, " \t\n", &tok_buf);
       } /* while(tok) */
       } /* while(tok) */
-    } /* while fgets() */
+    } /* while getline() */
 
 
+    free(netrcbuffer);
     fclose(file);
     fclose(file);
   }
   }
 
 

+ 1 - 0
debian/changelog

@@ -27,6 +27,7 @@ apt (0.9.7.6) UNRELEASED; urgency=low
       (partly fixing #687255, b= support has to wait for jessie)
       (partly fixing #687255, b= support has to wait for jessie)
   * apt-pkg/contrib/netrc.cc:
   * apt-pkg/contrib/netrc.cc:
     - remove the 64 char limit for login/password in internal usage
     - remove the 64 char limit for login/password in internal usage
+    - remove 256 char line limit by using getline() (POSIX.1-2008)
 
 
  -- David Kalnischkies <kalnischkies@gmail.com>  Wed, 19 Sep 2012 11:29:56 +0200
  -- David Kalnischkies <kalnischkies@gmail.com>  Wed, 19 Sep 2012 11:29:56 +0200