FreeCalypso > hg > freecalypso-tools
view ffstools/tiffs-wrappers/pirffs.c @ 965:2969032bdfac
fcup-smsend[mult]: fix buglet in K&R C NULL pointer passing
The only 100% safe way to pass a NULL pointer as a function argument
in K&R C is to cast 0 to a pointer type; failing to do so may cause
mysterious bugs (invalid stack frames or garbage in argument registers)
on 64-bit machines. This issue has already been fixed in most of
FC host tools, but I just found some missed spots: passing of NULL UDH
to PDU encoding functions in fcup-smsend[mult] in the case of single
(not concatenated) SMS.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 01 Sep 2023 07:33:51 +0000 |
parents | e7502631a0f9 |
children |
line wrap: on
line source
/* * pirffs is a wrapper around tiffs: we pass the user's command along, * together with any options, but insert the 256x18 FFS organization argument * automatically. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <unistd.h> extern char tiffs_prog_pathname[]; char *imgfile; char *aopt, *ropt; char **passon_argv; int passon_argc; int output_argc; char **output_argv; main(argc, argv) char **argv; { extern int optind; extern char *optarg; int c; char **sp, **dp; while ((c = getopt(argc, argv, "+a:r:")) != EOF) switch (c) { case 'a': aopt = optarg; continue; case 'r': ropt = optarg; continue; default: usage: fprintf(stderr, "usage: %s [global-options] <imgfile> <op> ...\n", argv[0]); exit(1); } if (argc - optind < 2) goto usage; imgfile = argv[optind++]; passon_argv = argv + optind; passon_argc = argc - optind; output_argc = passon_argc + 3; if (aopt) output_argc += 2; if (ropt) output_argc += 2; output_argv = malloc(sizeof(char *) * (output_argc + 1)); if (!output_argv) { perror("malloc for tiffs argument list"); exit(1); } dp = output_argv; *dp++ = "tiffs"; if (aopt) { *dp++ = "-a"; *dp++ = aopt; } if (ropt) { *dp++ = "-r"; *dp++ = ropt; } *dp++ = imgfile; *dp++ = "256x18"; for (sp = passon_argv; *sp; sp++) *dp++ = *sp; *dp = 0; execvp(tiffs_prog_pathname, output_argv); perror(tiffs_prog_pathname); exit(1); }