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

Correctly handle trailing spaces in versions

Wichert Akkerman лет назад: 25
Родитель
Сommit
03fe1d5876
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      lib/parsehelp.c

+ 6 - 2
lib/parsehelp.c

@@ -188,17 +188,21 @@ const char *versiondescribe
 
 const char *parseversion(struct versionrevision *rversion, const char *string) {
   char *hyphen, *colon, *eepochcolon;
-  const char *end;
+  const char *end, *ptr;
   unsigned long epoch;
 
   if (!*string) return _("version string is empty");
 
   /* trim leading and trailing space */
   while (*string && (*string == ' ' || *string == '\t') ) string++;
+  /* string now points to the first non-whitespace char */
   end = string;
+  /* find either the end of the string, or a whitespace char */
   while (*end && *end != ' ' && *end != '\t' ) end++;
   /* check for extra chars after trailing space */
-  if (*end) return _("version string has embedded spaces");
+  ptr = end;
+  while (*ptr && ( *ptr == ' ' || *ptr == '\t' ) ) ptr++;
+  if (*ptr) return _("version string has embedded spaces");
 
   colon= strchr(string,':');
   if (colon) {