Sfoglia il codice sorgente

Remove leading and trailing spaces from versions, and check if there are
embedded spaces in versions.

Adam Heath 25 anni fa
parent
commit
141416223f
2 ha cambiato i file con 15 aggiunte e 2 eliminazioni
  1. 5 0
      ChangeLog
  2. 10 2
      lib/parsehelp.c

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+Sat Jun  2 14:09:28 CDT 2001 Adam Heath <doogie@debian.org>
+
+  * lib/parsehelp.c: Remove leading and trailing spaces from versions, and
+    check if there are embedded spaces in versions.
+
 Tue May 29 07:27:31 CEST 2001 peter karlsson <peterk@debian.org>
 
   * po/sv.po: Updated.

+ 10 - 2
lib/parsehelp.c

@@ -188,10 +188,18 @@ const char *versiondescribe
 
 const char *parseversion(struct versionrevision *rversion, const char *string) {
   char *hyphen, *colon, *eepochcolon;
+  const char *end;
   unsigned long epoch;
 
   if (!*string) return _("version string is empty");
-  
+
+  /* trim leading and trailing space */
+  while (*string && (*string == ' ' || *string == '\t') ) string++;
+  end = string;
+  while (*end && *end != ' ' && *end != '\t' ) end++;
+  /* check for extra chars after trailing space */
+  if (*end) return _("version string has embedded spaces");
+
   colon= strchr(string,':');
   if (colon) {
     epoch= strtoul(string,&eepochcolon,10);
@@ -202,7 +210,7 @@ const char *parseversion(struct versionrevision *rversion, const char *string) {
   } else {
     rversion->epoch= 0;
   }
-  rversion->version= nfstrsave(string);
+  rversion->version= nfstrnsave(string,end-string+1);
   hyphen= strrchr(rversion->version,'-');
   if (hyphen) *hyphen++= 0;
   rversion->revision= hyphen ? hyphen : "";