Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rofl0r/proxychains-ng.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrofl0r <retnyg@gmx.net>2014-11-14 15:17:36 +0300
committerrofl0r <retnyg@gmx.net>2014-11-14 15:19:06 +0300
commit25ee4c318d9c8a394fe73842daf7d5618418199e (patch)
treeea649fc47cb083bd15ec3c9ee1c415177f28aee4 /src/hostsreader.c
parent4fb7eb05328465c97b5c374244a82596da9734cf (diff)
hostsreader: use temporary vars for string manipulation
working directly with the passed variables could lead to bugs when some lines in the hosts file aren't well-formed and the loop is taken several times while the buf vars are already modified.
Diffstat (limited to 'src/hostsreader.c')
-rw-r--r--src/hostsreader.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/hostsreader.c b/src/hostsreader.c
index d20a1a5..dcfaa47 100644
--- a/src/hostsreader.c
+++ b/src/hostsreader.c
@@ -29,26 +29,28 @@ int hostsreader_get(struct hostsreader *ctx, char* buf, size_t bufsize) {
while(1) {
if(!fgets(buf, bufsize, ctx->f)) return 0;
if(*buf == '#') continue;
- ctx->ip = buf;
- while(*buf && !isspace(*buf) && bufsize) {
- buf++;
- bufsize--;
+ char *p = buf;
+ size_t l = bufsize;
+ ctx->ip = p;
+ while(*p && !isspace(*p) && l) {
+ p++;
+ l--;
}
- if(!bufsize || !*buf || buf == ctx->ip) continue;
- *buf = 0;
- buf++;
- while(*buf && isspace(*buf) && bufsize) {
- buf++;
- bufsize--;
+ if(!l || !*p || p == ctx->ip) continue;
+ *p = 0;
+ p++;
+ while(*p && isspace(*p) && l) {
+ p++;
+ l--;
}
- if(!bufsize || !*buf) continue;
+ if(!l || !*p) continue;
ctx->name = buf;
- while(*buf && !isspace(*buf) && bufsize) {
- buf++;
- bufsize--;
+ while(*p && !isspace(*p) && l) {
+ p++;
+ l--;
}
- if(!bufsize || !*buf) continue;
- *buf = 0;
+ if(!l || !*p) continue;
+ *p = 0;
if(isnumericipv4(ctx->ip)) return 1;
}
}