{"record":{"id":"c007b742106e4d7f","repo":"DrKLO/Telegram","slug":"usage-s-correct-md5-sum-file","errorCode":null,"errorMessage":"USAGE: %s <correct MD5 sum> <file>\n","messagePattern":"USAGE: (.+?) <correct MD5 sum> <file>\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/md5/md5cmp.c","lineNumber":39,"sourceCode":" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n#include <stdio.h>\n#include <string.h>\n#include \"./md5.h\"\n#include \"../tjutil.h\"\n\nint main(int argc, char *argv[])\n{\n  char *md5sum = NULL, buf[65];\n\n  if (argc < 3) {\n    fprintf(stderr, \"USAGE: %s <correct MD5 sum> <file>\\n\", argv[0]);\n    return -1;\n  }\n\n  if (strlen(argv[1]) != 32)\n    fprintf(stderr, \"WARNING: MD5 hash size is wrong.\\n\");\n\n  md5sum = MD5File(argv[2], buf);\n  if (!md5sum) {\n    perror(\"Could not obtain MD5 sum\");\n    return -1;\n  }\n\n  if (!strcasecmp(md5sum, argv[1])) {\n    fprintf(stderr, \"%s: OK\\n\", argv[2]);\n    return 0;\n  } else {\n    fprintf(stderr, \"%s: FAILED.  Checksum is %s\\n\", argv[2], md5sum);\n    return -1;","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/md5/md5cmp.c#L21-L57","documentation":"The md5cmp utility prints this usage message when invoked with fewer than 3 command-line arguments. It is a standalone CLI program (main) that expects exactly two arguments: a reference MD5 hex string and a file path to hash. The function then computes the MD5 of the file and compares it to the reference. When argc < 3 the program cannot proceed and exits with return code -1.","triggerScenarios":"Running md5cmp with zero or one argument: 'md5cmp', 'md5cmp <file>', or invoking it programmatically via execve/system without supplying both the expected hash string and the file path as argv[1] and argv[2].","commonSituations":"Shell scripts or build/CI pipelines that call md5cmp but fail to interpolate the hash or file variable; Android NDK test harnesses that invoke the compiled md5cmp binary with missing positional arguments; copy-paste errors when constructing the command line.","solutions":["Pass exactly two arguments after the program name: the 32-character MD5 hex digest as argv[1] and the file path as argv[2].","Verify that any shell variables used for the hash and file path are non-empty before calling md5cmp.","If calling from another program, ensure argc is at least 3 before invoking exec/system."],"exampleFix":"// before\nsystem(\"md5cmp input.jpg\");\n// after\nsystem(\"md5cmp d41d8cd98f00b204e9800998ecf8427e input.jpg\");","handlingStrategy":"validation","validationCode":"# Validate argument count before invoking md5cmp\nif [ $# -lt 2 ]; then\n  echo \"Error: need <hash> <file>\" >&2\n  exit 1\nfi\nmd5cmp \"$1\" \"$2\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always check argc >= 3 (or $# >= 2 in shell) before invoking md5cmp.","Wrap md5cmp invocations in shell scripts with argument validation.","Use set -u in shell scripts to catch unset positional parameters."],"tags":["cli","argument-error","md5","mozjpeg"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}