From: Simon Wilkinson Date: Wed, 27 Feb 2013 09:21:30 +0000 (+0000) Subject: pt_util: Catch sscanf failures X-Git-Tag: upstream/1.8.0_pre1^2~1396 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=62a10e063b4fe6721bd9768611d5f0c13b303189;p=packages%2Fo%2Fopenafs.git pt_util: Catch sscanf failures If there isn't sufficient data in the input line to satisfy sscanf, fail with an error, rather than continuing with potentially corrupt data. Change-Id: I5f963b5623176ac7631693b093d23cf9f0405edc Reviewed-on: http://gerrit.openafs.org/9295 Tested-by: BuildBot Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman --- diff --git a/src/ptserver/pt_util.c b/src/ptserver/pt_util.c index 58288ef29..f1e9c392f 100644 --- a/src/ptserver/pt_util.c +++ b/src/ptserver/pt_util.c @@ -237,7 +237,12 @@ CommandProc(struct cmd_syndesc *a_as, void *arock) char name[PR_MAXNAMELEN], mem[PR_MAXNAMELEN]; if (isspace(*buffer)) { - sscanf(buffer, "%s %d", mem, &uid); + code = sscanf(buffer, "%s %d", mem, &uid); + if (code != 2) { + fprintf(stderr, + "Insuffient data provided for group membership\n"); + exit(1); + } for (u = usr_head; u; u = u->next) if (u->uid && u->uid == uid) @@ -287,8 +292,13 @@ CommandProc(struct cmd_syndesc *a_as, void *arock) fprintf(stderr, "Error while adding %s to %s: %s\n", mem, name, afs_error_message(code)); } else { - sscanf(buffer, "%s %d/%d %d %d %d", name, &flags, "a, &id, - &oid, &cid); + code = sscanf(buffer, "%s %d/%d %d %d %d", name, &flags, "a, &id, + &oid, &cid); + if (code != 6) { + fprintf(stderr, + "Insufficient data provided for user/group\n"); + exit(1); + } if (FindByID(0, id)) code = PRIDEXIST;