Path: blob/main/crypto/openssl/apps/lib/vms_decc_argv.c
34879 views
/*1* Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#include <stdlib.h>10#include <openssl/crypto.h>11#include "platform.h" /* for copy_argv() */1213char **newargv = NULL;1415static void cleanup_argv(void)16{17OPENSSL_free(newargv);18newargv = NULL;19}2021char **copy_argv(int *argc, char *argv[])22{23/*-24* The note below is for historical purpose. On VMS now we always25* copy argv "safely."26*27* 2011-03-22 SMS.28* If we have 32-bit pointers everywhere, then we're safe, and29* we bypass this mess, as on non-VMS systems.30* Problem 1: Compaq/HP C before V7.3 always used 32-bit31* pointers for argv[].32* Fix 1: For a 32-bit argv[], when we're using 64-bit pointers33* everywhere else, we always allocate and use a 64-bit34* duplicate of argv[].35* Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed36* to NULL-terminate a 64-bit argv[]. (As this was written, the37* compiler ECO was available only on IA64.)38* Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a39* 64-bit argv[argc] for NULL, and, if necessary, use a40* (properly) NULL-terminated (64-bit) duplicate of argv[].41* The same code is used in either case to duplicate argv[].42* Some of these decisions could be handled in preprocessing,43* but the code tends to get even uglier, and the penalty for44* deciding at compile- or run-time is tiny.45*/4647int i, count = *argc;48char **p = newargv;4950cleanup_argv();5152/*53* We purposefully use OPENSSL_malloc() rather than app_malloc() here,54* to avoid symbol name clashes in test programs that would otherwise55* get them when linking with all of libapps.a.56* See comment in test/build.info.57*/58newargv = OPENSSL_malloc(sizeof(*newargv) * (count + 1));59if (newargv == NULL)60return NULL;6162/* Register automatic cleanup on first use */63if (p == NULL)64OPENSSL_atexit(cleanup_argv);6566for (i = 0; i < count; i++)67newargv[i] = argv[i];68newargv[i] = NULL;69*argc = i;70return newargv;71}727374