X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/4dc77823d360158d6870a5710cc8c17064f1308f..c72f5c4fb4b1d496a9bbdb421f25e986f0cba9bf:/apt-pkg/tagfile.cc diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 213a413cb..a0b64f9ca 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -353,7 +353,7 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const R return true; // Start a new index and add it to the hash - if (isspace(Stop[0]) == 0) + if (isspace_ascii(Stop[0]) == 0) { // store the last found tag if (lastTagData.EndTag != 0) @@ -375,14 +375,16 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const R // find the end of the tag (which might or might not be the colon) char const * EndTag = Colon; --EndTag; - for (; EndTag > Stop && isspace(*EndTag) != 0; --EndTag) + for (; EndTag > Stop && isspace_ascii(*EndTag) != 0; --EndTag) ; ++EndTag; lastTagData.EndTag = EndTag - Section; lastTagHash = AlphaHash(Stop, EndTag - Stop); // find the beginning of the value Stop = Colon + 1; - for (; isspace(*Stop) != 0; ++Stop); + for (; isspace_ascii(*Stop) != 0; ++Stop) + if (*Stop == '\n' && Stop[1] != ' ') + break; if (Stop >= End) return false; lastTagData.StartValue = Stop - Section; @@ -484,7 +486,7 @@ bool pkgTagSection::Find(const char *Tag,const char *&Start, if (unlikely(Start > End)) return _error->Error("Internal parsing error"); - for (; isspace(End[-1]) != 0 && End > Start; --End); + for (; isspace_ascii(End[-1]) != 0 && End > Start; --End); return true; } @@ -512,7 +514,7 @@ string pkgTagSection::FindRawS(const char *Tag) const if (unlikely(Start > End)) return ""; - for (; isspace(End[-1]) != 0 && End > Start; --End); + for (; isspace_ascii(End[-1]) != 0 && End > Start; --End); return std::string(Start, End - Start); } @@ -533,9 +535,15 @@ signed int pkgTagSection::FindI(const char *Tag,signed long Default) const return Default; strncpy(S,Start,Stop-Start); S[Stop - Start] = 0; - + + errno = 0; char *End; signed long Result = strtol(S,&End,10); + if (errno == ERANGE || + Result < std::numeric_limits::min() || Result > std::numeric_limits::max()) { + errno = ERANGE; + _error->Error(_("Cannot convert %s to integer: out of range"), S); + } if (S == End) return Default; return Result; @@ -579,6 +587,34 @@ bool pkgTagSection::FindB(const char *Tag, bool const &Default) const // TagSection::FindFlag - Locate a yes/no type flag /*{{{*/ // --------------------------------------------------------------------- /* The bits marked in Flag are masked on/off in Flags */ +bool pkgTagSection::FindFlag(const char * const Tag, uint8_t &Flags, + uint8_t const Flag) const +{ + const char *Start; + const char *Stop; + if (Find(Tag,Start,Stop) == false) + return true; + return FindFlag(Flags, Flag, Start, Stop); +} +bool pkgTagSection::FindFlag(uint8_t &Flags, uint8_t const Flag, + char const* const Start, char const* const Stop) +{ + switch (StringToBool(string(Start, Stop))) + { + case 0: + Flags &= ~Flag; + return true; + + case 1: + Flags |= Flag; + return true; + + default: + _error->Warning("Unknown flag value: %s",string(Start,Stop).c_str()); + return true; + } + return true; +} bool pkgTagSection::FindFlag(const char *Tag,unsigned long &Flags, unsigned long Flag) const { @@ -638,7 +674,7 @@ pkgTagSection::Tag pkgTagSection::Tag::Rewrite(std::string const &Name, std::str } static bool WriteTag(FileFd &File, std::string Tag, std::string const &Value) { - if (Value.empty() || isspace(Value[0]) != 0) + if (Value.empty() || isspace_ascii(Value[0]) != 0) Tag.append(":"); else Tag.append(": "); @@ -792,7 +828,7 @@ bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[], Visited[J] |= 2; if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0) { - if (isspace(Rewrite[J].Rewrite[0])) + if (isspace_ascii(Rewrite[J].Rewrite[0])) fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); else fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); @@ -848,7 +884,7 @@ bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[], Visited[J] |= 2; if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0) { - if (isspace(Rewrite[J].Rewrite[0])) + if (isspace_ascii(Rewrite[J].Rewrite[0])) fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); else fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); @@ -877,7 +913,7 @@ bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[], if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0) { - if (isspace(Rewrite[J].Rewrite[0])) + if (isspace_ascii(Rewrite[J].Rewrite[0])) fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); else fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);